Beispiel #1
0
        void TempUpPlayer_OnError(StreamPlayer obj)
        {
            lock (LockObject) {
                if (VolumeDownPlayer == null)
                {
                    if (VolumeUpPlayer != null)
                    {
                        VolumeDownPlayer = VolumeUpPlayer;
                        VolumeDownPlayer.VolumeDown();
                    }
                }
                else
                {
                    if (VolumeUpPlayer != null)
                    {
                        VolumeUpPlayer.Stop();
                        //VolumeUpPlayer.Dispose();
                        VolumeUpPlayer = null;
                    }
                }

                VolumeUpPlayer = null;
                TempUpPlayer   = null;
            }

            IsPlaying = false;

            if (OnError != null)
            {
                OnError();
            }
        }
Beispiel #2
0
        public bool PlayUri(string RadioUri)
        {
            try {
                lock (LockObject) {
                    if (TempUpPlayer != null)
                    {
                        lock (TempUpPlayer) {
                            TempUpPlayer.OnStartPlay     -= TempUpPlayer_OnStartPlay;
                            TempUpPlayer.OnStoped        -= TempUpPlayer_OnStoped;
                            TempUpPlayer.OnNewTrack      -= TempUpPlayer_OnNewTrack;
                            TempUpPlayer.OnError         -= TempUpPlayer_OnError;
                            TempUpPlayer.OnFftCalculated -= TempUpPlayer_OnFftCalculated;
                            TempUpPlayer.Stop();
                        }
                    }

                    TempUpPlayer                  = new StreamPlayer();
                    TempUpPlayer.OnStartPlay     += TempUpPlayer_OnStartPlay;
                    TempUpPlayer.OnStoped        += TempUpPlayer_OnStoped;
                    TempUpPlayer.OnNewTrack      += TempUpPlayer_OnNewTrack;
                    TempUpPlayer.OnError         += TempUpPlayer_OnError;
                    TempUpPlayer.OnFftCalculated += TempUpPlayer_OnFftCalculated;
                    TempUpPlayer.Volume           = MasterVolume;
                    TempUpPlayer.Play(RadioUri);
                    IsPlaying = true;
                }

                return(true);
            } catch (Exception e) {
                // Console.WriteLine(e.Message);
                return(false);
            }
        }
Beispiel #3
0
 public void VolumeDown()
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback((a) => {
         StreamPlayer ip = a as StreamPlayer;
         for (float v = LocalVolume; v > 0.0f; v -= 0.01f)
         {
             ip.volumeProvider.Volume = MasterVolume * v;
             LocalVolume = v;
             Thread.Sleep(15);
         }
         ip.Stop();
     }), this);
 }
Beispiel #4
0
        public SimpleRadio()
        {
            // Open the JSON files for reading
            foreach (string File in Directory.GetFiles("scripts\\SimpleRadio", "*.json"))
            {
                // Open the JSON files for reading
                using (StreamReader Reader = new StreamReader(File))
                {
                    // Read the file content
                    string JSON = Reader.ReadToEnd();
                    // Parse it
                    ConfigFile Config = JsonConvert.DeserializeObject <ConfigFile>(JSON);
                    // And add it onto the existing list of radios
                    Radios.AddRange(Config.Radios);
                    // Notify that we have loaded the file
                    UI.Notify($"List of radios loaded: {Config.Name} by {Config.Author}");
                }
            }

            // And add our events
            Tick += OnTickFixes;
            Tick += OnTickControls;
            Tick += OnTickDraw;
            MusicOutput.PlaybackStopped += OnFileStop;
            Aborted += (Sender, Args) => { Streaming.Stop(); };

            // Enable the mobile phone radio
            Function.Call(Hash.SET_MOBILE_PHONE_RADIO_STATE, true);

            // Set the selected radio as off, just in case
            Selected          = Radios[0];
            Game.RadioStation = RadioStation.RadioOff;

            // Order the radios by frequency
            Radios = Radios.OrderBy(X => X.Frequency).ToList();

            // Show the count of radios to the user
            UI.Notify($"Radios available: {Radios.Count}");
        }
Beispiel #5
0
 public void VolumeDownAndStop()
 {
     ThreadPool.QueueUserWorkItem(new WaitCallback((a) => {
         StreamPlayer ip = a as StreamPlayer;
         for (float v = LocalVolume; v > 0.0f; v -= 0.01f)
         {
             if (ip.volumeProvider != null)
             {
                 ip.volumeProvider.Volume = (float)CommandFactory.GlobalVolume * v;
             }
             LocalVolume = v;
             Thread.Sleep(15);
         }
         ip.Stop();
     }), this);
 }
Beispiel #6
0
 private void StopCommand_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     player.Stop(false);
 }