// Custom message handler private void MessageHandler(int msgtype, IntPtr msgdata) { switch (msgtype) { case (int)InterProcess.MSG_MEDIA_PAUSE: player.Ctlcontrols.pause(); break; case (int)InterProcess.MSG_MEDIA_RESUME: player.Ctlcontrols.play(); break; case (int)InterProcess.MSG_MEDIA_SEEK: int pos = InterProcess.GetMessageData <int>(msgdata); player.Ctlcontrols.currentPosition = (double)pos; break; case (int)InterProcess.MSG_MEDIA_START: MEDIASTARTDATA startdata = InterProcess.GetMessageData <MEDIASTARTDATA>(msgdata); muxingfile = startdata.muxfilename; PlayFile(startdata.filename, startdata.startpos); break; case (int)InterProcess.MSG_MEDIA_STOP: stopintended = true; updatetimer.Stop(); muxingfileplaying = ""; muxplayer.Ctlcontrols.stop(); muxplayer.close(); player.Ctlcontrols.stop(); player.close(); break; } }
// 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(); } }