Ejemplo n.º 1
0
 public void Reset()
 {
     PlaylistSongCollection?.Clear();
     TracksCollection?.Clear();
     DontUpdatePosition = true;
     CurrentPosition    = 0;
     UpcomingSong       = null;
     timer.Stop();
     ShuffledList?.Clear();
     PlayPauseIcon = new SymbolIcon(Symbol.Play);
 }
Ejemplo n.º 2
0
        public async void Load(Mediafile mp3file, bool play = false, double currentPos = 0, double vol = 50)
        {
            if (mp3file != null)
            {
                try
                {
                    if (play == true)
                    {
                        Player.IgnoreErrors = true;
                    }

                    if (await Player.Load(mp3file))
                    {
                        TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; service.UpdateMediafile(file); }));
                        PlaylistSongCollection?.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                        PlayPauseCommand.IsEnabled = true;
                        mp3file.State = PlayerState.Playing;
                        if (Player.Volume == 50)
                        {
                            Player.Volume = vol;
                        }
                        if (play)
                        {
                            PlayPauseCommand.Execute(null);
                        }
                        else
                        {
                            DontUpdatePosition = true;
                            CurrentPosition    = currentPos;
                        }
                        if (GetPlayingCollection() != null)
                        {
                            UpcomingSong = await GetUpcomingSong();
                        }

                        Themes.ThemeManager.SetThemeColor(Player.CurrentlyPlayingFile.AttachedPicture);
                    }
                    else
                    {
                        BLogger.Logger.Error("Failed to load file. Loading next file...");
                        TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; service.UpdateMediafile(file); }));
                        PlaylistSongCollection?.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                        mp3file.State = PlayerState.Playing;
                        int indexoferrorfile = GetPlayingCollection().IndexOf(GetPlayingCollection().FirstOrDefault(t => t.Path == mp3file.Path));
                        Player.IgnoreErrors = false;
                        Load(await GetUpcomingSong(), true);
                    }
                }
                catch (Exception ex)
                {
                    BLogger.Logger.Error("Failed to load file.", ex);
                }
            }
        }
Ejemplo n.º 3
0
 private ThreadSafeObservableCollection <Mediafile> GetPlayingCollection()
 {
     if (PlaylistSongCollection?.Any(t => t.State == PlayerState.Playing) == true || IsPlayingFromPlaylist)
     {
         return(PlaylistSongCollection);
     }
     if (TracksCollection?.Elements.Any(t => t.State == PlayerState.Playing) == true)
     {
         return(TracksCollection.Elements);
     }
     return(null);
 }
