New state model, processingState + playing

This commit is contained in:
Ryan Heise 2020-08-04 00:16:15 +10:00
parent 6d14d257a0
commit e4789d9cd2
7 changed files with 620 additions and 644 deletions

View file

@ -101,24 +101,29 @@ class _MyAppState extends State<MyApp> {
);
},
),
StreamBuilder<FullAudioPlaybackState>(
stream: _player.fullPlaybackStateStream,
StreamBuilder<PlayerState>(
stream: _player.playerStateStream,
builder: (context, snapshot) {
final fullState = snapshot.data;
final state = fullState?.state;
final buffering = fullState?.buffering;
final playerState = snapshot.data;
final processingState = playerState?.processingState;
final playing = playerState?.playing;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (state == AudioPlaybackState.connecting ||
buffering == true)
if (processingState == ProcessingState.buffering)
Container(
margin: EdgeInsets.all(8.0),
width: 64.0,
height: 64.0,
child: CircularProgressIndicator(),
)
else if (state == AudioPlaybackState.playing)
else if (playing != true)
IconButton(
icon: Icon(Icons.play_arrow),
iconSize: 64.0,
onPressed: _player.play,
)
else if (processingState != ProcessingState.completed)
IconButton(
icon: Icon(Icons.pause),
iconSize: 64.0,
@ -126,18 +131,11 @@ class _MyAppState extends State<MyApp> {
)
else
IconButton(
icon: Icon(Icons.play_arrow),
icon: Icon(Icons.replay),
iconSize: 64.0,
onPressed: _player.play,
onPressed: () =>
_player.seek(Duration.zero, index: 0),
),
IconButton(
icon: Icon(Icons.stop),
iconSize: 64.0,
onPressed: state == AudioPlaybackState.stopped ||
state == AudioPlaybackState.none
? null
: _player.stop,
),
],
);
},
@ -148,7 +146,7 @@ class _MyAppState extends State<MyApp> {
builder: (context, snapshot) {
final duration = snapshot.data ?? Duration.zero;
return StreamBuilder<Duration>(
stream: _player.getPositionStream(),
stream: _player.positionStream,
builder: (context, snapshot) {
var position = snapshot.data ?? Duration.zero;
if (position > duration) {
@ -308,10 +306,10 @@ class _SeekBarState extends State<SeekBar> {
}
},
onChangeEnd: (value) {
_dragValue = null;
if (widget.onChangeEnd != null) {
widget.onChangeEnd(Duration(milliseconds: value.round()));
}
_dragValue = null;
},
);
}

View file

@ -1,27 +1,13 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.4.2"
boolean_selector:
dependency: transitive
description:
@ -29,6 +15,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
charcode:
dependency: transitive
description:
@ -36,13 +29,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
version: "1.14.13"
convert:
dependency: transitive
description:
@ -64,6 +64,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
file:
dependency: transitive
description:
@ -86,13 +93,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
intl:
dependency: transitive
description:
@ -113,7 +113,7 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.8"
meta:
dependency: transitive
description:
@ -127,7 +127,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
version: "1.7.0"
path_provider:
dependency: transitive
description:
@ -156,13 +156,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
platform:
dependency: transitive
description:
@ -184,13 +177,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.13"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
rxdart:
dependency: "direct main"
description:
@ -216,7 +202,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.9.5"
stream_channel:
dependency: transitive
description:
@ -244,14 +230,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.17"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.2.0"
uuid:
dependency: transitive
description:
@ -273,13 +259,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"