示例#1
0
        // 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;
            }
        }
示例#2
0
        // Constructor
        public MediaPlayerDisplayForm()
        {
            InitializeComponent();

            // Setup player
            player.uiMode                         = "none";
            player.stretchToFit                   = true;
            player.Ctlenabled                     = false;
            player.enableContextMenu              = false;
            player.windowlessVideo                = true;
            player.settings.volume                = 100;
            player.settings.enableErrorDialogs    = false;
            muxplayer.uiMode                      = "none";
            muxplayer.stretchToFit                = true;
            muxplayer.Ctlenabled                  = false;
            muxplayer.enableContextMenu           = false;
            muxplayer.TabIndex                    = 20;
            muxplayer.windowlessVideo             = true;
            muxplayer.settings.volume             = 0;
            muxplayer.settings.enableErrorDialogs = false;
            muxplayer.settings.playCount          = 99999999;
            muxplayer.Visible                     = false;

            // Hook up inter-process communcation
            InterProcess.SendHWND(this.Handle);
            InterProcess.MessageHandler += MessageHandler;
        }
示例#3
0
        // 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;
            }
        }
示例#4
0
        // 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();
        }
示例#5
0
        // Receive messages
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case (int)InterProcess.WM_COPYDATA:
                InterProcess.HandleDataMessage(ref m);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
示例#6
0
        // 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;
            }
        }
示例#7
0
        // Receive messages
        public void MessageHandler(int msgtype, IntPtr msgdata)
        {
            switch (msgtype)
            {
            case (int)InterProcess.MSG_MEDIA_ENDED:
                MediaEnded();
                break;

            case (int)InterProcess.MSG_MEDIA_LENGTH:
                medialength = InterProcess.GetMessageData <int>(msgdata);
                ShowMediaInfo(currentmediapos, medialength);
                break;

            case (int)InterProcess.MSG_MEDIA_POSITION:
                currentmediapos = InterProcess.GetMessageData <int>(msgdata);
                ShowMediaInfo(currentmediapos, medialength);
                break;
            }
        }
示例#8
0
        // Receive messages
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            // Display sends us its HWND
            case (int)InterProcess.MSG_HWND:
                InterProcess.otherhwnd = m.WParam;
                break;

            // Data message
            case (int)InterProcess.WM_COPYDATA:
                InterProcess.HandleDataMessage(ref m);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
示例#9
0
        // 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();
            }
        }
示例#10
0
        // 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;
            }
        }
示例#11
0
 // Send position updates to Gluon
 private void updatetimer_Tick(object sender, EventArgs e)
 {
     InterProcess.SendMessage(InterProcess.MSG_MEDIA_POSITION, (int)player.Ctlcontrols.currentPosition);
 }
示例#12
0
        // 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();
            }
        }