Example #1
0
        public async Task CanPlayAWholeBunchOfSongs()
        {
            var song = new LocalSong("C://", TimeSpan.Zero);

            using (Library library = new LibraryBuilder().WithPlaylist().Build())
            {
                var awaiter = library.PlaybackState.Where(x => x == AudioPlayerState.Playing)
                    .Select((x, i) => i + 1)
                    .FirstAsync(x => x == 10)
                    .PublishLast();
                awaiter.Connect();

                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                await library.PlayInstantlyAsync(Enumerable.Repeat(song, 10).ToList(), token);

                await awaiter.Timeout(TimeSpan.FromSeconds(5));
            }
        }
Example #2
0
            public async Task DoesNotSaveTemporaryPlaylist()
            {
                var libraryWriter = Substitute.For<ILibraryWriter>();

                using (Library library = new LibraryBuilder().WithWriter(libraryWriter).Build())
                {
                    Guid token = library.LocalAccessControl.RegisterLocalAccessToken();

                    library.AddAndSwitchToPlaylist("Playlist", token);

                    await library.PlayInstantlyAsync(Helpers.SetupSongMocks(1), token);

                    library.Save();
                }

                libraryWriter.Received(1).Write(Arg.Any<IEnumerable<LocalSong>>(), Arg.Is<IEnumerable<Playlist>>(x => x.Count() == 1), Arg.Any<string>());
            }
Example #3
0
            public async Task SmokeTest()
            {
                var audioPlayer = Substitute.For<IMediaPlayerCallback>();

                using (Library library = new LibraryBuilder().WithAudioPlayer(audioPlayer).Build())
                {
                    Song song = Helpers.SetupSongMock();

                    await library.PlayInstantlyAsync(new[] { song }, library.LocalAccessControl.RegisterLocalAccessToken());
                }

                audioPlayer.Received(1).PlayAsync();
            }
Example #4
0
            public async Task JumpsOverCorruptedSong()
            {
                using (var handle = new CountdownEvent(2))
                {
                    var audioPlayer = Substitute.For<IMediaPlayerCallback>();
                    audioPlayer.PlayAsync().Returns(_ => Task.Run(() =>
                    {
                        switch (handle.CurrentCount)
                        {
                            case 2:
                                handle.Signal();
                                throw new SongLoadException();
                            case 1:
                                handle.Signal();
                                break;
                        }
                    }));

                    using (Library library = new LibraryBuilder().WithPlaylist().WithAudioPlayer(audioPlayer).Build())
                    {
                        Song[] songs = Helpers.SetupSongMocks(2);

                        await library.PlayInstantlyAsync(songs, library.LocalAccessControl.RegisterLocalAccessToken());

                        if (!handle.Wait(5000))
                        {
                            Assert.False(true, "Timeout");
                        }
                    }
                }
            }
Example #5
0
            public async Task PropagatesToMediaPlayer()
            {
                var audioPlayer = Substitute.For<IMediaPlayerCallback>();

                using (Library library = new LibraryBuilder().WithAudioPlayer(audioPlayer).WithPlaylist().Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    await library.PlayInstantlyAsync(Helpers.SetupSongMocks(1), accessToken);

                    library.SetVolume(0.5f, accessToken);
                }

                audioPlayer.Received().SetVolume(0.5f);
            }
Example #6
0
            public async Task PropagatesToMediaPlayer()
            {
                var audioPlayer = Substitute.For<IMediaPlayerCallback>();
                var timeSpan = TimeSpan.FromMinutes(1);

                using (Library library = new LibraryBuilder().WithAudioPlayer(audioPlayer).WithPlaylist().Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    await library.PlayInstantlyAsync(Helpers.SetupSongMocks(1), accessToken);

                    library.SetCurrentTime(timeSpan, accessToken);
                }

                Assert.Equal(timeSpan, audioPlayer.CurrentTime);
            }