Exemplo n.º 1
0
        // Subscriber
        private void SetTimerAndTrackBar(TrackStatusEventArgs e)
        {
            trackBar.Maximum = _musicPlayer.GetSongLength();
            timer.Start();

            PlayerResumeHandler();
        }
Exemplo n.º 2
0
        // Subscriber
        public void ResetTimerAndTrackBar(TrackStatusEventArgs e)
        {
            timer.Stop();

            // Reset the posotion of thumb
            ResetTrackBar();
            // Reset icon of btn_StartPlayback
            btnStartPlayback.Content = FindResource("PlaybackCtrl_Play");
        }
Exemplo n.º 3
0
        public void Resume()
        {
            string cmd = "play MediaFile";

            error        = mciSendString(cmd, null, 0, IntPtr.Zero);
            PlayerStatus = PlaybackState.Playing;

            // Fire event
            TrackInfo            track;
            int                  trackIdx = trackQueue.Current(out track);
            TrackStatusEventArgs e        = new TrackStatusEventArgs(track, Properties.Settings.Default.TaskPlaylistGUID, trackIdx);

            PlayerStartedEvent(e);
        }
Exemplo n.º 4
0
        public void UpdateTrackStatus(TrackStatusEventArgs e)
        {
            if (e == null || e.Index == -1)
            {
                return;
            }

            PlayingTrack = e.Track;
            TrackInfo track = soundtracks.FirstOrDefault(x => x.GUID == e.Track.GUID);

            if (track != null)
            {
                track.TrackStatus = e.Track.TrackStatus;
            }
            else
            {
                return;
            }
        }
Exemplo n.º 5
0
        public void SetTrackStatus(TrackStatusEventArgs e)
        {
            // Check
            if (e == null || e.Index == -1)
            {
                return;
            }

            TracksViewModel     tracksVM     = lv_Playlist.DataContext as TracksViewModel;
            TrackListsViewModel trackListsVM = lb_PlaylistMenu.DataContext as TrackListsViewModel;

            // TODO: try to rewrite this
            Playlist pl = trackListsVM.TrackLists.First(x => x.GUID == e.OwnerListGUID);

            pl.Soundtracks.Find(x => x.GUID == e.Track.GUID).TrackStatus = e.Track.TrackStatus;

            if (pl.GUID == e.OwnerListGUID)
            {
                tracksVM.UpdateTrackStatus(e);
            }
        }
Exemplo n.º 6
0
 public void HideTrackBar(TrackStatusEventArgs e)
 {
     TrackBar.Visibility = Visibility.Hidden;
 }
Exemplo n.º 7
0
 public void ShowTrackBar(TrackStatusEventArgs e)
 {
     TrackBar.Visibility = Visibility.Visible;
 }
Exemplo n.º 8
0
 public void ResetTrackProgress(TrackStatusEventArgs e)
 {
     TrackProgress.Content = "";
 }
Exemplo n.º 9
0
 public void ResetTrackName(TrackStatusEventArgs e)
 {
     TrackName.Content = "";
 }
Exemplo n.º 10
0
 public void SetTrackName(TrackStatusEventArgs e)
 {
     TrackName.Content = e.Track.TrackName;
 }
Exemplo n.º 11
0
 public void SetTrackLength(TrackStatusEventArgs e)
 {
     trackDuration = e.Track.Duration;
 }
Exemplo n.º 12
0
        public bool Play(TrackInfo track)
        {
            bool trackIsOpened = false;

            this.Stop();

            if (track == null)
            {
                PlayerStoppedEvent(null);

                // Once there is no more track can be popped out from trackQueue, it means that task is finished.
                ClearQueue();

                // Reset task info
                Properties.Settings.Default.TaskPlaylistGUID       = Guid.Empty;
                Properties.Settings.Default.TaskPlayingTrackIndex  = -1;
                Properties.Settings.Default.TaskPlayingTrackStatus = 0;
                Properties.Settings.Default.TaskPlaybackMode       = 0;
                Properties.Settings.Default.Save();
                return(false);
            }

            try
            {
                trackIsOpened = Open(track);
            }
            catch (FailedToOpenFileException ex_FailedToOpen)  // Unacceptable chars in file path
            {
                if (trackQueue == null)
                {
                    PlayerStoppedEvent(null);
                }
                else
                {
                    TrackInfo prevTrack;
                    int       prevTrackIdx = trackQueue.Current(out prevTrack);
                    prevTrack.TrackStatus = TrackStatus.IncorrectPath;
                    PlayerStoppedEvent(new TrackStatusEventArgs(prevTrack, Properties.Settings.Default.TaskPlaylistGUID, prevTrackIdx));
                }

                if (MPLiteSetting.KeepPlayingAfterCatchingError)
                {
                    TrackEndsEvent();
                }

                throw ex_FailedToOpen;
            }
            catch (InvalidFilePathException ex_InvaildPath)
            {
                track.TrackStatus = TrackStatus.IncorrectPath;
                Properties.Settings.Default.TaskPlayingTrackIndex  = CurrentTrackIndex;
                Properties.Settings.Default.TaskPlayingTrackStatus = (int)TrackStatus.IncorrectPath;
                Properties.Settings.Default.Save();

                if (trackQueue == null)
                {
                    PlayerStoppedEvent(null);
                }
                else
                {
                    TrackInfo prevTrack;
                    int       prevTrackIdx = trackQueue.Current(out prevTrack);
                    prevTrack.TrackStatus = TrackStatus.IncorrectPath;
                    PlayerStoppedEvent(new TrackStatusEventArgs(prevTrack, Properties.Settings.Default.TaskPlaylistGUID, prevTrackIdx));
                }

                if (MPLiteSetting.KeepPlayingAfterCatchingError)
                {
                    TrackEndsEvent();
                }

                throw ex_InvaildPath;
            }

            if (trackIsOpened)
            {
                string cmd = "play MediaFile";
                error = mciSendString(cmd, null, 0, IntPtr.Zero);

                if (error == 0)
                {
                    // Set volume
                    try
                    {
                        SetVolume(MPLiteSetting.Volume);
                    }
                    catch
                    {
                        throw;
                    }

                    // Save the trackInfo that is playing currently
                    CurrentTrack        = track;
                    CurrentTrackIndex   = trackQueue.Current();
                    CurrentPlaylistGUID = Properties.Settings.Default.TaskPlaylistGUID;
                    PlayerStatus        = PlaybackState.Playing;
                    track.TrackStatus   = TrackStatus.Playing;

                    Properties.Settings.Default.TaskPlayingTrackIndex  = CurrentTrackIndex;
                    Properties.Settings.Default.TaskPlayingTrackStatus = (int)TrackStatus.Playing;
                    Properties.Settings.Default.Save();

                    // Fire event to notify subscribers
                    int trackIdx           = CurrentTrackIndex;
                    TrackStatusEventArgs e = new TrackStatusEventArgs(track, Properties.Settings.Default.TaskPlaylistGUID, trackIdx);
                    PlayerStartedEvent(e);
                    return(true);
                }
                else
                {
                    Close();
                    return(false);
                }
            }
            else
            {
                // TODO: Exception handling
                return(false);
            }
        }