Merge branch 'feature/play_mix' of kilowatt36/freezer into master

This commit is contained in:
exttex 2020-11-01 15:36:46 +00:00 committed by Gogs
commit d3c13444e7
3 changed files with 50 additions and 25 deletions

View File

@ -439,5 +439,13 @@ class DeezerAPI {
});
return data['results']['data'].map<Track>((t) => Track.fromPrivateJson(t)).toList();
}
// Get similar tracks for track with id [trackId]
Future<List<Track>> playMix(String trackId) async {
Map data = await callApi('song.getContextualTrackMix', params: {
'sng_ids': [trackId]
});
return data['results']['data'].map<Track>((t) => Track.fromPrivateJson(t)).toList();
}
}

View File

@ -150,35 +150,32 @@ class PlayerHelper {
//Flow
if (queueSource == null) return;
if (queueSource.id == 'flow') {
List<Track> tracks = await deezerAPI.flow();
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
await AudioService.addQueueItems(mi);
AudioService.skipToNext();
return;
}
//SmartRadio/Artist radio
if (queueSource.source == 'smartradio') {
List<Track> tracks = await deezerAPI.smartRadio(queueSource.id);
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
await AudioService.addQueueItems(mi);
AudioService.skipToNext();
return;
}
//Library shuffle
if (queueSource.source == 'libraryshuffle') {
List<Track> tracks = await deezerAPI.libraryShuffle(start: AudioService.queue.length);
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
await AudioService.addQueueItems(mi);
AudioService.skipToNext();
return;
}
List<Track> tracks = [];
switch(queueSource.source) {
case 'flow':
tracks = await deezerAPI.flow();
break;
case 'smartradio': //SmartRadio/Artist radio
tracks = await deezerAPI.smartRadio(queueSource.id);
break;
case 'libraryshuffle': //Library shuffle
tracks = await deezerAPI.libraryShuffle(start: AudioService.queue.length);
break;
case 'mix':
tracks = await deezerAPI.playMix(queueSource.id);
// Deduplicate tracks with the same id
List<String> queueIds = AudioService.queue.map((e) => e.id).toList();
tracks.removeWhere((track) => queueIds.contains(track.id));
break;
default:
print(queueSource.toJson());
}
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
await AudioService.addQueueItems(mi);
AudioService.skipToNext();
}
//Play track from album
Future playFromAlbum(Album album, String trackId) async {
await playFromTrackList(album.tracks, trackId, QueueSource(
@ -187,6 +184,16 @@ class PlayerHelper {
source: 'album'
));
}
//Play mix by track
Future playMix(String trackId, String trackTitle) async {
List<Track> tracks = await deezerAPI.playMix(trackId);
playFromTrackList(tracks, tracks[0].id, QueueSource(
id: trackId,
text: 'Mix based on'.i18n + ' $trackTitle',
source: 'mix'
));
}
//Play from artist top tracks
Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async {
await playFromTrackList(tracks, trackId, QueueSource(

View File

@ -7,6 +7,7 @@ import 'package:fluttertoast/fluttertoast.dart';
import 'package:freezer/api/cache.dart';
import 'package:freezer/api/deezer.dart';
import 'package:freezer/api/download.dart';
import 'package:freezer/api/player.dart';
import 'package:freezer/ui/details_screens.dart';
import 'package:freezer/ui/error.dart';
import 'package:freezer/translations.i18n.dart';
@ -132,6 +133,7 @@ class MenuSheet {
addToPlaylist(track),
downloadTrack(track),
shareTile('track', track.id),
playMix(track),
showAlbum(track.album),
...List.generate(track.artists.length, (i) => showArtist(track.artists[i])),
...options
@ -289,6 +291,14 @@ class MenuSheet {
},
);
Widget playMix(Track track) => ListTile(
title: Text('Play mix'.i18n),
leading: Icon(Icons.online_prediction),
onTap: () async {
playerHelper.playMix(track.id, track.title);
_close();
},
);
//===================
// ALBUM