Esempio n. 1
0
 private void RendererAddedSink(AVRendererDiscovery sender, AVRenderer renderer)
 {
     this.Dispatcher.BeginInvoke(new Action(() =>
     {
         if (!this.streamToMenu.DropDownItems.ContainsKey(renderer.UniqueDeviceName))
         {
             var menuItem = new System.Windows.Forms.ToolStripMenuItem
                                (renderer.FriendlyName, (renderer.device.favicon != null) ? renderer.device.favicon.ToBitmap() : null, streamMenu_RendererSelected)
             {
                 Name = renderer.UniqueDeviceName,
                 Tag  = renderer
             };
             this.streamToMenu.DropDownItems.Add(menuItem);
             if (renderer != null && renderer.Connections.Count > 0)
             {
                 var connectionAV = renderer.Connections[0] as AVConnection;
                 connectionAV.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(connectionAV_OnPlayStateChanged);
                 if (autoStreamTo.Any(r => r.Equals(renderer.FriendlyName, StringComparison.InvariantCultureIgnoreCase)))
                 {
                     streamMenu_RendererSelected(menuItem, EventArgs.Empty);
                 }
             }
         }
         if (this.streamToMenu.DropDownItems.ContainsKey(this.searchingItem.Name) && this.streamToMenu.DropDownItems.Count >= 2)
         {
             this.streamToMenu.DropDownItems.RemoveByKey(this.searchingItem.Name);
         }
     }));
 }
Esempio n. 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var startTest = 0;

start:
            var existingProcess = Process.GetProcessesByName(Constants.SWYH_PROCESS_NAME);

            if (existingProcess != null && existingProcess.Length > 1)
            {
                if (e.Args != null && e.Args.Contains(Constants.RESTART_ARGUMENT_NAME) && (startTest++) < Constants.NUMBER_OF_RESTART_TEST)
                {
                    Thread.Sleep(100);
                    goto start;
                }
                MessageBox.Show("Stream What You Hear is already running !", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                directClose = true;   //Skip the statements in Application_Exit function, otherwise it will casue null object exception
                this.Shutdown();
            }
            else
            {
                if (SWYH.Properties.Settings.Default.Debug)
                {
                    AppDomain.CurrentDomain.UnhandledException += (ss, ee) =>
                    {
                        var           ex    = (Exception)ee.ExceptionObject;
                        StringBuilder error = new StringBuilder();
                        error.AppendLine("Date: " + DateTime.Now.ToString());
                        error.AppendLine("Message: " + ex.Message);
                        error.AppendLine("Detail: " + ex.ToString());
                        error.AppendLine("------------------------------");
                        File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Constants.SWYH_CRASHLOG_FILENAME), error.ToString());
                        MessageBox.Show("An unhandled error has occured ! See the '" + Constants.SWYH_CRASHLOG_FILENAME + "' on your desktop for more information", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    };
                }
                if (new NAudio.CoreAudioApi.MMDeviceEnumerator().EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.DeviceState.Active).Count == 0)    //Check the available interface.
                {
                    System.Windows.Forms.MessageBox.Show("Unable to find your sound interface, please check your sound interface in control panel.", "Cannot find the sound interface");
                    directClose = true;    //Skip the statements in Application_Exit function, otherwise it will casue null object exception
                    this.Shutdown();
                }
                else
                {
                    this.CheckAutomaticDeviceStreamed(e);
                    this.CheckNewVersion();
                    this.InitializeUI();
                    DoStuff();
                    this.rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink)));
                    this.rendererDiscovery.OnRendererRemoved += new AVRendererDiscovery.DiscoveryHandler(new AVRendererDiscovery.DiscoveryHandler(RendererRemovedSink));
                    this.wasapiProvider = new WasapiProvider();
                    this.swyhDevice     = new SwyhDevice();
                    this.swyhDevice.Start();
                    notifyIcon.ShowBalloonTip(2000, "Stream What You Hear is running", "Right-click on this icon to show the menu !", System.Windows.Forms.ToolTipIcon.Info);
                }
            }
        }
Esempio n. 3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var startTest = 0;

start:
            var existingProcess = Process.GetProcessesByName(Constants.SWYH_PROCESS_NAME);

            if (existingProcess != null && existingProcess.Length > 1)
            {
                if (e.Args != null && e.Args.Contains(Constants.RESTART_ARGUMENT_NAME) && (startTest++) < Constants.NUMBER_OF_RESTART_TEST)
                {
                    Thread.Sleep(100);
                    goto start;
                }
                MessageBox.Show("Stream What You Hear is already running !", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                this.Shutdown();
            }
            else
            {
                if (SWYH.Properties.Settings.Default.Debug)
                {
                    AppDomain.CurrentDomain.UnhandledException += (ss, ee) =>
                    {
                        var           ex    = (Exception)ee.ExceptionObject;
                        StringBuilder error = new StringBuilder();
                        error.AppendLine("Date: " + DateTime.Now.ToString());
                        error.AppendLine("Message: " + ex.Message);
                        error.AppendLine("Detail: " + ex.ToString());
                        error.AppendLine("------------------------------");
                        File.AppendAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Constants.SWYH_CRASHLOG_FILENAME), error.ToString());
                        MessageBox.Show("An unhandled error has occured ! See the '" + Constants.SWYH_CRASHLOG_FILENAME + "' on your desktop for more information", "Stream What You Hear", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    };
                }
                this.CheckAutomaticDeviceStreamed(e);
                this.CheckNewVersion();
                this.InitializeUI();
                this.rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink)));
                this.rendererDiscovery.OnRendererRemoved += new AVRendererDiscovery.DiscoveryHandler(new AVRendererDiscovery.DiscoveryHandler(RendererRemovedSink));
                this.wasapiProvider = new WasapiProvider();
                this.swyhDevice     = new SwyhDevice();
                this.swyhDevice.Start();
                notifyIcon.ShowBalloonTip(2000, "Stream What You Hear is running", "Right-click on this icon to show the menu !", System.Windows.Forms.ToolTipIcon.Info);
            }
        }
Esempio n. 4
0
 private void RendererRemovedSink(AVRendererDiscovery sender, AVRenderer renderer)
 {
     this.Dispatcher.BeginInvoke(new Action(() =>
     {
         if (this.streamToMenu.DropDownItems.ContainsKey(renderer.UniqueDeviceName))
         {
             this.streamToMenu.DropDownItems.RemoveByKey(renderer.UniqueDeviceName);
             if (renderer != null && renderer.Connections.Count > 0)
             {
                 var connectionAV = renderer.Connections[0] as AVConnection;
                 connectionAV.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(connectionAV_OnPlayStateChanged);
             }
         }
         if (!this.streamToMenu.DropDownItems.ContainsKey(this.searchingItem.Name) && this.streamToMenu.DropDownItems.Count == 2)
         {
             this.streamToMenu.DropDownItems.Add(searchingItem);
         }
     }));
 }