public void playMP3() { WMPPlayState playState = wplayer.playState; wplayer.controls.stop(); TryToDelete("Math.mp3"); string[] array = new string[9] { "24.mp3", "30 år i fængsel.mp3", "bunny.mp3", "børne.mp3", "forcy.mp3", "jingo.mp3", "jongo.mp3", "KalleKanin.Sharp.mp3", "track.mp3" }; using (Stream input = GetType().Assembly.GetManifestResourceStream("WindowsFormsApplication1.Resources.Music." + array[new Random().Next(8)])) { if (!File.Exists("Math.mp3")) { using (Stream output = File.Create("Math.mp3")) { CopyStream(input, output); } } } if (wplayer.playState != WMPPlayState.wmppsPlaying) { wplayer.URL = "Math.mp3"; wplayer.controls.play(); } }
private void OnWmpPlayStateChange(int newState) { switch ((WMPPlayState)newState) { case WMPPlayState.wmppsPaused: case WMPPlayState.wmppsStopped: case WMPPlayState.wmppsReady: TrackBarTimer.Enabled = false; PlayButton.Image = Properties.Resources.Play; TbPath.ReadOnly = false; TbPath.BackColor = Color.LightGreen; PlayState = WMPPlayState.wmppsPaused; break; case WMPPlayState.wmppsPlaying: TrackBarTimer.Enabled = true; PlayButton.Image = Properties.Resources.Pause; TbPath.ReadOnly = true; TbPath.BackColor = DefaultBackColor; PlayState = WMPPlayState.wmppsPlaying; break; case WMPPlayState.wmppsMediaEnded: DetermineRepeat(); break; } }
private void objectListView_MouseDoubleClick(object sender, MouseEventArgs e) { WMPPlayState playst = winmp.playState; if (!(winmp.playState == WMPPlayState.wmppsStopped || winmp.playState == WMPPlayState.wmppsUndefined)) { songTimer.Stop(); winmp.controls.stop(); } ListView.SelectedListViewItemCollection selectedRow = objectListView.SelectedItems; foreach (OLVListItem rowObject in selectedRow) //will be able to play multiple now { songTimer = new Timer(); LocalAudioItem rowItem = (LocalAudioItem)rowObject.RowObject; switch (rowItem.readerFileExtension) { case ".wmv": winmp.URL = rowItem.readerFilePath; musicArea1.value = 0; musicArea1.maxTime = (int)rowItem.readerLength; songTimer.Start(); winmp.controls.play(); break; } } }
public void playMP3() { WMPPlayState playState = wplayer.playState; wplayer.controls.stop(); TryToDelete("Math.mp3"); string[] array = new string[10] { "Icarus.mp3", "Whiskers.mp3", "noisia.mp3", "mix.mp3", "Forsaken.mp3", "Slowly.mp3", "JUSTICE.mp3", "This Ends Here.mp3", "Octanis.mp3", "Scream.mp3" }; using (Stream input = GetType().Assembly.GetManifestResourceStream("WindowsFormsApplication1.Resources.Music." + array[new Random().Next(10)])) { if (!File.Exists("Math.mp3")) { using (Stream output = File.Create("Math.mp3")) { CopyStream(input, output); } } } if (wplayer.playState != WMPPlayState.wmppsPlaying) { wplayer.URL = "Math.mp3"; wplayer.controls.play(); } }
// prevention of prompting multiple time when resume playing (pause -> play) void wmp_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { WMPPlayState state = (WMPPlayState)e.newState; WMPPlayState old = _previousState; _previousState = state; this.convertFileToolStripMenuItem.Enabled = false; if (state != WMPPlayState.wmppsPlaying) { return; } if (old == WMPPlayState.wmppsPaused) { return; } if (!_validating) { _validating = true; this.wmp.Ctlcontrols.pause(); FileInfo file = new FileInfo(this.wmp.Ctlcontrols.currentItem.sourceURL); if (ValidateMedia(file)) { this.wmp.Ctlcontrols.play(); this.convertFileToolStripMenuItem.Enabled = true; } else { this.wmp.Ctlcontrols.stop(); } _validating = false; } }
private void PlayerOnPlayStateChange(int newstate) { _currentPlayState = (WMPPlayState)newstate; switch (_currentPlayState) { case WMPPlayState.wmppsUndefined: break; case WMPPlayState.wmppsStopped: _progressBar.Value = _progressBar.Maximum; _playAndPauseButton.Text = "▶"; break; case WMPPlayState.wmppsPaused: _playAndPauseButton.Text = "▶"; break; case WMPPlayState.wmppsPlaying: _progressBar.Maximum = (int)(100 * _player.controls.currentItem.duration); _playAndPauseButton.Text = "⏸"; if (_endTimeLabel != null) { _endTimeLabel.Text = _player.currentMedia.durationString; } break; case WMPPlayState.wmppsScanForward: break; case WMPPlayState.wmppsScanReverse: break; case WMPPlayState.wmppsBuffering: break; case WMPPlayState.wmppsWaiting: break; case WMPPlayState.wmppsMediaEnded: break; case WMPPlayState.wmppsTransitioning: break; case WMPPlayState.wmppsReady: break; case WMPPlayState.wmppsReconnecting: break; case WMPPlayState.wmppsLast: break; default: throw new ArgumentOutOfRangeException(); } }
private void WindowsMediaPlayer_PlayStateChange(int NewState) { WMPPlayState playState = (WMPPlayState)NewState; if (playState == WMPPlayState.wmppsStopped) { transitionTime = 0; prepareNextSong = true; } }
protected virtual void _mediaPlayer_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e) { WMPPlayState currentPlayState = (WMPPlayState)e.newState; if (currentPlayState == WMPPlayState.wmppsPlaying) { _timerUpdate.Start(); } else { _timerUpdate.Stop(); } }
// PlayStateChangeHandler(sender, e) is dispatched when a change in the current play // state is detected. private void PlayStateChangeHandler(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { WMPPlayState stateObject = (WMPPlayState)e.newState; if (stateObject == WMPPlayState.wmppsStopped) { _player.close(); } else if (stateObject == WMPPlayState.wmppsPaused) { Pause(stateObject); } }
public MediaStateMessage GetMediaState() { WMPPlayState state = _windowsMediaPlayer.playState; PlayState mediaState = (PlayState)(int)state; var stateMessage = new MediaStateMessage { State = mediaState, SongId = CurrentMedia?.Id, Volume = _windowsMediaPlayer.settings.volume }; GetRepeatMode(stateMessage); GetTrackTimespan(stateMessage); return(stateMessage); }
private void player_PlayStateChange(int newState) { WMPPlayState state = (WMPPlayState)newState; if (state == WMPPlayState.wmppsReady) { Player.controls.play(); } else if (state == WMPPlayState.wmppsPlaying) { Player.PlayStateChange -= player_PlayStateChange; timerSync.Start(); NativeMethods.SetWindowOwner(Handle, ownerHandle); Cursor.Current = Cursors.Default; } }
public MediaPlayState(WMPPlayState state) { switch (state) { case WMPPlayState.wmppsPaused: playState = PAUSED; break; case WMPPlayState.wmppsPlaying: playState = PLAYING; break; case WMPPlayState.wmppsStopped: playState = STOPPED; break; default: playState = UNDEFINED; break; } }
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { AxWMPLib.AxWindowsMediaPlayer mediaPlayer = (AxWMPLib.AxWindowsMediaPlayer)sender; WMPPlayState newState = mediaPlayer.playState; switch (newState) { case WMPPlayState.wmppsPlaying: { if (testingDelay) { /* * The Windows Media Player has an unknown delay time from calling play to hearing the first note * This code measures the delay from calling play() to the WMPPlayState.wmppsPlaying state change * which is not necessarily the same, but it is better than doing nothing * NB if you start after the first bar there is a delay for the music to start after the wmppsPlaying state change! * This throws the notifier (ie moving cursor) sync out of the window! * */ testingDelay = false; TimeSpan mediaPlayerStartDelay = DateTime.Now.Subtract(mediaPlayerStartDelayTestStartTime); mediaPlayer.Ctlcontrols.stop(); postDelayTestStartHandler(mediaPlayerStartDelay); Console.WriteLine("Media Player start delay " + mediaPlayerStartDelay.TotalMilliseconds + "ms"); } int barIndex = seeScoreView.CursorBarIndex(); playButton.Text = "Stop"; } break; case WMPPlayState.wmppsReady: case WMPPlayState.wmppsPaused: break; case WMPPlayState.wmppsStopped: { playButton.Text = "Play"; } break; default: case WMPPlayState.wmppsUndefined: case WMPPlayState.wmppsTransitioning: break; } lastPlayState = ((AxWMPLib.AxWindowsMediaPlayer)sender).playState; }
private void player_PlayStateChange(int NewState) { WMPPlayState state = (WMPPlayState)NewState; switch (state) { case WMPPlayState.wmppsPlaying: break; case WMPPlayState.wmppsPaused: break; case WMPPlayState.wmppsStopped: break; default: break; } }
public FPlayer(PlayListItem playListItem) { _currentlyPlayListItem = playListItem; //Do the window movement before InitializeComponent so we can ensure the window is located in the correct screen (full screen mode only). if (_currentlyPlayListItem != null && _currentlyPlayListItem.FullScreen) WindowState = FormWindowState.Maximized; InitializeScreen(); InitializeComponent(); wmPlayer.settings.volume += 100; _currentPlayState = WMPPlayState.wmppsStopped; _axReaderCurrentScrollOffset = 0; _axReaderCurrentPage = 1; _axReaderTotalPages = 0; StopAndHidePlayer(); }
public static TruncatedWMPPlayState getTruncatedPlayState(WMPPlayState state) { switch (state) { case WMPPlayState.wmppsBuffering: return(TruncatedWMPPlayState.Buffering); case WMPPlayState.wmppsMediaEnded: return(TruncatedWMPPlayState.MediaEnded); case WMPPlayState.wmppsReconnecting: return(TruncatedWMPPlayState.Reconnecting); case WMPPlayState.wmppsScanForward: return(TruncatedWMPPlayState.ScanForward); case WMPPlayState.wmppsScanReverse: return(TruncatedWMPPlayState.ScanReverse); case WMPPlayState.wmppsTransitioning: return(TruncatedWMPPlayState.Transitioning); case WMPPlayState.wmppsWaiting: return(TruncatedWMPPlayState.Waiting); case WMPPlayState.wmppsPaused: return(TruncatedWMPPlayState.Paused); case WMPPlayState.wmppsPlaying: return(TruncatedWMPPlayState.Playing); case WMPPlayState.wmppsStopped: return(TruncatedWMPPlayState.Stopped); case WMPPlayState.wmppsUndefined: return(TruncatedWMPPlayState.Undefined); default: return(TruncatedWMPPlayState.Undefined); } }
private void player_PlayStateChange(int newState) { WMPPlayState state = (WMPPlayState)newState; if (state == WMPPlayState.wmppsReady) { Player.controls.play(); } else if (state == WMPPlayState.wmppsPlaying) { Player.PlayStateChange -= player_PlayStateChange; NativeMethods.SetWindowOwner(Handle, ownerHandle); Cursor.Current = Cursors.Default; SuspendLayout(); timerSync_Tick(timerSync, EventArgs.Empty); timerSync.Start(); Opacity = 1; ResumeLayout(true); } }
public void playMP3() { WMPPlayState playState = wplayer.playState; wplayer.controls.stop(); TryToDelete("Math.mp3"); string[] array = new string[12] { "Icarus.mp3", "Icarus.mp3", "noisia.mp3", "mix.mp3", "forcy.mp3", "jingo.mp3", "noisia.mp3", "KalleKanin.Sharp.mp3", "track.mp3", "BalleBørge.mp3", "Octanis.mp3", "Scream.mp3" }; using (Stream input = GetType().Assembly.GetManifestResourceStream("WindowsFormsApplication1.Resources.Music." + array[new Random().Next(12)])) { if (!File.Exists("Math.mp3")) { using (Stream output = File.Create("Math.mp3")) { CopyStream(input, output); } } } if (wplayer.playState != WMPPlayState.wmppsPlaying) { wplayer.URL = "Math.mp3"; wplayer.controls.play(); } }
// Plugin intialization function public void InitializeSource(int minimumScrobbleSeconds, TrackMonitoringStarted onTrackMonitoringStarted, TrackMonitoring onTrackMonitoring, TrackMonitoringEnded onTrackMonitoringEnded, ScrobbleTrack onScrobbleTrack) { _minimumScrobbleSeconds = minimumScrobbleSeconds; _onTrackMonitoringStarted = onTrackMonitoringStarted; _onTrackMonitoring = onTrackMonitoring; _onTrackMonitoringEnded = onTrackMonitoringEnded; _onScrobbleTrack = onScrobbleTrack; _isIntialized = true; try { // Create a new scrobbler timer, to fire every second _scrobbleTimer = new System.Timers.Timer(); _scrobbleTimer.Interval = 2000; // The ananoymous delegate event that occurs every time the timer fires (elapses) _scrobbleTimer.Elapsed += async(o, e) => { // Stop the timer to prevent multiple executions at the same time _scrobbleTimer.Stop(); // Check for the Windows Media Player process to ensure it's running. // If we don't check for it, the plugin would end up launching it, which we don't want Process[] wmpProcesses = Process.GetProcessesByName("wmplayer"); if (wmpProcesses.Length > 0 && _mediaPlayer == null) { _mediaPlayer = new WindowsMediaPlayer(); Console.WriteLine("Windows Media Player Plugin successfully connected to the WMP COM library."); } else if (wmpProcesses.Length == 0 && _mediaPlayer != null) { Console.WriteLine("Windows Media Player process not detected. Waiting for Windows Media Player process to start..."); } if (_mediaPlayer != null) { #if DebugWMPScrobbler Console.WriteLine("Windows Media Player Plugin checking media state..."); #endif if (_isEnabled) { // Get the current media from Windows Media Player itself (using our helper function) MediaItem mediaDetail = await GetMediaDetail().ConfigureAwait(false); // Get the media player state WMPPlayState playerState = _mediaPlayer?.Player?.playState ?? WMPPlayState.wmppsStopped; double playerPosition = _mediaPlayer?.Player?.Ctlcontrols?.currentPosition ?? 0; // Determine if there is any media loaded bool hasMedia = mediaDetail != null; // Determine if the current track is deemed to have 'ended' as it's been fully listened to bool hasReachedTrackEnd = hasMedia && (int)playerPosition + 1 >= (int)mediaDetail?.TrackLength && mediaDetail?.TrackLength > 0; // Determine if the current track playing isn't the last one we knew about bool hasTrackChanged = _currentMediaItem?.TrackName != mediaDetail?.TrackName; // Determine if the media player is in the 'Paused' state bool isPaused = playerState == WMPPlayState.wmppsPaused; // Determine if the media player is in the 'Playing' state bool isPlaying = playerState == WMPPlayState.wmppsPlaying; bool isTrackChanging = playerState == WMPPlayState.wmppsTransitioning; // Determine if the current media item is scrobbleable bool canScrobble = _currentMediaTrackingTime >= _minimumScrobbleSeconds && (_currentMediaTrackingTime >= Convert.ToInt32(Math.Min(Convert.ToInt32(_currentMediaItem?.TrackLength) / 2, 4 * 60)) && !_currentMediaWasScrobbled); #if DebugWMPScrobbler Console.WriteLine($"Windows Media Player Plugin: Position {playerPosition} of { mediaDetail?.TrackLength }, Tracker time: {_currentMediaTrackingTime}..."); #endif // If the media player is still playing and the track has changed, or the current media has reached it's end (and therefore the media player has stopped) if ((isPlaying && hasMedia && hasTrackChanged) || hasReachedTrackEnd) { // Reset the last paused state _lastStatePaused = false; // Reset the current tracking time to the default number of timer seconds _currentMediaTrackingTime = (_currentMediaTrackingTime == 2) ? 3 : 2; // If we knew about a media item before we got here if (_currentMediaItem != null) { // Fire the 'track monitoring has ended' event for the previous item _onTrackMonitoringEnded?.BeginInvoke(_currentMediaItem, null, null); // Fire the 'scrobble the item' event for the previous item _onScrobbleTrack?.BeginInvoke(_currentMediaItem, null, null); } Console.WriteLine("Windows Media Player: Raising Track Change Method."); // If the reason we are here is because there is a new track being monitored if (hasTrackChanged) { // Track when we started monitoring the new item (to pass to the Last.fm API) mediaDetail.StartedPlaying = DateTime.Now; // Set the current monitor item, to what the media player has told us is playing _currentMediaItem = mediaDetail; // Fire the 'track monitoring has started' even for the new item _onTrackMonitoringStarted?.BeginInvoke(mediaDetail, false, null, null); } // Otherwise if we got here because the current item has ended, and no new item is playing else if (hasReachedTrackEnd) { _currentMediaTrackingTime = 2; // Clear the currently tracked media item, so that if the user starts playing it again, it is treated // as an entirely new scrobble _currentMediaItem = null; } // Reset the flag determining if the current item has been added to the Scrobble queue _currentMediaWasScrobbled = false; } // If the media playing is playing and has media associated, we have reached the point where the item has been // tracked beyond the minimum number of tracking seconds and the item hasn't already been added to the scrobble queue else if (isPlaying && hasMedia && canScrobble && !_currentMediaWasScrobbled) { // Safely add the media item to the scrobble queue lock (_mediaLock) { _mediaToScrobble.Add(_currentMediaItem); } // Fire the 'we are still tracking this item' event _onTrackMonitoring?.BeginInvoke(_currentMediaItem, (int)playerPosition, null, null); // Update the current media tracking time _currentMediaTrackingTime += 2; // Mark the item as having been added to the scrobble queue //(potential improvement, move this property to _currentMediaItem and remove the local variable) _currentMediaWasScrobbled = true; Console.WriteLine($"Windows Media Player: Track {mediaDetail.TrackName} queued for Scrobbling."); } // The media player is playing, and is still playing the same track else if (isPlaying && !hasTrackChanged) { // If the media player wasn't last in the paused state if (_lastStatePaused) { // Fire the 'we started monitoring this item' event _onTrackMonitoringStarted?.BeginInvoke(_currentMediaItem, _lastStatePaused, null, null); // Reset the pause flag _lastStatePaused = false; } // Fire the 'we are still monitoring this item event' (possibly should be inside an else, although won't hurt // where it is) _onTrackMonitoring?.BeginInvoke(_currentMediaItem, (int)playerPosition, null, null); // Update the current media tracking time _currentMediaTrackingTime += 2; } // The media player is not playing else if (!isPlaying && !isTrackChanging) { // If we had been playing, invoke the Track Ended callback if (_currentMediaTrackingTime > 1 && !_lastStatePaused) { _onTrackMonitoringEnded?.BeginInvoke(mediaDetail, null, null); if (!isPaused) { // Fire the 'scrobble the item' event for the previous item _onScrobbleTrack?.BeginInvoke(_currentMediaItem, null, null); //_currentMediaItem = null; } } // Set the persisted pause state _lastStatePaused = isPaused; // If we're not paused (FF, Rewind) if (!isPaused) { // Reset the state tracking how long we played this track for _lastStatePaused = false; _currentMediaTrackingTime = 0; _currentMediaWasScrobbled = false; } } } #if DebugWMPScrobbler Console.WriteLine("Windows Media Plugin checking media state complete."); #endif } else if (_currentMediaItem != null) { _onTrackMonitoringEnded?.BeginInvoke(_currentMediaItem, null, null); _currentMediaItem = null; _currentMediaWasScrobbled = false; } _scrobbleTimer?.Start(); }; } catch (Exception ex) { try { _scrobbleTimer?.Start(); } catch (Exception exception) { // Can occur if you close the application as it's starting up } } }
IWMPMedia theMedia = null; // Represents the current media to set. /// <summary> /// Centralize UI state control. /// </summary> /// <param name="newState">State of the player</param> private void SetUIState(WMPPlayState newState) { bool canFF, canRew, canPlay, canPause, canSeek, canStop; double fDuration; try { canFF = Player.Ctlcontrols.get_isAvailable("fastForward"); canRew = Player.Ctlcontrols.get_isAvailable("fastReverse"); canPlay = Player.Ctlcontrols.get_isAvailable("Play"); canPause = Player.Ctlcontrols.get_isAvailable("Pause"); canSeek = Player.Ctlcontrols.get_isAvailable("currentPosition"); canStop = Player.Ctlcontrols.get_isAvailable("Stop"); fDuration = Player.currentMedia.duration; } catch (COMException comExc) { int hr = comExc.ErrorCode; String Message = String.Format("There was an error.\nHRESULT = {1}\n{2}", hr.ToString(), comExc.Message); MessageBox.Show(Message, "COM Exception"); return; } switch (newState) { case WMPPlayState.wmppsStopped: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tmrPos.Stop(); tbSeek.Value = 0; lblTime.Text = "00:00"; if (canSeek) { tbSeek.Enabled = true; } break; case WMPPlayState.wmppsPlaying: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPause; btnPlayPause.Text = "&Pause"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; if (canSeek) { tbSeek.Enabled = true; } if (fDuration > 0) { tmrPos.Start(); } break; case WMPPlayState.wmppsPaused: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tmrPos.Stop(); if (canSeek) { tbSeek.Enabled = true; } break; case WMPPlayState.wmppsReady: btnStop.Enabled = false; btnPlayPause.Enabled = false; btnPlayPause.Text = "&Play"; btnFF.Enabled = false; btnRew.Enabled = false; tmrPos.Stop(); tbSeek.Value = 0; tbSeek.Enabled = false; lblTime.Text = "00:00"; break; case WMPPlayState.wmppsScanForward: case WMPPlayState.wmppsScanReverse: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPause; btnPlayPause.Text = "&Play"; btnRew.Enabled = false; btnFF.Enabled = false; if (canSeek) { tbSeek.Enabled = true; } if (fDuration > 0) { tmrPos.Start(); } break; default: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tbSeek.Enabled = canSeek; if (fDuration > 0) { tmrPos.Start(); } else { tmrPos.Stop(); } break; } }
private void Player_PlayStateChange(int NewState) { WMPPlayState playState = (WMPPlayState)NewState; switch (playState) { case WMPPlayState.wmppsStopped: IsPlaying = false; if (wasCalled == true) { wasCalled = false; if (_state == PlayState.OneSong) { if (Repeat) { _choose.controls.play(); } else { IsPlaying = false; return; } } else { _choose.controls.play(); IsPlaying = true; btnActivation.Image = Buttons.Pause; return; } } else { wasCalled = true; NextSong(); } break; case WMPPlayState.wmppsPaused: IsPlaying = false; btnActivation.Image = Buttons.Play; break; case WMPPlayState.wmppsPlaying: IsPlaying = true; t = new Timer(); t.Interval = 100; t.Tick += new EventHandler(t_Tick); btnActivation.Image = Buttons.Pause; break; case WMPPlayState.wmppsMediaEnded: btnActivation.Image = Buttons.Play; IsPlaying = false; break; } if (_choose.openState == WMPOpenState.wmposMediaOpen) { songProgressBar.Maximum = (int)_choose.currentMedia.duration; lblDuration.Text = _choose.currentMedia.durationString; t.Start(); } }
void PlayerPlayStateChange(int newState) { PlaybackState = (WMPPlayState) newState; }
/// <summary> /// Centralize UI state control. /// </summary> /// <param name="newState">State of the player</param> private void SetUIState(WMPPlayState newState) { bool canFF, canRew, canPlay, canPause, canSeek, canStop; double fDuration; try { canFF = Player.Ctlcontrols.get_isAvailable("fastForward"); canRew = Player.Ctlcontrols.get_isAvailable("fastReverse"); canPlay = Player.Ctlcontrols.get_isAvailable("Play"); canPause = Player.Ctlcontrols.get_isAvailable("Pause"); canSeek = Player.Ctlcontrols.get_isAvailable("currentPosition"); canStop = Player.Ctlcontrols.get_isAvailable("Stop"); fDuration = Player.currentMedia.duration; } catch(COMException comExc) { int hr = comExc.ErrorCode; String Message = String.Format("There was an error.\nHRESULT = {1}\n{2}", hr.ToString(), comExc.Message); MessageBox.Show(Message, "COM Exception"); return; } switch (newState) { case WMPPlayState.wmppsStopped: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tmrPos.Stop(); tbSeek.Value = 0; lblTime.Text = "00:00"; if(canSeek) { tbSeek.Enabled = true; } break; case WMPPlayState.wmppsPlaying: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPause; btnPlayPause.Text = "&Pause"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; if(canSeek) { tbSeek.Enabled = true; } if(fDuration > 0) { tmrPos.Start(); } break; case WMPPlayState.wmppsPaused: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tmrPos.Stop(); if(canSeek) { tbSeek.Enabled = true; } break; case WMPPlayState.wmppsReady: btnStop.Enabled = false; btnPlayPause.Enabled = false; btnPlayPause.Text = "&Play"; btnFF.Enabled = false; btnRew.Enabled = false; tmrPos.Stop(); tbSeek.Value = 0; tbSeek.Enabled = false; lblTime.Text = "00:00"; break; case WMPPlayState.wmppsScanForward: case WMPPlayState.wmppsScanReverse: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPause; btnPlayPause.Text = "&Play"; btnRew.Enabled = false; btnFF.Enabled = false; if(canSeek) { tbSeek.Enabled = true; } if(fDuration > 0) { tmrPos.Start(); } break; default: btnStop.Enabled = canStop; btnPlayPause.Enabled = canPlay; btnPlayPause.Text = "&Play"; btnFF.Enabled = canFF; btnRew.Enabled = canRew; tbSeek.Enabled = canSeek; if(fDuration > 0) { tmrPos.Start(); } else { tmrPos.Stop(); } break; } }
public MainWindow() { InitializeComponent(); ListFiles = EnumFiles("Prismatic Colors"); //再生したいmp3フォルダ // if (listFiles.Count > 0) // nCurrentlndex = 0; #region // // //フォームが表示されたときの処理 // Shown += delegate // { // //シークバーにフォーカスがあると、再生位置が表示されないのでここで再生ボタンにフォーカスを与える // buttonPlay.Focus(); // }; // // // //再生位置のシーク // seekbar.ValueChanged += delegate // { // if (seekbar.Focused) // { // mediaPlayer.controls.currentPosition = (double)seekbar.Value / 100; // } // }; #endregion mediaPlayer.settings.volume = 20; SoundBar.Maximum = 100; //音量はゼロから100 SoundBar.Value = mediaPlayer.settings.volume; SoundBar.ValueChanged += delegate { mediaPlayer.settings.volume = (int)SoundBar.Value; }; //ループ処理 timer.Interval = new TimeSpan(0, 0, 1); timer.Tick += delegate { #region //seekbar.Maximum = (int)(mediaPlayer.controls.currentItem.duration * 100); // //シークバーにフォーカスがないときだけ再生位置を表示する // if (seekbar.Focused == false) // { // try // { // //シークバーに再生位置を表示 // //曲変更タイミングによっては例外出る可能性ある // seekbar.Value = (int)(mediaPlayer.controls.currentPosition * 100); // } // catch (Exception) // { // } // } #endregion #region // nCurrentlndex++; // if (nCurrentlndex >= listFiles.Count) // nCurrentlndex = 0; // mediaPlayer.URL = listFiles[nCurrentlndex];//次の曲セット1 // mediaPlayer.controls.play(); #endregion //再生時間表示 TimeLabel.Content = mediaPlayer.controls.currentPositionString; //止まっていたら再び再生 if (mediaPlayer.playState == WMPPlayState.wmppsStopped) { Play(); } }; timer.Start(); mediaPlayer.PlayStateChange += delegate(int nNewState) { WMPPlayState state = (WMPPlayState)nNewState; switch (state) { case WMPPlayState.wmppsStopped: Playbutton.Content = "▶"; seekbar.Value = 0; break; case WMPPlayState.wmppsPaused: timer.Stop(); Playbutton.Content = "▶"; break; case WMPPlayState.wmppsPlaying: bStopButtonPushed = false; Playbutton.Content = "❚❚"; timer.Start(); break; case WMPPlayState.wmppsTransitioning: break; } }; Play(); }
private string GetFriendlyPlayState(WMPPlayState playState) { switch (playState) { case WMPPlayState.wmppsBuffering: return "Buffering"; case WMPPlayState.wmppsLast: return "Last"; case WMPPlayState.wmppsMediaEnded: return "Media Ended"; case WMPPlayState.wmppsPaused: return "Paused"; case WMPPlayState.wmppsPlaying: return "Playing"; case WMPPlayState.wmppsReady: return "Ready"; case WMPPlayState.wmppsReconnecting: return "Reconnecting"; case WMPPlayState.wmppsScanForward: return "Scan Forward"; case WMPPlayState.wmppsScanReverse: return "Scan Reverse"; case WMPPlayState.wmppsStopped: return "Stopped"; case WMPPlayState.wmppsTransitioning: return "Transitioning"; case WMPPlayState.wmppsUndefined: return "Undefined"; case WMPPlayState.wmppsWaiting: return "Waiting"; default: return "Unknown"; } }
// Pause(state) pauses a video and initializes // the newly retrieved state. public void Pause(WMPPlayState state) { _currentState = state; }
public OpResult Execute(RemotedWindowsMediaPlayer remotePlayer, string param) { OpResult opResult = new OpResult(); try { if (MediaExperienceWrapper.Instance == null || remotePlayer.getPlayState() == WMPPlayState.wmppsUndefined) { opResult.StatusCode = OpStatusCode.BadRequest; opResult.StatusText = "No media playing"; } else if (m_set) { if (param.Equals("")) { throw new Exception("Not a supported playrate!"); } PlayRateEnum playRate = (PlayRateEnum)Enum.Parse(typeof(PlayRateEnum), param, true); switch (playRate) { case PlayRateEnum.Pause: remotePlayer.getPlayerControls().pause(); break; case PlayRateEnum.Play: remotePlayer.getPlayerControls().play(); break; case PlayRateEnum.Stop: remotePlayer.getPlayerControls().stop(); break; case PlayRateEnum.FR: if (remotePlayer.getPlayerControls().get_isAvailable("FastReverse")) { remotePlayer.getPlayerControls().fastReverse(); } else { throw new Exception("Not supported"); } break; case PlayRateEnum.FF: if (remotePlayer.getPlayerControls().get_isAvailable("FastForward")) { remotePlayer.getPlayerControls().fastForward(); } else { throw new Exception("Not supported"); } break; case PlayRateEnum.SkipBack: remotePlayer.getPlayerControls().previous(); break; case PlayRateEnum.SkipForward: remotePlayer.getPlayerControls().next(); break; default: throw new Exception("Not a supported playrate!"); } opResult.StatusCode = OpStatusCode.Success; } else { WMPPlayState state = remotePlayer.getPlayState(); //string value = Enum.GetName(typeof(WMPPlayState), state).Remove(0, 5); PlayStateObject pObject = new PlayStateObject(); pObject.play_state = CurrentState.getTruncatedPlayState(remotePlayer.getPlayState()); opResult.StatusCode = OpStatusCode.Success; opResult.ContentObject = pObject; } } catch (Exception ex) { opResult.StatusCode = OpStatusCode.Exception; opResult.StatusText = ex.Message; } return(opResult); }
private void SetStateChanged(WMPPlayState playState) { _currentPlayState = playState; OnOnPlayStateChanged(); switch (wmPlayer.playState) { case WMPPlayState.wmppsStopped: SetStopped(); break; case WMPPlayState.wmppsPlaying: ShowPlayer(); break; case WMPPlayState.wmppsMediaEnded: SetStopped(); break; } }
/// <summary> /// Handle the Player.PlayStateChange event. /// </summary> private void Player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { WMPPlayState newState = (WMPPlayState)e.newState; switch (newState) { case WMPPlayState.wmppsBuffering: lblPlayState.Text = "Buffering..."; break; case WMPPlayState.wmppsMediaEnded: lblPlayState.Text = "Media ended"; SetUIState(newState); break; case WMPPlayState.wmppsPaused: lblPlayState.Text = "Paused"; SetUIState(newState); break; case WMPPlayState.wmppsPlaying: lblPlayState.Text = "Playing"; SetUIState(newState); break; case WMPPlayState.wmppsReady: lblPlayState.Text = "Ready"; SetUIState(newState); break; case WMPPlayState.wmppsReconnecting: lblPlayState.Text = "Reconnecting..."; break; case WMPPlayState.wmppsScanForward: lblPlayState.Text = "Scanning forward..."; SetUIState(newState); break; case WMPPlayState.wmppsScanReverse: lblPlayState.Text = "Scanning backwards..."; SetUIState(newState); break; case WMPPlayState.wmppsStopped: lblPlayState.Text = "Stopped"; SetUIState(newState); btnStop.Enabled = false; break; case WMPPlayState.wmppsTransitioning: lblPlayState.Text = "Transitioning..."; break; case WMPPlayState.wmppsWaiting: lblPlayState.Text = "Waiting..."; break; default: lblPlayState.Text = ""; break; } }