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(); 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 //Flow
if (queueSource == null) return; if (queueSource == null) return;
if (queueSource.id == 'flow') { List<Track> tracks = [];
List<Track> tracks = await deezerAPI.flow(); switch(queueSource.source) {
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList(); case 'flow':
await AudioService.addQueueItems(mi); tracks = await deezerAPI.flow();
AudioService.skipToNext(); break;
return; case 'smartradio': //SmartRadio/Artist radio
} tracks = await deezerAPI.smartRadio(queueSource.id);
break;
//SmartRadio/Artist radio case 'libraryshuffle': //Library shuffle
if (queueSource.source == 'smartradio') { tracks = await deezerAPI.libraryShuffle(start: AudioService.queue.length);
List<Track> tracks = await deezerAPI.smartRadio(queueSource.id); break;
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList(); case 'mix':
await AudioService.addQueueItems(mi); tracks = await deezerAPI.playMix(queueSource.id);
AudioService.skipToNext(); // Deduplicate tracks with the same id
return; List<String> queueIds = AudioService.queue.map((e) => e.id).toList();
} tracks.removeWhere((track) => queueIds.contains(track.id));
break;
//Library shuffle default:
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;
}
print(queueSource.toJson()); print(queueSource.toJson());
} }
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
await AudioService.addQueueItems(mi);
AudioService.skipToNext();
}
//Play track from album //Play track from album
Future playFromAlbum(Album album, String trackId) async { Future playFromAlbum(Album album, String trackId) async {
await playFromTrackList(album.tracks, trackId, QueueSource( await playFromTrackList(album.tracks, trackId, QueueSource(
@ -187,6 +184,16 @@ class PlayerHelper {
source: 'album' 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 //Play from artist top tracks
Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async { Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async {
await playFromTrackList(tracks, trackId, QueueSource( 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/cache.dart';
import 'package:freezer/api/deezer.dart'; import 'package:freezer/api/deezer.dart';
import 'package:freezer/api/download.dart'; import 'package:freezer/api/download.dart';
import 'package:freezer/api/player.dart';
import 'package:freezer/ui/details_screens.dart'; import 'package:freezer/ui/details_screens.dart';
import 'package:freezer/ui/error.dart'; import 'package:freezer/ui/error.dart';
import 'package:freezer/translations.i18n.dart'; import 'package:freezer/translations.i18n.dart';
@ -132,6 +133,7 @@ class MenuSheet {
addToPlaylist(track), addToPlaylist(track),
downloadTrack(track), downloadTrack(track),
shareTile('track', track.id), shareTile('track', track.id),
playMix(track),
showAlbum(track.album), showAlbum(track.album),
...List.generate(track.artists.length, (i) => showArtist(track.artists[i])), ...List.generate(track.artists.length, (i) => showArtist(track.artists[i])),
...options ...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 // ALBUM