Adding parse error catch and allow app to remove the current song or the only song of the queue.

This commit is contained in:
Tristan Roux
2019-04-07 19:56:18 +02:00
parent 609a61f4ab
commit d237b88481
7 changed files with 65 additions and 19 deletions

View File

@@ -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<TextView>(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<TextView>(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");

View File

@@ -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)
{

View File

@@ -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<ProgressBar>(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<ProgressBar>(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<ProgressBar>(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<ProgressBar>(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);
}

View File

@@ -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));

View File

@@ -184,7 +184,7 @@
<string name="youtube_endpoint">El algoritmo youtube a cambiado, la aplicación no puede leer este video.Espere la proxima actualización.</string>
<string name="timout">Timout, compruebe su conexión internet.</string>
<string name="unknow">Un error desconozido est sucedió.</string>
<string name="country_blocked">This song is not available in your country.</string>
<string name="country_blocked"> is not available in your country.</string>
<string name="not_streamable"> no pude ser reproducido, el audio no está disponible.</string> <!--A song title will be placed before this sentence-->
<string name="update_no_internet">No está conectado a internet, imposible de comprobar si existen actualizaciones.</string>
<string name="update">La versión %1$s está disponible</string> <!--%1$s will be replaced with the version number-->

View File

@@ -184,7 +184,7 @@
<string name="youtube_endpoint">L\'algorithme youtube a changé, l\'application ne peut plus lire cette vidéo. Attendez la prochaine mise a jour.</string>
<string name="timout">Timout, vérifier votre connection internet.</string>
<string name="unknow">Une erreur inconnue est survenue.</string>
<string name="country_blocked">Cette musique n\'est pas disponible dans votre pays.</string>
<string name="country_blocked"> n\'est pas disponible dans votre pays.</string>
<string name="not_streamable"> ne peut pas être lu, l\'audio n\'est pas disponible.</string> <!--//A song title will be placed before this sentence-->
<string name="update_no_internet">Vous n\'êtes pas connecté a internet, impossible de verifier si des mises à jour existent.</string>
<string name="update">La version %1$s est disponible</string> <!--//%1$s will be replaced with the version number-->

View File

@@ -184,7 +184,7 @@
<string name="youtube_endpoint">The way youtube play video has changed, the app can\'t play this video now. Wait for the next update.</string>
<string name="timout">Timout, check if you\'re still connected to internet.</string>
<string name="unknow">An unknown error has occured.</string>
<string name="country_blocked">This song is not available in your country.</string>
<string name="country_blocked"> is not available in your country.</string>
<string name="not_streamable"> can\'t be played. No audio streams are availables.</string> <!--A song title will be placed before this sentence-->
<string name="update_no_internet">You are not connected to internet, can\'t check for updates.</string>
<string name="update">The version %1$s is available</string> <!--//%1$s will be replaced with the version number-->