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);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles mouse click events for both Host and Fullscreen.
        /// </summary>
        private void HandleMouseAction(object sender, MouseButtonEventArgs e, int clickCount)
        {
            bool IsFullScreen = sender is FullScreenUI;

            if (IsActionFullScreen(e, clickCount))
            {
                FullScreen = !IsFullScreen; // using !FullScreen can return wrong value when exiting fullscreen
                e.Handled  = true;
            }
            else if (IsActionPause(e, clickCount))
            {
                if (PlayPauseCommand.CanExecute(null))
                {
                    PlayPauseCommand.Execute(null);
                }
                e.Handled = true;
            }
        }
Beispiel #3
0
        private async void Load(object mp3file, bool play = false)
        {
            StorageFile file = mp3file as StorageFile;

            if (file != null)
            {
                await player.Load(file.Path);

                Length          = player.Length;
                CurrentPosition = 0;
                Tags            = player.Tags;
                if (play)
                {
                    PlayPauseCommand.IsEnabled = true;
                    PlayPauseCommand.Execute(null);
                }
            }
            GC.Collect();
        }
        public async void Load(Mediafile mp3file, bool play = false, double currentPos = 0, double vol = 50)
        {
            if (mp3file != null)
            {
                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?.Elements.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 (play)
                    {
                        PlayPauseCommand.Execute(null);
                    }
                    else
                    {
                        Player.Volume      = vol;
                        DontUpdatePosition = true;
                        CurrentPosition    = currentPos;
                    }
                    if (GetPlayingCollection() != null)
                    {
                        UpcomingSong = await GetUpcomingSong();
                    }
                }
                else
                {
                    TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; service.UpdateMediafile(file); }));
                    PlaylistSongCollection?.Elements.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);
                }
            }
        }
Beispiel #5
0
    /// <summary>
    /// Handles mouse click events for both Host and Fullscreen.
    /// </summary>
    private void HandleMouseAction(object?_, PointerPressedEventArgs e, int clickCount)
    {
        var isFullScreen = false; // sender is FullScreenUI;

        if (IsActionFullScreen(e.MouseButton, clickCount))
        {
            FullScreen = !isFullScreen; // using !FullScreen can return wrong value when exiting fullscreen
            e.Handled  = true;
        }
        else if (IsActionPause(e.MouseButton, clickCount))
        {
            if (PlayPauseCommand.CanExecute(null))
            {
                PlayPauseCommand.Execute(null);
            }

            e.Handled = true;
        }
    }
 public async void Load(Mediafile mp3file, bool play = false, double currentPos = 0, double vol = 50)
 {
     if (mp3file != null)
     {
         if (play == true)
         {
             Player.IgnoreErrors = true;
         }
         ChangePlayingSongState(PlayerState.Playing, PlayerState.Stopped);
         if (await Player.Load(mp3file))
         {
             PlayPauseCommand.IsEnabled = true;
             mp3file.State = PlayerState.Playing;
             if (LibVM.TracksCollection.Elements.Count(t => t.Path == Player.CurrentlyPlayingFile?.Path) < 2)
             {
                 var mp3 = LibVM.TracksCollection?.Elements?.SingleOrDefault(t => t.Path == Player.CurrentlyPlayingFile?.Path);
                 if (mp3 != null)
                 {
                     mp3.State = PlayerState.Playing;
                 }
             }
             if (play)
             {
                 PlayPauseCommand.Execute(null);
             }
             else
             {
                 Player.Volume      = vol;
                 DontUpdatePosition = true;
                 CurrentPosition    = currentPos;
             }
             UpcomingSong = await GetUpcomingSong();
         }
         else
         {
             mp3file.State = PlayerState.Playing;
             int indexoferrorfile = GetPlayingCollection().IndexOf(GetPlayingCollection().FirstOrDefault(t => t.Path == mp3file.Path));
             Player.IgnoreErrors = false;
             Load(await GetUpcomingSong(), true);
         }
     }
 }
 private async void Load(Mediafile mp3file, bool play = false, double currentPos = 0, double vol = 50)
 {
     if (mp3file != null)
     {
         if (await Player.Load(mp3file))
         {
             PlayPauseCommand.IsEnabled = true;
             if (play)
             {
                 PlayPauseCommand.Execute(null);
             }
             else
             {
                 Player.Volume      = vol;
                 DontUpdatePosition = true;
                 CurrentPosition    = currentPos;
             }
         }
     }
 }
Beispiel #8
0
 private async void Player_MediaEnded(object sender, Events.MediaEndedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
     {
         DontUpdatePosition = true;
         CurrentPosition    = 0;
         player.PlayerState = PlayerState.Stopped;
         if (!Repeat)
         {
             await player.Pause();
             timer.Stop();
             PlayPauseIcon      = new SymbolIcon(Symbol.Play);
             DontUpdatePosition = false;
         }
         else
         {
             timer.Start();
             DontUpdatePosition = false;
             PlayPauseCommand.Execute(null);
         }
     });
 }
Beispiel #9
0
        private async void Load(object mp3file, bool play = false, double currentPos = 0, double vol = 50)
        {
            StorageFile file = mp3file as StorageFile;

            if (file != null && file.FileType == ".mp3")
            {
                await player.Load(file.Path);

                Length = player.Length;
                PlayPauseCommand.IsEnabled = true;
                if (play)
                {
                    PlayPauseCommand.Execute(null);
                }
                else
                {
                    Volume             = vol;
                    DontUpdatePosition = true;
                    CurrentPosition    = currentPos;
                }
                Tags = player.Tags;
            }
            GC.Collect();
        }