From 8577734c4e6300b9d2f3e9f2fc172f308ae584d4 Mon Sep 17 00:00:00 2001
From: Tristan Roux
Date: Sun, 27 Jan 2019 21:16:52 +0100
Subject: [PATCH] Making create mix work when there is no queue.
---
MusicApp/MainActivity.cs | 2 +-
.../Resources/Portable Class/LineAdapter.cs | 4 +--
.../Resources/Portable Class/MusicPlayer.cs | 5 ++--
.../Portable Class/PlaylistTracks.cs | 2 +-
MusicApp/Resources/Portable Class/Queue.cs | 2 +-
.../Resources/Portable Class/YoutubeEngine.cs | 28 +++++--------------
6 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/MusicApp/MainActivity.cs b/MusicApp/MainActivity.cs
index 84a7038..74df89a 100644
--- a/MusicApp/MainActivity.cs
+++ b/MusicApp/MainActivity.cs
@@ -1185,7 +1185,7 @@ namespace MusicApp
if (sender != null)
QuickPlay(this, e);
- YoutubeEngine.CreateMix((await MusicPlayer.GetItem()).YoutubeID);
+ YoutubeEngine.CreateMix((await MusicPlayer.GetItem()));
}
public void YoutubeEndPointChanged()
diff --git a/MusicApp/Resources/Portable Class/LineAdapter.cs b/MusicApp/Resources/Portable Class/LineAdapter.cs
index e5a21c3..a09d908 100644
--- a/MusicApp/Resources/Portable Class/LineAdapter.cs
+++ b/MusicApp/Resources/Portable Class/LineAdapter.cs
@@ -184,7 +184,7 @@ namespace MusicApp.Resources.Portable_Class
{
new BottomSheetAction(Resource.Drawable.PlayCircle, MainActivity.instance.Resources.GetString(Resource.String.create_mix_from_song), (sender, eventArg) =>
{
- YoutubeEngine.CreateMix(item.YoutubeID);
+ YoutubeEngine.CreateMix(item);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.Download, MainActivity.instance.Resources.GetString(Resource.String.download), (sender, eventArg) =>
@@ -268,7 +268,7 @@ namespace MusicApp.Resources.Portable_Class
{
new BottomSheetAction(Resource.Drawable.PlayCircle, MainActivity.instance.Resources.GetString(Resource.String.create_mix_from_song), (sender, eventArg) =>
{
- YoutubeEngine.CreateMix(item.YoutubeID);
+ YoutubeEngine.CreateMix(item);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.Download, MainActivity.instance.Resources.GetString(Resource.String.download), (sender, eventArg) =>
diff --git a/MusicApp/Resources/Portable Class/MusicPlayer.cs b/MusicApp/Resources/Portable Class/MusicPlayer.cs
index a93c6b6..18405f8 100644
--- a/MusicApp/Resources/Portable Class/MusicPlayer.cs
+++ b/MusicApp/Resources/Portable Class/MusicPlayer.cs
@@ -538,14 +538,15 @@ namespace MusicApp.Resources.Portable_Class
if (action == "Play")
{
- MainActivity.instance.ShowPlayer();
+ if(showPlayer)
+ MainActivity.instance.ShowPlayer();
+
Song song = new Song(title, artist, thumbnailURL, videoID, -1, -1, null, true, false);
queue.Clear();
queue.Add(song);
currentID = 0;
await ParseSong(song, 0, true);
}
-
else
{
Song song = await ParseSong(new Song(title, artist, thumbnailURL, videoID, -1, -1, null, true, false));
diff --git a/MusicApp/Resources/Portable Class/PlaylistTracks.cs b/MusicApp/Resources/Portable Class/PlaylistTracks.cs
index a1c19df..eba06c0 100644
--- a/MusicApp/Resources/Portable Class/PlaylistTracks.cs
+++ b/MusicApp/Resources/Portable Class/PlaylistTracks.cs
@@ -744,7 +744,7 @@ namespace MusicApp.Resources.Portable_Class
{
new BottomSheetAction(Resource.Drawable.PlayCircle, Resources.GetString(Resource.String.create_mix_from_song), (sender, eventArg) =>
{
- YoutubeEngine.CreateMix(item.YoutubeID);
+ YoutubeEngine.CreateMix(item);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.Download, Resources.GetString(Resource.String.download), (sender, eventArg) =>
diff --git a/MusicApp/Resources/Portable Class/Queue.cs b/MusicApp/Resources/Portable Class/Queue.cs
index 3c45041..5a20fa0 100644
--- a/MusicApp/Resources/Portable Class/Queue.cs
+++ b/MusicApp/Resources/Portable Class/Queue.cs
@@ -222,7 +222,7 @@ namespace MusicApp.Resources.Portable_Class
{
new BottomSheetAction(Resource.Drawable.PlayCircle, Resources.GetString(Resource.String.create_mix_from_song), (sender, eventArg) =>
{
- YoutubeEngine.CreateMix(item.YoutubeID);
+ YoutubeEngine.CreateMix(item);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.Download, Resources.GetString(Resource.String.download), (sender, eventArg) =>
diff --git a/MusicApp/Resources/Portable Class/YoutubeEngine.cs b/MusicApp/Resources/Portable Class/YoutubeEngine.cs
index 8273011..bc887a7 100644
--- a/MusicApp/Resources/Portable Class/YoutubeEngine.cs
+++ b/MusicApp/Resources/Portable Class/YoutubeEngine.cs
@@ -480,7 +480,7 @@ namespace MusicApp.Resources.Portable_Class
}),
new BottomSheetAction(Resource.Drawable.PlayCircle, Resources.GetString(Resource.String.create_mix_from_song), (sender, eventArg) =>
{
- CreateMix(item.YoutubeID);
+ CreateMix(item);
bottomSheet.Dismiss();
}),
new BottomSheetAction(Resource.Drawable.PlaylistAdd, Resources.GetString(Resource.String.add_to_playlist), (sender, eventArg) => { Browse.GetPlaylist(item); bottomSheet.Dismiss(); }),
@@ -554,20 +554,6 @@ namespace MusicApp.Resources.Portable_Class
ShowRecomandations(videoID);
}
- public static void Play(string videoID)
- {
- MusicPlayer.queue?.Clear();
- MusicPlayer.UpdateQueueDataBase();
- MusicPlayer.currentID = -1;
-
- Intent intent = new Intent(Android.App.Application.Context, typeof(MusicPlayer));
- intent.SetAction("YoutubePlay");
- intent.PutExtra("action", "Play");
- intent.PutExtra("file", videoID);
- Android.App.Application.Context.StartService(intent);
- ShowRecomandations(videoID);
- }
-
public static async void PlayFiles(Song[] files)
{
if (files.Length < 1)
@@ -986,11 +972,11 @@ namespace MusicApp.Resources.Portable_Class
MusicPlayer.instance.RandomPlay(songs, false);
}
- public static async void CreateMix(string videoID)
+ public static async void CreateMix(Song item)
{
if(MusicPlayer.queue.Count == 0)
{
- Play(videoID);
+ Play(item.YoutubeID, item.Title, item.Artist, item.Album, true, true);
}
ProgressBar parseProgress = MainActivity.instance.FindViewById(Resource.Id.ytProgress);
@@ -1009,7 +995,7 @@ namespace MusicApp.Resources.Portable_Class
try
{
YoutubeClient client = new YoutubeClient();
- var video = await client.GetVideoAsync(MusicPlayer.queue[MusicPlayer.CurrentID()].YoutubeID);
+ var video = await client.GetVideoAsync(item.YoutubeID);
var ytPlaylistRequest = youtubeService.PlaylistItems.List("snippet, contentDetails");
ytPlaylistRequest.PlaylistId = video.GetVideoMixPlaylistId();
@@ -1017,11 +1003,11 @@ namespace MusicApp.Resources.Portable_Class
var ytPlaylist = await ytPlaylistRequest.ExecuteAsync();
- foreach (var item in ytPlaylist.Items)
+ foreach (var ytItem in ytPlaylist.Items)
{
- if (item.Snippet.Title != "[Deleted video]" && item.Snippet.Title != "Private video" && item.Snippet.Title != "Deleted video" && item.ContentDetails.VideoId != MusicPlayer.queue[MusicPlayer.CurrentID()].YoutubeID)
+ if (ytItem.Snippet.Title != "[Deleted video]" && ytItem.Snippet.Title != "Private video" && ytItem.Snippet.Title != "Deleted video" && ytItem.ContentDetails.VideoId != MusicPlayer.queue[MusicPlayer.CurrentID()].YoutubeID)
{
- Song song = new Song(item.Snippet.Title, item.Snippet.ChannelTitle, item.Snippet.Thumbnails.High.Url, item.ContentDetails.VideoId, -1, -1, item.ContentDetails.VideoId, true, false);
+ Song song = new Song(ytItem.Snippet.Title, ytItem.Snippet.ChannelTitle, ytItem.Snippet.Thumbnails.High.Url, ytItem.ContentDetails.VideoId, -1, -1, ytItem.ContentDetails.VideoId, true, false);
tracks.Add(song);
}
}