Ejemplo n.º 4
0
        public async Task <Mediafile> GetUpcomingSong(bool isNext = false)
        {
            var playingCollection = GetPlayingCollection();

            NowPlayingQueue = playingCollection;
            if (playingCollection != null && playingCollection.Any())
            {
                try
                {
                    int indexOfCurrentlyPlayingFile = -1;
                    if (playingCollection.Any(t => t.State == PlayerState.Playing))
                    {
                        indexOfCurrentlyPlayingFile = playingCollection.IndexOf(playingCollection.FirstOrDefault(t => t.State == PlayerState.Playing));
                    }

                    Mediafile toPlayFile = null;
                    if (Shuffle)
                    {
                        if (_shuffledList.Count < playingCollection.Count || _shuffledList == null)
                        {
                            _shuffledList = await ShuffledCollection();

                            indexOfCurrentlyPlayingFile = 0;
                        }
                        toPlayFile = _shuffledList?.ElementAt(indexOfCurrentlyPlayingFile + 1);
                    }
                    else if (IsSourceGrouped)
                    {
                        toPlayFile = GetNextSongInGroup();
                    }
                    else
                    {
                        toPlayFile = indexOfCurrentlyPlayingFile <= playingCollection.Count - 2 && indexOfCurrentlyPlayingFile != -1 ? playingCollection.ElementAt(indexOfCurrentlyPlayingFile + 1) : Repeat == "Repeat List" || isNext?playingCollection.ElementAt(0) : null;
                    }
                    return(toPlayFile);
                }
                catch (Exception ex)
                {
                    BLogger.Logger.Error("An error occured while trying to play next song.", ex);
                    await NotificationManager.ShowMessageAsync("An error occured while trying to play next song. Trying again...");

                    TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(file => { file.State = PlayerState.Stopped; });
                    PlaylistSongCollection?.Where(t => t.State == PlayerState.Playing).ToList().ForEach(file => { file.State = PlayerState.Stopped; });
                    PlayNext();
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        public async Task <Mediafile> GetUpcomingSong(bool isNext = false)
        {
            var playingCollection = GetPlayingCollection();

            if (playingCollection != null && playingCollection.Any())
            {
                try
                {
                    int IndexOfCurrentlyPlayingFile = -1;
                    if (playingCollection.Any(t => t.State == PlayerState.Playing))
                    {
                        IndexOfCurrentlyPlayingFile = playingCollection.IndexOf(playingCollection.SingleOrDefault(t => t.State == PlayerState.Playing));
                    }
                    Mediafile toPlayFile = null;
                    if (Shuffle)
                    {
                        if (ShuffledList.Count < playingCollection.Count)
                        {
                            ShuffledList = await ShuffledCollection();

                            IndexOfCurrentlyPlayingFile = 0;
                        }
                        toPlayFile = ShuffledList?.ElementAt(IndexOfCurrentlyPlayingFile + 1);
                    }
                    else if (IsSourceGrouped)
                    {
                        toPlayFile = GetNextSongInGroup();
                    }
                    else
                    {
                        toPlayFile = IndexOfCurrentlyPlayingFile <= playingCollection.Count - 2 && IndexOfCurrentlyPlayingFile != -1 ? playingCollection.ElementAt(IndexOfCurrentlyPlayingFile + 1) : Repeat == "Repeat List" || isNext?playingCollection.ElementAt(0) : null;
                    }
                    return(toPlayFile);
                }
                catch
                {
                    await NotificationManager.ShowAsync("An error occured while trying to play next song. Trying again...");

                    TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                    PlaylistSongCollection?.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                    PlayNext();

                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
 private ThreadSafeObservableCollection <Mediafile> GetPlayingCollection()
 {
     if (Shuffle)
     {
         return(_shuffledList);
     }
     else
     {
         if (PlaylistSongCollection?.IsPlayingCollection() == true || IsPlayingFromPlaylist)
         {
             return(PlaylistSongCollection);
         }
         else if (TracksCollection?.Elements?.IsPlayingCollection() == true)
         {
             return(TracksCollection.Elements);
         }
     }
     if (NowPlayingQueue?.Any() == true)
     {
         return(NowPlayingQueue);
     }
     return(null);
 }
Ejemplo n.º 7
0
            private static PlaylistSongCollection GetContinuationPlaylistSongs(
                PlaylistSongCollection playlistSongCollection,
                string result,
                out string continuation)
            {
                continuation = string.Empty;
                var jo = JObject.Parse(result);
                var musicShelfRendererTokens = jo.Descendants().Where(t => t.Type == JTokenType.Property && ((JProperty)t).Name == "musicPlaylistShelfContinuation")
                                               .Select(p => ((JProperty)p).Value).ToList();

                foreach (var token in musicShelfRendererTokens)
                {
                    var msr = token.ToObject <BrowsePlaylistResultsContext.Musicplaylistshelfrenderer>();
                    if (msr.continuations != null &&
                        msr.continuations.Length > 0 &&
                        msr.continuations[0].nextContinuationData != null &&
                        msr.continuations[0].nextContinuationData.continuation != null)
                    {
                        continuation = msr.continuations[0].nextContinuationData.continuation;
                    }

                    int i = 0;
                    foreach (var content in msr.contents)
                    {
                        if (content.musicResponsiveListItemRenderer.fixedColumns != null)
                        {
                            try
                            {
                                string coverArtUrl = content.musicResponsiveListItemRenderer
                                                     .thumbnail
                                                     .musicThumbnailRenderer
                                                     .thumbnail
                                                     .thumbnails[0].url;

                                var song = new PlaylistSong
                                {
                                    Title = content.musicResponsiveListItemRenderer
                                            .flexColumns[0]
                                            .musicResponsiveListItemFlexColumnRenderer
                                            .text
                                            .runs[0]
                                            .text,

                                    ArtistTitle = content.musicResponsiveListItemRenderer
                                                  .flexColumns[1]
                                                  .musicResponsiveListItemFlexColumnRenderer
                                                  .text
                                                  .runs != null
                                                        ? content.musicResponsiveListItemRenderer
                                                  .flexColumns[1]
                                                  .musicResponsiveListItemFlexColumnRenderer
                                                  .text
                                                  .runs[0]
                                                  .text
                                                        : "",

                                    AlbumTitle = content.musicResponsiveListItemRenderer
                                                 .flexColumns[2]
                                                 .musicResponsiveListItemFlexColumnRenderer
                                                 .text
                                                 .runs != null
                                                        ? content.musicResponsiveListItemRenderer
                                                 .flexColumns[2]
                                                 .musicResponsiveListItemFlexColumnRenderer
                                                 .text
                                                 .runs[0]
                                                 .text
                                                        : "",

                                    Duration = content.musicResponsiveListItemRenderer
                                               .fixedColumns[0].musicResponsiveListItemFixedColumnRenderer
                                               .text
                                               .runs[0]
                                               .text,

                                    VideoId = GetVideoEntityId(content.musicResponsiveListItemRenderer
                                                               .menu
                                                               .menuRenderer),

                                    CoverArtUrl = coverArtUrl
                                };

                                playlistSongCollection.Add(song);
                            }
                            catch (Exception e)
                            {
                                var _ = e;
#if DEBUG
                                Console.Out.WriteLine(e.Message);
#endif
                                Logger.Log(e, "GetContinuationPlaylistSongs - Error fetching playlist items", Log.LogTypeEnum.Error);
                            }
                        }

                        i++;
                    }
                }

                return(playlistSongCollection);
            }