private void ChoiceProd_Click(object sender, RoutedEventArgs e) { Task.Run(() => { ServiceBusViewUpdate(0); isUpdatingServiceBus = true; if (streaming != null) { streaming.Stop(); } lock (lockS) streaming = streamingProd; Dispatcher.Invoke(() => xState.Content = "Prod", System.Windows.Threading.DispatcherPriority.Background); streaming.Run(); StreamingViewUpdateStart(); }); }
private void PlayRadio(Radio SelectedRadio, bool Store = true, bool LoadTime = true) { // If there is a long file currently playing, store the playback status if (MusicOutput.PlaybackState == PlaybackState.Playing) { Progress[Selected] = MusicFile.CurrentTime; } // Stop all of the inputs Streaming.Stop(); MusicOutput.Stop(); Game.RadioStation = RadioStation.RadioOff; // If the chosen radio is vanilla if (SelectedRadio.Type == RadioType.Vanilla) { Game.RadioStation = (RadioStation)SelectedRadio.ID; } // If the radio is a single large file else if (SelectedRadio.Type == RadioType.SingleFile || SelectedRadio.Type == RadioType.Radio) { if (MusicFile != null) { MusicFile.Dispose(); } if (SelectedRadio.Type == RadioType.Radio && !CurrentSong.ContainsKey(SelectedRadio)) { CurrentSong[SelectedRadio] = SelectedRadio.Songs[Randomizer.Next(SelectedRadio.Songs.Count)]; } string SongFile = SelectedRadio.Type == RadioType.SingleFile ? Path.Combine(DataFolder, "Radios", SelectedRadio.Location) : Path.Combine(DataFolder, "Radios", SelectedRadio.Location, CurrentSong[SelectedRadio].File); if (!File.Exists(SongFile)) { UI.Notify($"Error: The file {SongFile} does not exists"); goto FinishChange; } // "The data specified for the media type is invalid, inconsistent, or not supported by this object." with MediaFoundationReader if (SelectedRadio.CodecFix) { WaveFileReader TempWave = new WaveFileReader(SongFile); MusicFile = WaveFormatConversionStream.CreatePcmStream(TempWave); } else { MusicFile = new MediaFoundationReader(SongFile); } MusicOutput.Init(MusicFile); if (LoadTime) { if (Progress.ContainsKey(SelectedRadio)) { MusicFile.CurrentTime = Progress[SelectedRadio]; } else { int RandomPosition = Randomizer.Next((int)MusicFile.TotalTime.TotalSeconds); TimeSpan RandomTimeSpan = TimeSpan.FromSeconds(RandomPosition); MusicFile.CurrentTime = RandomTimeSpan; } } MusicOutput.Play(); MusicOutput.Volume = UserSettings.Volume; } // If the radio is a stream else if (SelectedRadio.Type == RadioType.Stream) { Game.RadioStation = RadioStation.RadioOff; Streaming.Play(SelectedRadio.Location, UserSettings.Volume); } // Set the next radio as the selected one if is required FinishChange: if (Store) { Selected = SelectedRadio; } }