// Pause / Resume private void pausebutton_Click(object sender, EventArgs e) { if (ispaused) { // Continue playing if (onscreen) { InterProcess.SendMessage(InterProcess.MSG_MEDIA_RESUME, 0); } else { player.Ctlcontrols.play(); } pausebutton.Text = "Pause"; pausebutton.StopInfoFlash(); ispaused = false; } else { // Pause if (onscreen) { InterProcess.SendMessage(InterProcess.MSG_MEDIA_PAUSE, 0); } else { player.Ctlcontrols.pause(); } pausebutton.Text = "Resume"; pausebutton.StartInfoFlash(); ispaused = true; } }
// This starts playing a file public void PlayFile(string filename, int startpos) { stopintended = false; player.URL = filename; // Wait for the player to load the file while ((player.playState == WMPPlayState.wmppsBuffering) || (player.playState == WMPPlayState.wmppsTransitioning) || (player.playState == WMPPlayState.wmppsReady)) { Application.DoEvents(); } // Send media length to gluon InterProcess.SendMessage(InterProcess.MSG_MEDIA_LENGTH, (int)player.currentMedia.duration); if (!string.IsNullOrEmpty(muxingfile)) { player.Visible = false; muxplayer.Visible = true; // Don't interrupt the muxed video if not needed if (muxingfile != muxingfileplaying) { muxingfileplaying = muxingfile; muxplayer.URL = muxingfile; // Wait for the player to load the file while ((player.playState == WMPPlayState.wmppsBuffering) || (player.playState == WMPPlayState.wmppsTransitioning) || (player.playState == WMPPlayState.wmppsReady)) { Application.DoEvents(); } // Play! muxplayer.Ctlcontrols.play(); } } else { player.Visible = true; muxplayer.Visible = false; muxplayer.close(); muxingfileplaying = ""; } // Play! player.Ctlcontrols.currentPosition = (double)startpos; player.Ctlcontrols.play(); updatetimer.Start(); }
// State changes private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) { // Media ended if ((e.newState == (int)WMPPlayState.wmppsStopped) && !stopintended && !stopeventblocker) { stopeventblocker = true; updatetimer.Stop(); // Let Gluon know the media has ended InterProcess.SendMessage(InterProcess.MSG_MEDIA_ENDED, 0); } else if (e.newState == (int)WMPPlayState.wmppsPlaying) { stopeventblocker = false; } }
// Stop playing private void stopbutton_Click(object sender, EventArgs e) { if (isplaying) { General.Power.EnablePowerSave(); } updatetimer.Stop(); stopintended = true; currentitem = -1; isplaying = false; ispaused = false; playingfile = ""; muxingfileplaying = ""; currentmediapos = 0; medialength = 0; lastplaylistitem = -1; seekbar.Visible = false; stopbutton.Visible = false; pausebutton.StopInfoFlash(); pausebutton.Visible = false; itemtitle.Text = ""; timelabel.Visible = false; totaltimelabel.Visible = false; positionlabel.Visible = false; onscreeninfo.Visible = false; UpdatePlaylistItems(); if (onscreen) { InterProcess.SendMessage(InterProcess.MSG_MEDIA_STOP, 0); } else { muxplayer.Ctlcontrols.stop(); muxplayer.close(); player.Ctlcontrols.stop(); player.close(); } }
// Mouse up on seek bar private void seekbar_MouseUp(object sender, MouseEventArgs e) { if ((e.Button == MouseButtons.Left) && seekbardragged) { if ((e.Y >= 0) && (e.Y < seekbar.ClientRectangle.Height)) { // Seek! double u = Tools.Clamp((double)e.X / (double)seekbar.ClientRectangle.Width, 0.0d, 1.0d); double dragtime = (double)medialength * u; if (onscreen) { InterProcess.SendMessage(InterProcess.MSG_MEDIA_SEEK, (int)dragtime); } else { player.Ctlcontrols.currentPosition = dragtime; } } seekbardragged = false; } }
// Send position updates to Gluon private void updatetimer_Tick(object sender, EventArgs e) { InterProcess.SendMessage(InterProcess.MSG_MEDIA_POSITION, (int)player.Ctlcontrols.currentPosition); }
// This tells the player to play a file private void PlayFile(string filepathname, int startpos) { if (!isplaying) { General.Power.DisablePowerSave(); } // Show the last two directories the file is in string displayfilepath = Path.GetFullPath(filepathname); string[] pathparts = displayfilepath.Split(Path.DirectorySeparatorChar); string displaypathtitle = ""; if (pathparts.Length > 2) { displaypathtitle += pathparts[pathparts.Length - 3] + " - "; } if (pathparts.Length > 1) { displaypathtitle += pathparts[pathparts.Length - 2] + " - "; } itemtitle.Text = displaypathtitle + Path.GetFileNameWithoutExtension(filepathname); timelabel.Visible = false; totaltimelabel.Visible = false; positionlabel.Visible = false; currentmediapos = 0; medialength = 0; seekbar.MaxValue = 100; seekbar.MinValue = 0; seekbar.Value = 0; seekbar.Visible = true; stopbutton.Visible = true; pausebutton.StopInfoFlash(); pausebutton.Text = "Pause"; pausebutton.Visible = true; stopintended = false; isplaying = true; ispaused = false; playingfile = filepathname; player.close(); // Subtitle support! try { string fileext = Path.GetExtension(filepathname); string filewithoutext = filepathname.Substring(0, filepathname.Length - fileext.Length); string subtitlefile = filewithoutext + ".srt"; if (File.Exists(subtitlefile)) { // Copy subtitles to the subtitles location File.Copy(subtitlefile, General.Settings.SubtitlesFile, true); } else { // Make the subtitles file empty File.WriteAllText(General.Settings.SubtitlesFile, ""); } } catch (Exception e) { General.WriteLogLine(e.GetType().Name + " while creating subtitles file: " + e.Message); } if (onscreen) { // Send message onscreeninfo.Visible = true; MEDIASTARTDATA startdata = new MEDIASTARTDATA(); startdata.muxfilename = muxingfile; startdata.filename = filepathname; startdata.startpos = startpos; InterProcess.SendMessage(InterProcess.MSG_MEDIA_START, startdata); } else { player.URL = filepathname; // Wait for the player to load the file while ((player.playState == WMPPlayState.wmppsBuffering) || (player.playState == WMPPlayState.wmppsTransitioning) || (player.playState == WMPPlayState.wmppsReady)) { Application.DoEvents(); } if (!string.IsNullOrEmpty(muxingfile)) { player.Visible = false; muxplayer.Visible = true; // Don't interrupt the muxed video if not needed if (muxingfile != muxingfileplaying) { muxingfileplaying = muxingfile; muxplayer.URL = muxingfile; // Wait for the player to load the file while ((player.playState == WMPPlayState.wmppsBuffering) || (player.playState == WMPPlayState.wmppsTransitioning) || (player.playState == WMPPlayState.wmppsReady)) { Application.DoEvents(); } // Play! muxplayer.Ctlcontrols.play(); } } else { player.Visible = true; muxplayer.Visible = false; muxplayer.close(); muxingfileplaying = ""; } // Play! player.Ctlcontrols.currentPosition = (double)startpos; player.Ctlcontrols.play(); ShowMediaInfo(startpos, (int)player.currentMedia.duration); updatetimer.Start(); } }