public async Task PreventsNextSongFromPlaying() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); int played = 0; audioPlayerCallback.PlayAsync().Returns(Task.Run(() => { if (played == 0) { library.AddAndSwitchToPlaylist("Playlist2", token); } played++; })); library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token); await library.PlaySongAsync(0, token); Assert.Equal(1, played); } }
public async Task SetsCurrentSongIndexIfChangingToOtherPlaylistAndPlayingFirstSong() { var settings = new CoreSettings { EnablePlaylistTimeout = false }; using (Library library = new LibraryBuilder().WithPlaylist().WithSettings(settings).Build()) { var coll = library.CurrentPlaylistChanged.StartWith(library.CurrentPlaylist) .Select(x => x.WhenAnyValue(y => y.CurrentSongIndex)).Switch().CreateCollection(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongToPlaylist(Helpers.SetupSongMock()); await library.PlaySongAsync(0, token); library.AddPlaylist("Playlist 2", token); library.SwitchToPlaylist(library.Playlists.Last(), token); library.AddSongToPlaylist(Helpers.SetupSongMock()); await library.PlaySongAsync(0, token); Assert.Equal(new int?[] { null, 0, null, null, 0, null }, coll); } }
public async Task SongPreparationCanTimeout() { await new TestScheduler().With(async sched => { var song = Substitute.For<Song>("C://", TimeSpan.Zero); song.PrepareAsync(Arg.Any<YoutubeStreamingQuality>()).Returns(Observable.Return(Unit.Default) .Delay(Library.PreparationTimeout + TimeSpan.FromSeconds(1), sched).ToTask()); var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(new[] { song }, token); Task play = library.PlaySongAsync(0, token); sched.AdvanceByMs((Library.PreparationTimeout + TimeSpan.FromSeconds(2)).TotalMilliseconds); await play; } audioPlayerCallback.DidNotReceiveWithAnyArgs().LoadAsync(Arg.Any<Uri>()); }); }
public async Task WhileSongIsPlayingStopsCurrentSong() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(Helpers.SetupSongMocks(1), token); var awaiter = library.PlaybackState.FirstAsync(x => x == AudioPlayerState.Finished).PublishLast(); awaiter.Connect(); await library.PlaySongAsync(0, token); library.RemoveFromPlaylist(new[] { 0 }, token); await awaiter.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task PlaysNextSongAutomatically() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(Helpers.SetupSongMocks(2), token); var conn = library.PlaybackState.Where(x => x == AudioPlayerState.Playing) .Take(2) .PublishLast(); conn.Connect(); await library.PlaySongAsync(0, token); await conn.Timeout(TimeSpan.FromSeconds(5)); } }
public async Task CallsAudioPlayerPause() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Song song = Helpers.SetupSongMock(); library.AddSongToPlaylist(song); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); await library.PlaySongAsync(0, token); await library.PauseSongAsync(token); } audioPlayerCallback.Received(1).PauseAsync(); }
public async Task SetsSongIsCorruptedToTrueIfPlayIsFailing() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); audioPlayerCallback.PlayAsync().Returns(Observable.Throw<Unit>(new PlaybackException()).ToTask()); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); Song song = Helpers.SetupSongMock(); library.AddSongsToPlaylist(new[] { song }, accessToken); await library.PlaySongAsync(0, accessToken); Assert.True(song.IsCorrupted); } }
public async Task ResetsSongIsCorruptedIfPlayingIsWorking() { var audioPlayerCallback = Substitute.For<IMediaPlayerCallback>(); audioPlayerCallback.LoadAsync(Arg.Any<Uri>()).Returns(Observable.Throw<Unit>(new SongLoadException()).ToTask()); using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayerCallback).Build()) { Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken(); Song song = Helpers.SetupSongMock(); library.AddSongsToPlaylist(new[] { song }, accessToken); await library.PlaySongAsync(0, accessToken); audioPlayerCallback.LoadAsync(Arg.Any<Uri>()).Returns(_ => Task.Delay(0)); await library.PlaySongAsync(0, accessToken); Assert.False(song.IsCorrupted); } }
public async Task SetsCurrentSongIndexIfChangingToOtherPlaylistAndPlayingFirstSong() { using (Library library = new LibraryBuilder().WithPlaylist().Build()) { var coll = library.WhenAnyValue(x => x.CurrentPlaylist.CurrentSongIndex).CreateCollection(); Guid token = library.LocalAccessControl.RegisterLocalAccessToken(); library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, token); await library.PlaySongAsync(0, token); library.AddPlaylist("Playlist 2", token); library.SwitchToPlaylist(library.Playlists.Last(), token); library.AddSongsToPlaylist(new[] { Helpers.SetupSongMock() }, token); await library.PlaySongAsync(0, token); Assert.Equal(new int?[] { null, 0, null, null, 0, null }, coll); } }