Beispiel #1
0
        bool videoHasAlreadyBeenStarted = false; //this is used for the windows media player fullscreen. WMP can only fullscreen once a video has been loaded, which means we have to attach the "start video fullscreen" preference code to the Playing event of the WMP control. However, if this check is made every time the playing event is fired, then if the user makes the choice of exiting fullscreen, then pauses the player and plays it again, fullscreen will be entered again - when they specifically chose to exit fullscreen. So at the start of loading each video I will set this to false, then at the end of the "playing" event for each player, I will set it to true. Then the fullscreen code for each player will check that this variable is false before making the WMP control fullscreen. Even though this isn't necessary for the quicktime player (it can go fullscreen before the video is loaded, so doesnt need events), I will make it work this way too for consistency.

        /// <remarks>
        /// The controller part of the app, goes with the partial Publisher.Designer class which defines the GUI
        /// </remarks>
        public Publish()
        {
            try
            {
                InitializeComponent();
            }
            catch (COMException)
            {
                //quicktime is not installed
                //if the user has not chosen to hide the warning message, show the message. Otherwise, if the user has previously clicked "Don't show this message again", don't show the message
                if (!Properties.Settings.Default.dismissQuicktimeWarning)
                {
                    using (CheckboxMessageBox box = new CheckboxMessageBox("Quicktime is not installed, using Windows Media Player instead. If you do not have the right WMP codecs installed, this might not work"))
                    {
                        bool dontshowagain = box.showMessage();                         //show the message box, and get the result of whether the dont show this again checkbox was checked
                        if (dontshowagain)                                              //if the user chose not to show the message again
                        {
                            Properties.Settings.Default.dismissQuicktimeWarning = true; //save the result of the user choosing to not show the message again.
                            Properties.Settings.Default.Save();
                        }
                    }
                }
                quicktimeAvailable = false; //quicktime isn't available

                //WMP is the only option available, so disable the option to "prefer" it from the file menu
                useWindowsMediaPlayerToolStripMenuItem.Enabled = false;
            }

            systemTrayIcon.Icon = Properties.Resources.icon;
            this.Icon           = Properties.Resources.icon;

            //check if Bonjour is installed and exit app if it isn't
            if (checkBonjourInstalled())
            {
                //display the right player (quicktime if it's available, WMP otherwise)
                if (quicktimeAvailable && !Properties.Settings.Default.useWMPInstead) //if quicktime is available, and the user hasn't chosen to use WMP instead, show quicktime
                {
                    useWindowsMediaPlayerToolStripMenuItem.Checked = false;
                    usingQuicktime = true;
                    quicktimePlayer.Show();
                    player.Dispose();
                    player = null;
                }
                else //otherwise, if quicktime isn't available, or the user has specifically chosen to use WMP instead, show WMP
                {
                    useWindowsMediaPlayerToolStripMenuItem.Checked = true;
                    usingQuicktime = false;
                    player.Show();
                    quicktimePlayer.Dispose();
                    quicktimePlayer = null;
                }

                //start the server to receive incoming connections from iOS devices
                theServer = new Server(port);
                theServer.Start();

                //add the delegate to do something when a client connects to the server
                theServer.clientConnected += new Server.clientConnectedHandler(theServer_clientConnected);

                //add the delegate to do something when the server sends a message to the client
                theServer.messageSent += new Server.messageSentHandler(theServer_messageSent);

                //add the delegate to do something when the client sends a play url request
                theServer.playURL += new Server.urlPlayMessageHandler(theServer_playURL);

                //add the delegate to do something when a playback event is received
                theServer.playbackEvent += new Server.playbackMessageHandler(theServer_playbackEvent);

                //add the delegate to do something when play image event is received
                theServer.playImage += new Server.imageMessageHandler(theServer_playImage);

                //add the delegate to do something when authorisation key is received from server
                theServer.authorisationRequest += new Server.authorisationRequestHandler(theServer_authorisationRequest);

                //check if the debug window should be displayed, and display it if so
                if (Properties.Settings.Default.debug == true)
                {
                    setDebugVisibility(true);
                }

                //Set the check next to the "Start videos fullscreen" box if needed
                startVideosFullscreenToolStripMenuItem.Checked = Properties.Settings.Default.startVideosFullscreen;

                //start publishing the airplay service over Bonjour.
                DoPublish();
            }
            else
            {
                //exit the application because bonjour isn't installed.
                if (System.Windows.Forms.Application.MessageLoop)
                {
                    // WinForms app
                    System.Windows.Forms.Application.Exit();
                }
                else
                {
                    // console app
                    System.Environment.Exit(1);
                }
            }
        }
        bool videoHasAlreadyBeenStarted = false; //this is used for the windows media player fullscreen. WMP can only fullscreen once a video has been loaded, which means we have to attach the "start video fullscreen" preference code to the Playing event of the WMP control. However, if this check is made every time the playing event is fired, then if the user makes the choice of exiting fullscreen, then pauses the player and plays it again, fullscreen will be entered again - when they specifically chose to exit fullscreen. So at the start of loading each video I will set this to false, then at the end of the "playing" event for each player, I will set it to true. Then the fullscreen code for each player will check that this variable is false before making the WMP control fullscreen. Even though this isn't necessary for the quicktime player (it can go fullscreen before the video is loaded, so doesnt need events), I will make it work this way too for consistency.

        #endregion Fields

        #region Constructors

        /// <remarks>
        /// The controller part of the app, goes with the partial Publisher.Designer class which defines the GUI
        /// </remarks>
        public Publish()
        {
            try
            {
                InitializeComponent();
            }
            catch (COMException)
            {
                //quicktime is not installed
                //if the user has not chosen to hide the warning message, show the message. Otherwise, if the user has previously clicked "Don't show this message again", don't show the message
                if (!Properties.Settings.Default.dismissQuicktimeWarning)
                {
                    using (CheckboxMessageBox box = new CheckboxMessageBox("Quicktime is not installed, using Windows Media Player instead. If you do not have the right WMP codecs installed, this might not work"))
                    {
                        bool dontshowagain = box.showMessage(); //show the message box, and get the result of whether the dont show this again checkbox was checked
                        if (dontshowagain) //if the user chose not to show the message again
                        {
                            Properties.Settings.Default.dismissQuicktimeWarning = true; //save the result of the user choosing to not show the message again.
                            Properties.Settings.Default.Save();
                        }
                    }
                }
                quicktimeAvailable = false; //quicktime isn't available

                //WMP is the only option available, so disable the option to "prefer" it from the file menu
                useWindowsMediaPlayerToolStripMenuItem.Enabled = false;
            }

            systemTrayIcon.Icon = Properties.Resources.icon;
            this.Icon = Properties.Resources.icon;

            //check if Bonjour is installed and exit app if it isn't
            if (checkBonjourInstalled())
            {
                //display the right player (quicktime if it's available, WMP otherwise)
                if (quicktimeAvailable && !Properties.Settings.Default.useWMPInstead) //if quicktime is available, and the user hasn't chosen to use WMP instead, show quicktime
                {
                    useWindowsMediaPlayerToolStripMenuItem.Checked = false;
                    usingQuicktime = true;
                    quicktimePlayer.Show();
                    player.Dispose();
                    player = null;
                }
                else //otherwise, if quicktime isn't available, or the user has specifically chosen to use WMP instead, show WMP
                {
                    useWindowsMediaPlayerToolStripMenuItem.Checked = true;
                    usingQuicktime = false;
                    player.Show();
                    quicktimePlayer.Dispose();
                    quicktimePlayer = null;
                }

                //start the server to receive incoming connections from iOS devices
                theServer = new Server(port);
                theServer.Start();

                //add the delegate to do something when a client connects to the server
                theServer.clientConnected += new Server.clientConnectedHandler(theServer_clientConnected);

                //add the delegate to do something when the server sends a message to the client
                theServer.messageSent += new Server.messageSentHandler(theServer_messageSent);

                //add the delegate to do something when the client sends a play url request
                theServer.playURL += new Server.urlPlayMessageHandler(theServer_playURL);

                //add the delegate to do something when a playback event is received
                theServer.playbackEvent += new Server.playbackMessageHandler(theServer_playbackEvent);

                //add the delegate to do something when play image event is received
                theServer.playImage += new Server.imageMessageHandler(theServer_playImage);

                //add the delegate to do something when authorisation key is received from server
                theServer.authorisationRequest += new Server.authorisationRequestHandler(theServer_authorisationRequest);

                //check if the debug window should be displayed, and display it if so
                if (Properties.Settings.Default.debug == true)
                {
                    setDebugVisibility(true);
                }

                //Set the check next to the "Start videos fullscreen" box if needed
                startVideosFullscreenToolStripMenuItem.Checked = Properties.Settings.Default.startVideosFullscreen;

                //start publishing the airplay service over Bonjour.
                DoPublish();
            }
            else
            {
                //exit the application because bonjour isn't installed.
                if (System.Windows.Forms.Application.MessageLoop)
                {
                    // WinForms app
                    System.Windows.Forms.Application.Exit();
                }
                else
                {
                    // console app
                    System.Environment.Exit(1);
                }
            }
        }