Skip over error items in playlist on iOS. Fix positionStream.
This commit is contained in:
parent
f266ce0b7a
commit
d6e14ae9d6
3 changed files with 143 additions and 90 deletions
|
@ -115,87 +115,7 @@ class _MyAppState extends State<MyApp> {
|
|||
},
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream: _player.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
final playerState = snapshot.data;
|
||||
final processingState = playerState?.processingState;
|
||||
final playing = playerState?.playing;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.volume_up),
|
||||
onPressed: () {
|
||||
_showSliderDialog(
|
||||
context: context,
|
||||
title: "Adjust volume",
|
||||
divisions: 10,
|
||||
min: 0.0,
|
||||
max: 1.0,
|
||||
stream: _player.volumeStream,
|
||||
onChanged: _player.setVolume,
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.skip_previous),
|
||||
onPressed:
|
||||
_player.hasPrevious ? _player.seekToPrevious : null,
|
||||
),
|
||||
if (processingState == ProcessingState.loading ||
|
||||
processingState == ProcessingState.buffering)
|
||||
Container(
|
||||
margin: EdgeInsets.all(8.0),
|
||||
width: 64.0,
|
||||
height: 64.0,
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
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,
|
||||
onPressed: _player.pause,
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
icon: Icon(Icons.replay),
|
||||
iconSize: 64.0,
|
||||
onPressed: () =>
|
||||
_player.seek(Duration.zero, index: 0),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.skip_next),
|
||||
onPressed: _player.hasNext ? _player.seekToNext : null,
|
||||
),
|
||||
IconButton(
|
||||
icon: StreamBuilder<double>(
|
||||
stream: _player.speedStream,
|
||||
builder: (context, snapshot) => Text(
|
||||
"${snapshot.data?.toStringAsFixed(1)}x",
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
onPressed: () {
|
||||
_showSliderDialog(
|
||||
context: context,
|
||||
title: "Adjust speed",
|
||||
divisions: 10,
|
||||
min: 0.5,
|
||||
max: 1.5,
|
||||
stream: _player.speedStream,
|
||||
onChanged: _player.setSpeed,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
ControlButtons(_player),
|
||||
StreamBuilder<Duration>(
|
||||
stream: _player.durationStream,
|
||||
builder: (context, snapshot) {
|
||||
|
@ -299,6 +219,102 @@ class _MyAppState extends State<MyApp> {
|
|||
}
|
||||
}
|
||||
|
||||
class ControlButtons extends StatelessWidget {
|
||||
final AudioPlayer player;
|
||||
|
||||
ControlButtons(this.player);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.volume_up),
|
||||
onPressed: () {
|
||||
_showSliderDialog(
|
||||
context: context,
|
||||
title: "Adjust volume",
|
||||
divisions: 10,
|
||||
min: 0.0,
|
||||
max: 1.0,
|
||||
stream: player.volumeStream,
|
||||
onChanged: player.setVolume,
|
||||
);
|
||||
},
|
||||
),
|
||||
StreamBuilder<int>(
|
||||
stream: player.currentIndexStream,
|
||||
builder: (context, snapshot) => IconButton(
|
||||
icon: Icon(Icons.skip_previous),
|
||||
onPressed: player.hasPrevious ? player.seekToPrevious : null,
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream: player.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
final playerState = snapshot.data;
|
||||
final processingState = playerState?.processingState;
|
||||
final playing = playerState?.playing;
|
||||
if (processingState == ProcessingState.loading ||
|
||||
processingState == ProcessingState.buffering) {
|
||||
return Container(
|
||||
margin: EdgeInsets.all(8.0),
|
||||
width: 64.0,
|
||||
height: 64.0,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else if (playing != true) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.play_arrow),
|
||||
iconSize: 64.0,
|
||||
onPressed: player.play,
|
||||
);
|
||||
} else if (processingState != ProcessingState.completed) {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.pause),
|
||||
iconSize: 64.0,
|
||||
onPressed: player.pause,
|
||||
);
|
||||
} else {
|
||||
return IconButton(
|
||||
icon: Icon(Icons.replay),
|
||||
iconSize: 64.0,
|
||||
onPressed: () => player.seek(Duration.zero, index: 0),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
StreamBuilder(
|
||||
stream: player.currentIndexStream,
|
||||
builder: (context, snapshot) => IconButton(
|
||||
icon: Icon(Icons.skip_next),
|
||||
onPressed: player.hasNext ? player.seekToNext : null,
|
||||
),
|
||||
),
|
||||
StreamBuilder<double>(
|
||||
stream: player.speedStream,
|
||||
builder: (context, snapshot) => IconButton(
|
||||
icon: Text("${snapshot.data?.toStringAsFixed(1)}x",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
onPressed: () {
|
||||
_showSliderDialog(
|
||||
context: context,
|
||||
title: "Adjust speed",
|
||||
divisions: 10,
|
||||
min: 0.5,
|
||||
max: 1.5,
|
||||
stream: player.speedStream,
|
||||
onChanged: player.setSpeed,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SeekBar extends StatefulWidget {
|
||||
final Duration duration;
|
||||
final Duration position;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue