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

            PlayerResumeHandler();
        }
Example #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");
        }
Example #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);
        }
Example #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;
            }
        }
Example #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);
            }
        }
 public void HideTrackBar(TrackStatusEventArgs e)
 {
     TrackBar.Visibility = Visibility.Hidden;
 }
 public void ShowTrackBar(TrackStatusEventArgs e)
 {
     TrackBar.Visibility = Visibility.Visible;
 }
 public void ResetTrackProgress(TrackStatusEventArgs e)
 {
     TrackProgress.Content = "";
 }
 public void ResetTrackName(TrackStatusEventArgs e)
 {
     TrackName.Content = "";
 }
 public void SetTrackName(TrackStatusEventArgs e)
 {
     TrackName.Content = e.Track.TrackName;
 }
 public void SetTrackLength(TrackStatusEventArgs e)
 {
     trackDuration = e.Track.Duration;
 }
Example #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);
            }
        }