Пример #1
0
        public void PlayerCanBeGivenANewPlaylist()
        {
            var library = new MemoryLibraryRepository();
            var playlist = new Playlist();
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo() { FullPath = song } });

            playlist.AddRange(library.GetAllMusic());

            player.Play();

            Assert.AreEqual(song, playlist.CurrentSong.FullPath, "The last song played must be the only one in the library.");

            var song2 = "song 2";

            library.ClearLibrary();
            library.AddMusicToLibrary(new MusicInfo[] { new MusicInfo() { FullPath = song2 } });

            playlist.AddRange(library.GetAllMusic());

            player.PlayCount = 0;
            player.Play();

            Assert.AreEqual(song, playlist.PreviousSong.FullPath, "The previous played must be new song in the library.");
            Assert.AreEqual(song2, playlist.CurrentSong.FullPath, "The current played must be new song in the library.");
        }
        public void Test()
        {
            var song1 = "song1";
            var song2 = "song2";
            var song3 = "song3";
            var song4 = "song4";

            _songs = new MusicInfo[] {
                    new MusicInfo() { FullPath = song1 },
                    new MusicInfo() { FullPath = song2 },
                    new MusicInfo() { FullPath = song3 },
                    new MusicInfo() { FullPath = song4 }
                };

            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            library.AddMusicToLibrary(_songs);

            var loopingWatcher = new RandomSongPlaylistWatcher(2);
            _playlist = new Playlist(loopingWatcher);
            _dummyAudio = new DummyAudioInteractor();

            var player = new Player(_playlist, _dummyAudio, library);

            loopingWatcher.AttachToPlaylist(_playlist, library);

            player.MaxPlayCount = 3;
            player.Play();
        }
Пример #3
0
        public void Loop()
        {
            var song1 = "song1";
            var song2 = "song2";

            var library = new MemoryLibraryRepository();
            library.ClearLibrary();
            library.AddMusicToLibrary(
                new MusicInfo[] {
                    new MusicInfo() { FullPath = song1 },
                    new MusicInfo() { FullPath = song2 }
                });

            var loopingWatcher = new LoopingPlaylistWatcher();
            var playlist = new Playlist(loopingWatcher);
            var dummyAudio = new DummyAudioInteractor();

            var player = new Player(playlist, dummyAudio, library);

            loopingWatcher.AttachToPlaylist(playlist, library);

            playlist.AddRange(library.GetAllMusic());

            player.MaxPlayCount = 3;
            player.Play();

            Assert.AreEqual(3, dummyAudio.PlayHistory.Count, "There must be three songs in the history.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[0], "The first song must play first.");
            Assert.AreEqual(song2, dummyAudio.PlayHistory[1], "The second song must play second.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[2], "The first song must play third.");

            Assert.AreEqual(2, playlist.RemainingSongs, "After playing three songs there must still be 2 songs in the playlist.");
        }
Пример #4
0
 public Player(Playlist playlist, IAudioInteractor audioInteractor, ILibraryRepository library)
 {
     AudioInteractor = audioInteractor;
     Playlist = playlist;
     _current = this;
     Library = library;
 }
Пример #5
0
        public void PlayerShouldBePausableAndResumeable()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";
            var music = new MusicInfo() { FullPath = song };

            playlist.Enqueue(music);

            player.Play();
            player.Pause();
            player.Resume();

            Assert.IsTrue(dummyAudio.WasPaused, "The audio must have been paused.");
            Assert.IsTrue(dummyAudio.WasResumed, "The audio must have been resumed.");
        }
Пример #6
0
        public void PlayerCanGoBack()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song1 = new MusicInfo() { FullPath = "song1" };
            var song2 = new MusicInfo() { FullPath = "song2" };

            playlist.Enqueue(song1);
            playlist.Enqueue(song2);

            player.MaxPlayCount = 2;
            player.Play();

            Assert.AreEqual(1, playlist.CurrentPosition, "The song must have moved one song ahead.");

            player.Back();

            Assert.AreEqual(0, playlist.CurrentPosition, "The song must have moved one song back.");
        }
Пример #7
0
        public void PlayerShouldBeStoppable()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";
            var music = new MusicInfo() { FullPath = song };

            playlist.Enqueue(music);

            player.Play();
            player.Stop();

            Assert.IsTrue(dummyAudio.WasStopped, "It should stop.");
        }
Пример #8
0
        public void ResumingWhileNotPausedDoesNothing()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";
            var music = new MusicInfo() { FullPath = song };

            playlist.Enqueue(music);

            player.Play();
            player.Resume();

            Assert.IsFalse(dummyAudio.WasResumed, "It should not resume if it wasn't paused.");
        }
Пример #9
0
        public void PlayerShouldStopIfThePlaylistRunsOut()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song = "song1";
            var music = new MusicInfo() { FullPath = song };

            playlist.Enqueue(music);

            player.Play();

            Assert.AreEqual(1, dummyAudio.PlayHistory.Count, "There must be one song that was played.");
            Assert.AreEqual(song, dummyAudio.PlayHistory[0], "The song that was played must be the right one.");
        }
Пример #10
0
        public void PlayerShouldPlayTheNextSongWhenTheSongFinishes()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            var song1 = "song1";
            var song2 = "song2";
            var music1 = new MusicInfo() { FullPath = song1 };
            var music2 = new MusicInfo() { FullPath = song2 };

            playlist.Enqueue(music1);
            playlist.Enqueue(music2);

            player.Play();

            Assert.AreEqual(2, dummyAudio.PlayHistory.Count, "There must be two songs that were played.");
            Assert.AreEqual(song1, dummyAudio.PlayHistory[0], "The first song that was played must be the right one.");
            Assert.AreEqual(song2, dummyAudio.PlayHistory[1], "The second song that was played must be the right one.");
        }
Пример #11
0
        public void PlayerShouldHaveASingletonishInstance()
        {
            var player = new Player(null, null, null);

            Assert.AreEqual(player, Player.Current, "The global Current player must be the same as the one just created.");
        }
Пример #12
0
        public void PlayerShouldDoNothingIfThePlaylistIsEmpty()
        {
            var playlist = new Playlist(new DummyPlaylistWatcher());
            var dummyAudio = new DummyAudioInteractor();
            var player = new Player(playlist, dummyAudio, null);

            player.Play();

            Assert.AreEqual(0, dummyAudio.PlayHistory.Count, "There must be not be any songs played.");
        }
Пример #13
0
        private void StartPlayer()
        {
            try
            {
                var playlistManager = GetPlaylistManager();
                var messagingWatcher = new MessagingPlaylistWatcher();
                var playlist = new Playlist(new IPlaylistWatcher[] { playlistManager, messagingWatcher });
                var dummyAudio = new NAudioInteractor();
                var library = new MongoLibraryRepository(null);
                _folderWatcher = new ImportFolderWatcher(library);

                if (ConfigurationManager.AppSettings["ResetLibraryForTesting"]=="true")
                    InsertTestSongs(library);

                var player = new Player(playlist, dummyAudio, library);
                _pubnub = new PubnubMessaging(player, true);

                messagingWatcher.AssignMessaging(_pubnub);
                messagingWatcher.AttachToPlaylist(playlist, library);
                playlistManager.AttachToPlaylist(playlist, library);

                _pubnub.StartListening();

                library.Messaging = _pubnub;

                _folderWatcher.Start();

                if (ConfigurationManager.AppSettings["AutoStartPlaying"]=="true")
                    player.Play();

                _pubnub.SendNowPlaying(playlist[0]);
            }
            catch (Exception exc)
            {
                Log.Debug(exc.ToString());
            }
        }