diff --git a/Opus/MainActivity.cs b/Opus/MainActivity.cs index 074e6b4..ef516c6 100644 --- a/Opus/MainActivity.cs +++ b/Opus/MainActivity.cs @@ -944,11 +944,17 @@ namespace Opus snackBar.Show(); } - public void Unplayable(string msg) + public void Unplayable(string title, string msg) { if (msg.Contains("country")) { - Snackbar snackBar = Snackbar.Make(FindViewById(Resource.Id.snackBar), Resource.String.country_blocked, Snackbar.LengthLong); + Snackbar snackBar = Snackbar.Make(FindViewById(Resource.Id.snackBar), title + " " + GetString(Resource.String.country_blocked), Snackbar.LengthLong); + snackBar.View.FindViewById(Resource.Id.snackbar_text).SetTextColor(Color.White); + snackBar.Show(); + } + else if(msg.Contains("not available")) + { + Snackbar snackBar = Snackbar.Make(FindViewById(Resource.Id.snackBar), title + " " + GetString(Resource.String.not_streamable), Snackbar.LengthLong); snackBar.View.FindViewById(Resource.Id.snackbar_text).SetTextColor(Color.White); snackBar.Show(); } @@ -1006,7 +1012,7 @@ namespace Opus return false; } - + private async void SyncPlaylists() { ISharedPreferences prefManager = PreferenceManager.GetDefaultSharedPreferences(this); @@ -1208,7 +1214,7 @@ namespace Opus { YoutubeEngine.instances = null; - if (MusicPlayer.instance != null && !MusicPlayer.isRunning && Preferences.instance == null && Queue.instance == null && EditMetaData.instance == null) + if (MusicPlayer.instance != null && !MusicPlayer.isRunning && Preferences.instance == null && EditMetaData.instance == null) { Intent intent = new Intent(this, typeof(MusicPlayer)); intent.SetAction("Stop"); diff --git a/Opus/Resources/Portable Class/CurrentItemDecoration.cs b/Opus/Resources/Portable Class/CurrentItemDecoration.cs index 88ae1c9..653c2f8 100644 --- a/Opus/Resources/Portable Class/CurrentItemDecoration.cs +++ b/Opus/Resources/Portable Class/CurrentItemDecoration.cs @@ -26,6 +26,8 @@ namespace Opus.Resources.Portable_Class return; } + if (MusicPlayer.CurrentID() < 0) //If there is no current item, do not draw the header + return; if (parent.ChildCount > 1 && parent.Width > 0) { diff --git a/Opus/Resources/Portable Class/MusicPlayer.cs b/Opus/Resources/Portable Class/MusicPlayer.cs index 7c8cd64..d13b751 100644 --- a/Opus/Resources/Portable Class/MusicPlayer.cs +++ b/Opus/Resources/Portable Class/MusicPlayer.cs @@ -355,7 +355,7 @@ namespace Opus.Resources.Portable_Class { if (song.IsParsed != true) { - song = await ParseSong(song); + await ParseSong(song, -1, true); return; } @@ -364,7 +364,7 @@ namespace Opus.Resources.Portable_Class queue?.Clear(); currentID = -1; } - + isLiveStream = song.IsLiveStream; isRunning = true; @@ -554,19 +554,30 @@ namespace Opus.Resources.Portable_Class if (MainActivity.instance != null) MainActivity.instance.FindViewById(Resource.Id.ytProgress).Visibility = ViewStates.Gone; song.IsParsed = false; - return song; + return null; } catch(YoutubeExplode.Exceptions.VideoUnplayableException ex) { Console.WriteLine("&Parse error: " + ex.Message); - MainActivity.instance.Unplayable(ex.Message); + MainActivity.instance.Unplayable(song.Title, ex.Message); if (MainActivity.instance != null) MainActivity.instance.FindViewById(Resource.Id.ytProgress).Visibility = ViewStates.Gone; song.IsParsed = false; if (position != -1) RemoveFromQueue(position); //Remove the song from the queue since it can't be played. - return song; + return null; + } + catch(YoutubeExplode.Exceptions.VideoUnavailableException) + { + MainActivity.instance.NotStreamable(song.Title); + if (MainActivity.instance != null) + MainActivity.instance.FindViewById(Resource.Id.ytProgress).Visibility = ViewStates.Gone; + + song.IsParsed = false; + if (position != -1) + RemoveFromQueue(position); //Remove the song from the queue since it can't be played. + return null; } return song; } @@ -600,6 +611,8 @@ namespace Opus.Resources.Portable_Class else { Song song = await ParseSong(new Song(title, artist, thumbnailURL, videoID, -1, -1, null, true, false)); + if (song == null) //The song can't be played, do not add it to the queue + return; switch (action) { @@ -898,11 +911,11 @@ namespace Opus.Resources.Portable_Class public static void RemoveFromQueue(int position) { - if(CurrentID() == position) + if (CurrentID() == position) { if (position > 0) currentID--; - else if (queue.Count > position - 1) + else if (queue.Count > position + 1) currentID++; else currentID = -1; @@ -913,8 +926,22 @@ namespace Opus.Resources.Portable_Class } queue.RemoveAt(position); - Home.instance?.NotifyQueueRemoved(position); - Queue.instance?.NotifyItemRemoved(position); + + if (queue.Count == 0) + { + MainActivity.instance.HideSmallPlayer(); + if (Home.instance != null && Home.adapterItems?.Count > 0 && Home.adapterItems[0]?.SectionTitle == "Queue") + { + Home.instance?.adapter?.NotifyItemRemoved(0); + Home.adapterItems?.RemoveAt(0); + } + Queue.instance?.NotifyItemRemoved(position); + } + else + { + Home.instance?.NotifyQueueRemoved(position); + Queue.instance?.NotifyItemRemoved(position); + } if (UseCastPlayer) RemotePlayer.QueueRemoveItem(RemotePlayer.MediaQueue.ItemIdAtIndex(position), null); @@ -1031,16 +1058,16 @@ namespace Opus.Resources.Portable_Class SwitchQueue(CurrentID() + 1); } - public async void SwitchQueue(int position, bool showPlayer = false, bool StartFromOldPosition = true) + public async void SwitchQueue(int position, bool showPlayer = false, bool StartFromOldPosition = false) { Song song = await GetItem(position); - currentID = position; if(showPlayer) MainActivity.instance.ShowPlayer(); if (UseCastPlayer) { + currentID = position; Console.WriteLine("&Switching to item at " + position + " with itemID: " + RemotePlayer.MediaQueue.ItemIdAtIndex(position)); RemotePlayer.QueueJumpToItem(RemotePlayer.MediaQueue.ItemIdAtIndex(position), null); } @@ -1055,6 +1082,11 @@ namespace Opus.Resources.Portable_Class } await ParseSong(song, position, !UseCastPlayer, true); + if (song != null) //Check if the parse has succeed, the song is set to null if there is an error + currentID = position; + else + Player.instance?.Ready(); //Remove player's loading bar since we'll not load this song + if (MainActivity.instance != null && showPlayer) { ProgressBar parseProgress = MainActivity.instance.FindViewById(Resource.Id.ytProgress); @@ -1062,7 +1094,10 @@ namespace Opus.Resources.Portable_Class } } else + { + currentID = position; Play(song, StartFromOldPosition ? LastTimer : -1, false); + } Queue.instance?.RefreshAP(); } @@ -1187,6 +1222,7 @@ namespace Opus.Resources.Portable_Class { ISharedPreferences pref = PreferenceManager.GetDefaultSharedPreferences(Application.Context); int queueSlot = pref.GetInt("currentID", 0); + Console.WriteLine("&Retrieved queue slot: " + queueSlot); return queueSlot == -1 ? 0 : queueSlot; } @@ -1578,6 +1614,8 @@ namespace Opus.Resources.Portable_Class editor.PutInt("currentID", currentID); editor.Apply(); + Console.WriteLine("&CurrentID: " + currentID); + if (player != null && CurrentPosition != 0) SaveTimer(CurrentPosition); } diff --git a/Opus/Resources/Portable Class/Queue.cs b/Opus/Resources/Portable Class/Queue.cs index 35394e2..3f7e1b2 100644 --- a/Opus/Resources/Portable Class/Queue.cs +++ b/Opus/Resources/Portable Class/Queue.cs @@ -111,7 +111,7 @@ public class Queue : Fragment, RecyclerView.IOnItemTouchListener, PopupMenu.IOnM { Song song = MusicPlayer.queue[i - 1]; RecyclerHolder holder = (RecyclerHolder)ListView.GetChildViewHolder(((LinearLayoutManager)ListView.GetLayoutManager()).FindViewByPosition(i)); - if (MusicPlayer.queue[MusicPlayer.CurrentID()] == song) + if (MusicPlayer.CurrentID() > -1 && MusicPlayer.queue[MusicPlayer.CurrentID()] == song) { holder.status.Visibility = ViewStates.Visible; holder.status.SetTextColor(MusicPlayer.isRunning ? Color.Argb(255, 244, 81, 30) : Color.Argb(255, 66, 165, 245)); diff --git a/Opus/Resources/values-es/strings.xml b/Opus/Resources/values-es/strings.xml index 58c3503..2fadbe2 100644 --- a/Opus/Resources/values-es/strings.xml +++ b/Opus/Resources/values-es/strings.xml @@ -184,7 +184,7 @@ El algoritmo youtube a cambiado, la aplicación no puede leer este video.Espere la proxima actualización. Timout, compruebe su conexión internet. Un error desconozido est sucedió. - This song is not available in your country. + is not available in your country. no pude ser reproducido, el audio no está disponible. No está conectado a internet, imposible de comprobar si existen actualizaciones. La versión %1$s está disponible diff --git a/Opus/Resources/values-fr/strings.xml b/Opus/Resources/values-fr/strings.xml index a7ef2e1..3a791a0 100644 --- a/Opus/Resources/values-fr/strings.xml +++ b/Opus/Resources/values-fr/strings.xml @@ -184,7 +184,7 @@ L\'algorithme youtube a changé, l\'application ne peut plus lire cette vidéo. Attendez la prochaine mise a jour. Timout, vérifier votre connection internet. Une erreur inconnue est survenue. - Cette musique n\'est pas disponible dans votre pays. + n\'est pas disponible dans votre pays. ne peut pas être lu, l\'audio n\'est pas disponible. Vous n\'êtes pas connecté a internet, impossible de verifier si des mises à jour existent. La version %1$s est disponible diff --git a/Opus/Resources/values/strings.xml b/Opus/Resources/values/strings.xml index 51a3029..f7a220f 100644 --- a/Opus/Resources/values/strings.xml +++ b/Opus/Resources/values/strings.xml @@ -184,7 +184,7 @@ The way youtube play video has changed, the app can\'t play this video now. Wait for the next update. Timout, check if you\'re still connected to internet. An unknown error has occured. - This song is not available in your country. + is not available in your country. can\'t be played. No audio streams are availables. You are not connected to internet, can\'t check for updates. The version %1$s is available