예제 #1
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);
                }
            }
        }
예제 #2
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);
        }
예제 #3
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);
        }