/// <summary> /// 鼠标抬起后进行进度切换,并等待切换完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pgrPlay_MouseUp(object sender, MouseEventArgs e) { Debug.WriteLine("Mouse up"); if (mPlayer == IntPtr.Zero || mTotalTime < 1000) { return; } try { PlayerMethods.CEPlayer_Play(mPlayer); PlayerMethods.CEPlayer_Seek(mPlayer, this.pgrPlay.Value); mCurrentTime = PlayerMethods.GetLongParam(mPlayer, CE_PARAM_ID.PARAM_MEDIA_POSITION); } catch { } this.BeginInvoke(new Action(() => { for (int i = 0; i < 200; i++) { System.Threading.Thread.Sleep(5); Int64 curMs = PlayerMethods.GetLongParam(mPlayer, CE_PARAM_ID.PARAM_MEDIA_POSITION); if (Math.Abs(curMs - mCurrentTime) > 500) { break; } } tmrPlay.Start(); })); }
private bool StartPlay(string aUrl) { if (string.IsNullOrEmpty(aUrl)) { return false; } StopPlay(); Url = aUrl; this.btnPlay.Enabled = false; mTotalTime = 0; mCurrentTime = 0; this.mPlaySpeed = 100; try { Debug.WriteLine("Start play..."); // mPlayer = (IntPtr)Invoke(new Func<IntPtr>(() => PlayerMethods.CEPlayer_Open(Url, this.lblView.Handle, CE_VIDEO_RENDER_TYPE.VIDEO_RENDER_TYPE_GDI, // CE_VIDEO_SCALE_MODE.VIDEO_MODE_STRETCHED, 100, 50))); // this.trackVolume.Value = 7; int volume = -255 + this.trackVolume.Value * 50; mPlayer = PlayerMethods.CEPlayer_Open(this.Url, this.lblView.Handle, CE_VIDEO_RENDER_TYPE.VIDEO_RENDER_TYPE_GDI, this.chkScaleMode.Checked ? CE_VIDEO_SCALE_MODE.VIDEO_MODE_STRETCHED : CE_VIDEO_SCALE_MODE.VIDEO_MODE_LETTERBOX, 100, volume); // mPlayer = PlayerMethods.player_open(this.Url, this.lblView.Handle, IntPtr.Zero); Debug.WriteLine("Start playing..."); } catch (AccessViolationException ex) { Debug.WriteLine($"Stop ESC ex: {ex.Message}"); } catch (Exception ex) { mPlayer = IntPtr.Zero; MessageBox.Show($"播放流媒体失败:{ex.Message}"); this.btnPlay.Enabled = true; return false; } if (mPlayer == IntPtr.Zero) { MessageBox.Show("播放流媒体失败..."); this.btnPlay.Enabled = true; return false; } PlayerMethods.CEPlayer_Play(mPlayer); this.btnPlay.Enabled = true; return true; }