/// <summary> /// Plays the thread. /// </summary> /// <remarks>Documented by Dev02, 2008-02-22</remarks> private void PlayThread() { stopThread = false; while (true) { try { string filename = null; lock (playQueue) { while (playQueue.Count == 0 && !stopThread) Monitor.Wait(playQueue); if (playQueue.Count > 0 && !stopCurrentPlay) filename = playQueue.Dequeue(); } if (stopThread && filename == null) break; //play video file stopCurrentPlay = false; if (video != null) { video.Ctlcontrols.stop(); video = null; } if (filename != null) { #if debug_output Trace.WriteLine("Fetching video object for " + filename); #endif Owner.Invoke((Action)delegate() { video = new AxWindowsMediaPlayer(); video.BeginInit(); video.Location = new System.Drawing.Point(0, 0); video.Size = Owner.Size; Owner.Controls.Add(video); video.PlayStateChange += (s, e) => { if (video.playState == WMPPlayState.wmppsStopped) OnStopping(EventArgs.Empty); }; video.EndInit(); }); video.URL = filename; #if debug_output Trace.WriteLine(string.Format("Starting playing {0}. Duration: {1}.", filename, video.currentMedia.duration.ToString())); #endif video.Ctlcontrols.play(); while (video.playState == WMPPlayState.wmppsTransitioning || video.playState == WMPPlayState.wmppsBuffering) Thread.Sleep(25); //wait for completion while (video.Ctlcontrols.currentPosition < video.currentMedia.duration && (video.playState == WMPPlayState.wmppsPlaying || video.playState == WMPPlayState.wmppsBuffering)) { System.Threading.Thread.Sleep(100); if (stopCurrentPlay && (video.currentMedia.duration - video.Ctlcontrols.currentPosition) > 1) //don't stop short sounds break; } if (video.playState == WMPPlayState.wmppsPlaying) video.Ctlcontrols.stop(); else OnEnding(EventArgs.Empty); #if debug_output Trace.WriteLine("Finished/Stopped playing " + filename); #endif } } catch (Exception exp) { if (exp is FileNotFoundException) { //Display a message and terminate player thread //[ML-724] On-Stick-Mode: Audioplayer thread crashes when the stick is pulled off and plugged back in (DAC, 2008-03-05) System.Windows.Forms.MessageBox.Show(Resources.AUDIOPLAYER_CRASHED_TEXT, Resources.AUDIOPLAYER_CRASHED_CAPTION, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); break; } if (exp is ThreadAbortException) { Trace.WriteLine("AudioPlayer Thread terminated."); } else { try { Trace.WriteLine("AudioPlayer crashed: " + exp.ToString()); } catch { Trace.WriteLine("AudioPlayer crashed with unreadable exception!"); } break; } } } }
private static void CreateInstance() { // disable auto windows mediaplayer auto cd-play if (_wmp10Player != null) { return; } try { UInt32 dwValue = (UInt32)0; using (RegistryKey subkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\MediaPlayer\Preferences", true) ) { subkey.SetValue("CDAutoPlay", (Int32)dwValue); // enable metadata lookup for CD's dwValue = (UInt32)Convert.ToInt32(subkey.GetValue("MetadataRetrieval")); dwValue |= 1; subkey.SetValue("MetadataRetrieval", (Int32)dwValue); } } catch (Exception) {} _wmp10Player = new AxWindowsMediaPlayer(); _wmp10Player.BeginInit(); GUIGraphicsContext.form.SuspendLayout(); _wmp10Player.Enabled = true; ComponentResourceManager resources = new ComponentResourceManager(typeof (Resource1)); _wmp10Player.Location = new Point(8, 16); _wmp10Player.Name = "axWindowsMediaPlayer1"; _wmp10Player.OcxState = ((AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState"))); _wmp10Player.Size = new Size(264, 240); _wmp10Player.TabIndex = 0; GUIGraphicsContext.form.Controls.Add(_wmp10Player); try { _wmp10Player.EndInit(); } catch (COMException) {} _wmp10Player.uiMode = "none"; _wmp10Player.windowlessVideo = true; _wmp10Player.enableContextMenu = false; _wmp10Player.Ctlenabled = false; _wmp10Player.ClientSize = new Size(0, 0); _wmp10Player.Visible = false; GUIGraphicsContext.form.ResumeLayout(false); }
private bool Initialize() { bool result = true; if (!_Initialized) { Log.Info("WMPlayer: Initializing player ..."); LoadSettings(); _AxWMP = new AxWindowsMediaPlayer(); GUIGraphicsContext.form.SuspendLayout(); GUIGraphicsContext.form.Controls.Add(_AxWMP); GUIGraphicsContext.form.ResumeLayout(false); _AxWMP.BeginInit(); _AxWMP.Name = "AxWindowsMediaPlayer"; _AxWMP.Visible = false; _AxWMP.TabIndex = 0; _AxWMP.TabStop = false; _AxWMP.Location = new Point(0, 0); _AxWMP.Size = new Size(1, 1); // Only in "full" mode advanced Visualizations are supported. // The controls are hidden by positioning them outside the window. // See also Process(). _AxWMP.uiMode = "full"; _AxWMP.settings.autoStart = false; _AxWMP.settings.enableErrorDialogs = false; _AxWMP.settings.volume = 100; _AxWMP.network.bufferingTime = _BufferTime; _AxWMP.windowlessVideo = false; _AxWMP.enableContextMenu = false; _AxWMP.Ctlenabled = false; _AxWMP.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(OnPlayStateChange); _AxWMP.Buffering += new AxWMPLib._WMPOCXEvents_BufferingEventHandler(OnBuffering); _AxWMP.EndInit(); _SavedFullScreenHandler = g_Player.ShowFullScreenWindowVideo; g_Player.ShowFullScreenWindowVideo = FullScreenHandler; GUIGraphicsContext.OnNewAction += new OnActionHandler(OnNewAction); GUIGraphicsContext.form.Disposed += new EventHandler(OnAppFormDisposed); _Timer.Elapsed += new System.Timers.ElapsedEventHandler(_Timer_Elapsed); if (result) { Log.Info("WMPlayer: Initializing complete."); _Initialized = true; } } return result; }