mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
mobile: Allow removing tracks from the playlist
This commit is contained in:
parent
37a1353297
commit
1c64d56346
2 changed files with 54 additions and 3 deletions
|
|
@ -170,6 +170,16 @@ class Player {
|
||||||
await AudioService.customAction('addTracks', jsonEncode(tracks));
|
await AudioService.customAction('addTracks', jsonEncode(tracks));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove the track at [index] from the playlist.
|
||||||
|
///
|
||||||
|
/// If the player is not active or an invalid value is provided, this will do
|
||||||
|
/// nothing.
|
||||||
|
Future<void> removeTrack(int index) async {
|
||||||
|
if (AudioService.running) {
|
||||||
|
await AudioService.customAction('removeTrack', index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Seek to [pos], which is a value between (and including) zero and one.
|
/// Seek to [pos], which is a value between (and including) zero and one.
|
||||||
///
|
///
|
||||||
/// If the player is not active or an invalid value is provided, this will do
|
/// If the player is not active or an invalid value is provided, this will do
|
||||||
|
|
@ -433,6 +443,27 @@ class _PlaybackService extends BackgroundAudioTask {
|
||||||
_sendPlaylist();
|
_sendPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove the track at [index] from the playlist.
|
||||||
|
///
|
||||||
|
/// If it was the current track, the next track will be played.
|
||||||
|
Future<void> _removeTrack(int index) async {
|
||||||
|
if (index >= 0 && index < _playlist.length) {
|
||||||
|
_playlist.removeAt(index);
|
||||||
|
|
||||||
|
if (_playlist.isEmpty) {
|
||||||
|
onStop();
|
||||||
|
} else {
|
||||||
|
if (_currentTrack == index) {
|
||||||
|
await _setCurrentTrack(index);
|
||||||
|
} else if (_currentTrack > index) {
|
||||||
|
_currentTrack--;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendPlaylist();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Jump to the beginning of the track with the index [index].
|
/// Jump to the beginning of the track with the index [index].
|
||||||
Future<void> _skipTo(int index) async {
|
Future<void> _skipTo(int index) async {
|
||||||
if (index >= 0 && index < _playlist.length) {
|
if (index >= 0 && index < _playlist.length) {
|
||||||
|
|
@ -452,15 +483,17 @@ class _PlaybackService extends BackgroundAudioTask {
|
||||||
super.onCustomAction(name, arguments);
|
super.onCustomAction(name, arguments);
|
||||||
|
|
||||||
// addTracks expects a List<Map<String, dynamic>> as its argument.
|
// addTracks expects a List<Map<String, dynamic>> as its argument.
|
||||||
// skipTo expects an integer as its argument.
|
// skipTo and removeTrack expect an integer as their argument.
|
||||||
if (name == 'addTracks') {
|
if (name == 'addTracks') {
|
||||||
final tracksJson = jsonDecode(arguments);
|
final tracksJson = jsonDecode(arguments);
|
||||||
final List<InternalTrack> tracks = List.castFrom(
|
final List<InternalTrack> tracks = List.castFrom(
|
||||||
tracksJson.map((j) => InternalTrack.fromJson(j)).toList());
|
tracksJson.map((j) => InternalTrack.fromJson(j)).toList());
|
||||||
|
|
||||||
_addTracks(tracks);
|
_addTracks(tracks);
|
||||||
}
|
} else if (name == 'removeTrack') {
|
||||||
if (name == 'skipTo') {
|
final index = arguments as int;
|
||||||
|
_removeTrack(index);
|
||||||
|
} else if (name == 'skipTo') {
|
||||||
final index = arguments as int;
|
final index = arguments as int;
|
||||||
_skipTo(index);
|
_skipTo(index);
|
||||||
} else if (name == 'sendState') {
|
} else if (name == 'sendState') {
|
||||||
|
|
|
||||||
|
|
@ -183,6 +183,24 @@ class _ProgramScreenState extends State<ProgramScreen> {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
backend.player.skipTo(index);
|
backend.player.skipTo(index);
|
||||||
},
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return SimpleDialog(
|
||||||
|
children: <Widget>[
|
||||||
|
ListTile(
|
||||||
|
title: Text('Remove from playlist'),
|
||||||
|
onTap: () {
|
||||||
|
backend.player.removeTrack(index);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue