Example #1
0
 protected override void OnExit(ExitEventArgs e)
 {
     if (_isInitialised)
     {
         ActiveRadio?.Stop();
         Bass.BASS_Free();
         _cts.Cancel();
         _trayIcon.Dispose();
         _mutex.ReleaseMutex();
     }
     InfovojnaRadio.Properties.Settings.Default.Save();
     base.OnExit(e);
 }
Example #2
0
        public App()
        {
            Instance = this;
            if (InfovojnaRadio.Properties.Settings.Default.Radios == null)
            {
                InfovojnaRadio.Properties.Settings.Default.Radios = new RadioCollection();
                InfovojnaRadio.Properties.Settings.Default.Radios.Add(new RadioEntry("InfoVojna", "http://stream.infovojna.sk:8000/live128"));
            }
            InfovojnaRadio.Properties.Settings.Default.Radios.CollectionChanged += (object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) =>
            {
                switch (e.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    foreach (RadioEntry item in e.NewItems)
                    {
                        _trayIcon.ContextMenu.MenuItems.Add(InfovojnaRadio.Properties.Settings.Default.Radios.Count, item.MenuItem);
                    }
                    if (_trayIcon.ContextMenu.MenuItems[1].Text.CompareTo("-") != 0)
                    {
                        _trayIcon.ContextMenu.MenuItems.Add(1, new MenuItem("-"));
                    }
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    RadioEntry radio = e.OldItems[0] as RadioEntry;
                    _trayIcon.ContextMenu.MenuItems.Remove(radio.MenuItem);
                    if (ActiveRadio?.Name.CompareTo(radio.Name) == 0)
                    {
                        if (ActiveRadio.IsActive)
                        {
                            ActiveRadio.Stop();
                            ActiveRadio = null;
                        }
                    }
                    if (InfovojnaRadio.Properties.Settings.Default.Radios.Count == 0)
                    {
                        _trayIcon.ContextMenu.MenuItems.RemoveAt(1);
                    }
                    break;
                }
            };
            InfovojnaRadio.Properties.Settings.Default.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
            {
                switch (e.PropertyName)
                {
                case "Autostart":
                    Uri         uriAppFile = new Uri(Assembly.GetExecutingAssembly().CodeBase);
                    RegistryKey runKey     = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", true);
                    if (InfovojnaRadio.Properties.Settings.Default.Autostart)
                    {
                        runKey.SetValue("Infovojna-radio", string.Format("\"{0}\"", uriAppFile.LocalPath), RegistryValueKind.String);
                    }
                    else
                    {
                        runKey.DeleteValue("Infovojna-radio", false);
                    }
                    runKey.Flush();
                    runKey.Close();
                    break;

                case "Balance":
                    if (ActiveRadio != null)
                    {
                        ActiveRadio.Balance = InfovojnaRadio.Properties.Settings.Default.Balance;
                    }
                    break;

                case "Mute":
                    if (ActiveRadio != null)
                    {
                        ActiveRadio.Mute = InfovojnaRadio.Properties.Settings.Default.Mute;
                    }
                    break;

                case "Volume":
                    if (ActiveRadio != null)
                    {
                        ActiveRadio.Volume = InfovojnaRadio.Properties.Settings.Default.Volume;
                    }
                    break;
                }
            };
        }
Example #3
0
 protected void CreateRadioMenu()
 {
     _trayIcon.ContextMenu = new ContextMenu();
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("Zastaviť prehrávanie", (object sender, EventArgs args) => { ActiveRadio?.Stop(); }));
     _trayIcon.ContextMenu.MenuItems[0].Enabled = false;
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
     foreach (RadioEntry radio in InfovojnaRadio.Properties.Settings.Default.Radios)
     {
         radio.OnBeforePlay += RadioBeforePlay;
         radio.OnAfterPlay  += RadioAfterPlay;
         _trayIcon.ContextMenu.MenuItems.Add(radio.MenuItem);
     }
     if (InfovojnaRadio.Properties.Settings.Default.Radios.Count > 0)
     {
         _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
     }
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("Nastavenia", (object sender, EventArgs args) =>
     {
         if (_preferencesWnd == null)
         {
             _preferencesWnd         = new PreferencesWindow();
             _preferencesWnd.Closed += (object sender2, EventArgs args2) => { _preferencesWnd = null; };
             _preferencesWnd.ShowDialog();
         }
         else
         {
             _preferencesWnd.Focus();
         }
     }));
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("O programe", (object sender, EventArgs args) =>
     {
         (new AboutWindow()).ShowDialog();
     }));
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("-"));
     _trayIcon.ContextMenu.MenuItems.Add(new MenuItem("Ukončiť", (object sender, EventArgs args) => { Shutdown(0); }));
 }
Example #4
0
 private void RadioBeforePlay(object sender, EventArgs args)
 {
     ActiveRadio?.Stop();
 }