/// <summary> /// 播放 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPlay_Click(object sender, EventArgs e) { //设置按钮状态 btnPlay.Enabled = false; btnPause.Enabled = true; btnStop.Enabled = true; btnLast.Enabled = true; btnNext.Enabled = true; if (!media_is_open) { VlcPlayerCore.PlayFile(MediaUrl); } trPlayerProgress.SetRange(0, (int)VlcPlayerCore.Duration()); VlcPlayerCore.SetPlayTime(trPlayerProgress.Value); VlcPlayerCore.Play(); trPlayerProgress.Value = (int)VlcPlayerCore.GetPlayTime(); tmrProgress.Start(); is_playinig = true; media_is_open = true; lblVideoName.Text = Path.GetFileNameWithoutExtension(MediaUrl); lblVideoName.Show(); lblVideoName.BringToFront(); if (StartEvent != null) { StartEvent(this, new EventArgs()); } }
/// <summary> /// 播放进度滑块 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void trPlayerProgress_Scroll(object sender, EventArgs e) { if (is_playinig) { VlcPlayerCore.SetPlayTime(trPlayerProgress.Value); trPlayerProgress.Value = (int)VlcPlayerCore.GetPlayTime(); } }
/// <summary> /// 初始化播放器 /// </summary> public void InitPlayer() { //初始化播放器 VlcPluginPath = System.IO.Path.Combine(System.Environment.CurrentDirectory, "plugins"); _vlcPlayerCore = new VlcPlayerCore(VlcPluginPath); IntPtr render_wnd = plDisplayControl.Handle; _vlcPlayerCore.SetRenderWindow((int)render_wnd); trPlayerVolume.Value = 50; trPlayerProgress.Value = 0; }
/// <summary> /// 暂停 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPause_Click(object sender, EventArgs e) { //设置按钮状态 btnPlay.Enabled = true; btnPause.Enabled = false; btnStop.Enabled = true; btnLast.Enabled = true; btnNext.Enabled = true; VlcPlayerCore.Pause(); tmrProgress.Stop(); is_playinig = false; }
/// <summary> /// 前进 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNext_Click(object sender, EventArgs e) { //设置按钮状态 btnPlay.Enabled = false; btnPause.Enabled = true; btnStop.Enabled = true; btnLast.Enabled = true; btnNext.Enabled = true; VlcPlayerCore.Pause(); int time = (int)VlcPlayerCore.GetPlayTime() + 5; if (time < trPlayerProgress.Maximum) { VlcPlayerCore.SetPlayTime(time); } else { VlcPlayerCore.SetPlayTime(trPlayerProgress.Maximum); } VlcPlayerCore.Play(); trPlayerProgress.Value = (int)VlcPlayerCore.GetPlayTime(); }
/// <summary> /// 停止 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStop_Click(object sender, EventArgs e) { //设置按钮状态 btnPlay.Enabled = true; btnPause.Enabled = false; btnStop.Enabled = false; btnLast.Enabled = false; btnNext.Enabled = false; VlcPlayerCore.Stop(); tmrProgress.Stop(); is_playinig = false; media_is_open = false; lblPlayerTimeRange.Text = "00:00:00/00:00:00"; trPlayerProgress.Value = 0; lblVideoName.Hide(); if (StopEvent != null) { StopEvent(this, new EventArgs()); } }
/// <summary> /// 设置媒体文件 /// </summary> /// <param name="url"></param> public void SetMediaUrl(string urls) { MediaUrl = urls; VlcPlayerCore.PlayFile(MediaUrl); trPlayerProgress.SetRange(0, (int)VlcPlayerCore.Duration()); trPlayerProgress.Value = 0; tmrProgress.Start(); is_playinig = true; media_is_open = true; lblVideoName.Text = Path.GetFileNameWithoutExtension(MediaUrl); lblVideoName.Show(); //设置按钮状态 btnPlay.Enabled = true; btnPause.Enabled = false; btnStop.Enabled = false; btnLast.Enabled = false; btnNext.Enabled = false; btnPlay.PerformClick(); }