private void PlaySong() { PlaybackPercentage = 0.0; TimePlayed = "0:00"; if (SelectedSong == null) { PlaybackSymbol = MdlConstants.SymbolPlay; return; } if (_player.SongPlaybackState != PlaybackState.Stop) { _player.Stop(); } var songfile = FileLocator.FindSongPath(SelectedSong); try { _player.Play(songfile); PlaybackSymbol = MdlConstants.SymbolPause; } catch (Exception) { // if the exception was thrown, show message // and manually set STOP flag in order to not proceed to next song _player.IsStoppedManually = true; MessageBox.Show("Sorry, song could not be played"); } }
/// <summary> /// Play song currently active in the radio /// </summary> public async Task PlayCurrentSong() { if (_player.SongPlaybackState != PlaybackState.Stop) { _player.Stop(); } var songpath = FileLocator.FindSongPath(_radio.CurrentSong); try { _player.Play(songpath); } catch (Exception) { await _radio.MoveToNextSongAsync(); } }
/// <summary> /// Same as synchronous version but with async calls to EF /// </summary> private async Task <Song> SelectRandomSongAsync(int maxAttempts = 15) { var attempts = 0; Song song; // keep selecting song randomly until the song file is actually present in the file system... // ...and while it isn't present in archive of recently played songs and upcoming songs do { if (attempts++ == maxAttempts) { return(_songSelector.DefaultSong()); } song = await _songSelector.SelectSongAsync().ConfigureAwait(false); }while (SongArchive.Any(s => s.Id == song.Id) || // true, if the archive already contains this song UpcomingSongs.Any(s => s.Id == song.Id) || // true, if it is already in songlist song.Id == CurrentSong.Id || // true, if it's currently playing FileLocator.FindSongPath(song) == ""); // true, if the file with this song doesn't exist return(song); }
/// <summary> /// Play song currently active in the radio /// </summary> public void PlayCurrentSong() { if (_player.SongPlaybackState != PlaybackState.Stop) { _player.Stop(); } var songpath = FileLocator.FindSongPath(_radio.CurrentSong); try { _player.Play(songpath); } //catch (InvalidOperationException) //{ // some multi-threading issue in debug mode //} catch (Exception) { _radio.MoveToNextSong(); } }
public async Task <HttpResponseMessage> Stream() { var radioResponse = await client.GetAsync("radio/current"); var songModel = await radioResponse.Content.ReadAsAsync <SongModel>(); var song = new Song { Id = songModel.Id, Name = songModel.Name, TrackNo = songModel.TrackNo, Album = new Album { Name = songModel.Album, ReleaseYear = songModel.Year, Performer = new Performer { Name = songModel.Performer } }, }; var response = Request.CreateResponse(); response.Content = new PushStreamContent((a, b, c) => { var path = FileLocator.FindSongPath(song); var audio = new HttpFileStream(path); audio.WriteToStream(a, b, c); }, "audio/mpeg"); return(response); }