/// <summary> /// 主计时器,每50ms自动根据播放器的状态来控制播放器的动作和重绘视图 /// </summary>> private void time_Tick(Object sender, EventArgs e) { //获取player状态 Constant.PLAY_STATE state = (Constant.PLAY_STATE) this.player.GetState(); switch (state) { case Constant.PLAY_STATE.PS_PLAY: case Constant.PLAY_STATE.PS_PAUSED: //暂停状态 this.position = this.player.GetPosition(); this.duration = this.player.GetDuration(); //设置视频进度条值 this.pgb_time.DM_Value = this.position / Convert.ToDouble(this.duration) * 100.0; if (position > 7000 && position / 1000 % 7 == 0) { int time = Convert.ToInt32((position / 1000 / 7)); if (captionDic.ContainsKey(time)) { //player.SetConfig(511, time + " \r\n" + "00:00:" + time * 7 + ",500" + " --> 00:00:" + (time + 1) * 7 + ",000" + " \r\n" + captionDic[time]); label2.Text = captionDic[time]; //Console.WriteLine(time + " \r\n" + "00:00:" + time * 7 + ",500" + " --> 00:00:" + (time + 1) * 7 + ",000" + " \r\n" + captionDic[time]); } else { label2.Text = ""; } //isTest = true; } // CaptionThread.position = Convert.ToInt32(position); //设置 当前播放时间/视频总共时间 this.lb_time.Text = PlayHelper.GetTime(this.position) + " / " + PlayHelper.GetTime(this.duration); this.pgb_time.Invalidate(); UpdateVol(); break; } if (this.Full) { if ((this.LastCursorX == Cursor.Position.X) && (this.LastCursorY == Cursor.Position.Y)) { this.CursorStayTime++; } else { this.CursorStayTime = 0; } if (Cursor.Position.Y >= (Screen.PrimaryScreen.Bounds.Height - this.menuPanel.Height)) { this.menuPanel.BringToFront(); } else if (this.CursorStayTime >= this.CursorStayMaxTime) { this.player.BringToFront(); } this.LastCursorX = Cursor.Position.X; this.LastCursorY = Cursor.Position.Y; } }
//打开一个文件 public static VideoItem OpenFile() { OpenFileDialog dialog = new OpenFileDialog { Filter = "媒体文件|*.mp4;*.avi;*.rm;*.rmvb;*.flv;*.mkv;*.wmv;|所有文件|*.*" }; if (dialog.ShowDialog() == DialogResult.OK) { VideoItem newVideo = new VideoItem(dialog.SafeFileName, dialog.FileName); if (PlayHelper.isRightExt(newVideo)) { return(newVideo); } } return(null); }
/// <summary> /// 打开文件夹 /// </summary> private void 打开文件夹ToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { bool isEqual = false; //使用委托,指定规则 PlayHelper.LoopFolder(dialog.SelectedPath, delegate(FileInfo file) { //新建视频实体 VideoItem myitem = new VideoItem(file.Name, file.FullName); //如果支持此格式,并且不重复,加入视频列表 if (PlayHelper.isRightExt(myitem)) { isEqual = false; foreach (var item in this.videoList) { if (item.Name == myitem.Name) { isEqual = true; break; } } if (!isEqual) { this.videoList.Add(myitem); } } }); //重绘播放列表 if (this.player.GetState() == 0) { this.InitPlayListView(null); } else { this.InitPlayListView(this.playingItem); } } }
/// <summary> /// 主计时器,每50ms自动根据播放器的状态来控制播放器的动作和重绘视图 /// </summary>> private void time_Tick(Object sender, EventArgs e) { //获取player状态 Constant.PLAY_STATE state = (Constant.PLAY_STATE) this.player.GetState(); switch (state) { case Constant.PLAY_STATE.PS_PLAY: case Constant.PLAY_STATE.PS_PAUSED: //暂停状态 this.position = this.player.GetPosition(); this.duration = this.player.GetDuration(); //设置视频进度条值 this.pgb_time.DM_Value = this.position / Convert.ToDouble(this.duration) * 100.0; //设置 当前播放时间/视频总共时间 this.lb_time.Text = PlayHelper.GetTime(this.position) + " / " + PlayHelper.GetTime(this.duration); this.pgb_time.Invalidate(); UpdateVol(); break; } if (this.Full) { if ((this.LastCursorX == Cursor.Position.X) && (this.LastCursorY == Cursor.Position.Y)) { this.CursorStayTime++; } else { this.CursorStayTime = 0; } if (Cursor.Position.Y >= (Screen.PrimaryScreen.Bounds.Height - this.menuPanel.Height)) { this.menuPanel.BringToFront(); } else if (this.CursorStayTime >= this.CursorStayMaxTime) { this.player.BringToFront(); } this.LastCursorX = Cursor.Position.X; this.LastCursorY = Cursor.Position.Y; } }