Example #1
0
        static void Run()
        {
            using (PlayerBase <AudioItem> player = new Player())
            {
                player.LockStateChanged += (sender, e) =>
                {
                    PlayerView.UpdateScreen(player);
                    Console.WriteLine($"Lock state changed event : {e.IsLocked}");
                };
                player.VolumeChanged += (sender, e) =>
                {
                    PlayerView.UpdateScreen(player);
                    Console.WriteLine($"Volume changed event : {e.Volume}");
                };
                player.CollectionChanged += (sender, e) =>
                {
                    PlayerView.UpdateScreen(player);
                    Console.WriteLine($"Colection changed event");
                };
                player.PlayerPlayingStateChanged += (sender, e) =>
                {
                    PlayerView.UpdateScreen(player);
                    Console.WriteLine($"Started/Stopped event : {e.IsPlaying}");
                };
                player.PlaingItemStarted += (sender, e) =>
                {
                    PlayerView.UpdateScreen(player);
                    Console.WriteLine($"Started song event : {e.ItemTitle} {e.ItemDuration} {e.ItemDurationMinSec}");
                };

                player.Load(Environment.CurrentDirectory);
                Console.WriteLine("set song");
                player.SetPlayingItem();

                //Console.WriteLine("play");
                //player.Play();
                //Console.ReadLine();
                //Console.WriteLine("set volume");
                //player.Volume = 50;
                //Console.ReadLine();
                //Console.WriteLine("play");
                //player.Play();
                //Console.ReadLine();
                //Console.WriteLine("lock");
                //player.LockUnLock = true;
                //Console.ReadLine();
                //Console.WriteLine("play");
                //player.Play();
                //Console.ReadLine();
                //Console.WriteLine("unlock");
                //player.LockUnLock = false;
                //Console.ReadLine();


                while (true)
                {
                    player.LabelOutput("Next action:");
                    //Console.WriteLine("Next action :");
                    string cmd = Console.ReadLine();
                    switch (cmd)
                    {
                    case "set volume":
                        player.Volume = player.Volume;
                        break;

                    case "play":
                        player.Play();
                        //player.Playing = true; //error. Property or indexer 'Player.Plaing' cannot be assigned to -- it is read only
                        break;

                    case "stop":
                        player.Stop();
                        break;

                    case "lock":
                        player.LockUnLock = true;
                        break;

                    case "unlock":
                        player.LockUnLock = false;
                        break;

                    case "set song":
                        player.SetPlayingItem();
                        break;

                    case "pause":
                        player.Pause();
                        break;

                    case "show":
                        //player.ShowPlaylist();
                        break;

                    case "sort":
                        player.SortPlayList_ByTitle();
                        break;

                    case "genre filter":
                        //Console.WriteLine("Input Genre you want..");
                        //player.SongListGenreSort(Console.ReadLine().Trim().ToUpper());
                        (player as Player).Filter_ByGenre();
                        break;

                    case "shuffle":
                        player.ShufflePlayList();
                        break;

                    case "quit":
                        //player.ClosePlayer();
                        //player.Dispose();

                        //Environment.Exit(0);
                        return;

                    //break;

                    case "set like":
                        player.SetLike();
                        break;

                    case "set skin":
                        player.SetSkin();
                        break;

                    case "load":
                        Console.WriteLine("Enter path:");
                        player.Load(Console.ReadLine());
                        break;

                    case "clear":
                        player.Clear();
                        break;

                    case "save playlist":
                        Console.WriteLine("Enter playlist name:");
                        player.SavePlaylist(Console.ReadLine());
                        break;

                    case "load playlist":
                        Console.WriteLine("Enter path:");
                        player.LoadPlaylist(Console.ReadLine());
                        break;

                    default:
                        player.LabelOutput("Unknown command...");

                        break;
                    }
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            Skin skin   = new RandomSkin();
            var  player = new Player(skin);

            player.Load();
            player.Play(Player.Songs, false);
            player.SaveAsPlaylist();
            player.LoadPlayList();

            Console.ReadLine();

            //    int min, max, total = 0;
            //
            //    List<Song> songs = new List<Song>();

            //    int i;
            //    for (i = 0; i < 8; i++)
            //    {
            //        var song = CreateSong("song " + (i + 1));
            //        songs.Add(song);
            //    }

            //    player.Add(songs);
            //    Sort.SortByTitle(songs);
            //    Shuffle.Shuffling(songs);
            //}

            //private static Song[] CreateSongs( out int min, out int max, ref int total)
            //{
            //    Random rand = new Random();
            //    Song[] songs = new Song[5];
            //    int MinDuration=0, MaxDuration=0, TotalDuration=0;
            //    for (int i = 0; i < songs.Length; i++)
            //    {
            //        var song1 = new Song();
            //        song1.Title = "Song" + i;
            //        song1.Duration = rand.Next(3000);
            //        song1.Artist = new Artist("Nensi");
            //        songs[i] = song1;
            //        TotalDuration = TotalDuration + song1.Duration;
            //        if (MaxDuration < song1.Duration)
            //        {
            //            MaxDuration = song1.Duration;
            //        }
            //        if (MinDuration>song1.Duration)
            //        {
            //            MinDuration = song1.Duration;
            //        }
            //    }
            //    min = MinDuration;
            //    max = MaxDuration;
            //    total = TotalDuration;
            //    return songs;

            //}
            //public static Song CreateSong()
            //{
            //    var song2 = new Song();
            //    song2.Duration = 500;
            //    song2.Title = "Title of song2";
            //    song2.Path = "Path of song2";
            //    song2.Lyrics = "Lyrics of song2";
            //    song2.Genre = (Song.Genres) 1;
            //    return song2;
            //}
            //public static Song CreateSong(string nameOfSong3)
            //{
            //    var song3 = new Song();
            //    song3.Duration = 1000;
            //    song3.Title = nameOfSong3;
            //    song3.Path = "Path of song3";
            //    song3.Lyrics = "Lyrics of song3";
            //    song3.Genre = (Song.Genres)2;
            //    return song3;
            //}
            //public static Song CreateSong(int durationOfSong4, string nameOfSong4, string titleOfSong4, string pathOfSong4, string lyricsOfSong4, string genreOfSong4)
            //{
            //    var song4 = new Song();
            //    song4.Duration = durationOfSong4;
            //    song4.Title = nameOfSong4;
            //    song4.Path = pathOfSong4;
            //    song4.Lyrics = lyricsOfSong4;
            //    song4.Genre = (Song.Genres)3;
            //    return song4;
            //}
            //refactoring
            // public static Song CreateSong()
            //{
            //var song2 = new Song();
            //CreateSong();
            //return song2;
            //}
            //public static Artist AddArtist(string name = "Unknown Artist")
            //{
            //    var artist = new Artist("Unknown Artist");
            //    artist.Name = name;
            //    WriteLine(artist.Name);
            //    return artist;
            //}
            //public static Album AddAlbum(int year = 0, string name = "Unknown Album")
            //{
            //    var album = new Album("Unknown Album", "Unknown year");
            //    album.Name = name;
            //    album.Year = year;
            //    WriteLine($"Name of album:{album.Name}, Year of album: {album.Year}");
            //    return album;
            //
        }
Example #3
0
        static void Main(string[] args)
        {
            int    min, max, total = 0;
            Player player = new Player(new ClassicSkin());
            Random rand   = new Random();

            Console.WriteLine($"{0}");
            //var songs = CreateSongs(out min, out max, ref total);


            List <Song> songs = new List <Song>();

            for (int i = 0; i < 8; i++)
            {
                var song = CreateSong($"song {i}", Convert.ToBoolean(rand.Next(2)));
                songs.Add(song);
            }
            player.Add(songs);

            List <Song> songsGenre = new List <Song>();

            for (int i = 0; i < 8; i++)
            {
                var songG = CreateSongGenre($"song {i}", rand.Next(4));

                songsGenre.Add(songG);
            }
            player.Add(songsGenre);

            while (true)
            {
                switch (ReadLine())
                {
                case "up":
                {
                    player.VolumeUp();
                }
                break;

                case "down":
                {
                    player.VolumeDown();
                }
                break;

                case "p":
                {
                    player.Play(true);
                }
                break;

                case "l":
                {
                    player.Lock();
                }
                break;

                case "ul":
                {
                    player.Unlock();
                }
                break;

                case "s":
                {
                    player.Stop();
                }
                break;

                case "start":
                {
                    player.Start();
                }
                break;

                case "shuf":
                {
                    player.Shuffle(songs);
                }
                break;

                case "sort":
                {
                    player.SortByTitle(songs);
                }
                break;

                case "GS":
                {
                    player.FilterByGenre(songsGenre, Song.Genres.Pop);
                }
                break;

                case "CHS":
                {
                    player.ChangeSkin();
                }
                break;
                }
            }
            //player.Playing=true;
            Console.ReadLine();
        }
Example #4
0
 static void Main(string[] args)
 {
     Player p = new Player();
     p.Play(".\\AudioTest.xml");
     Console.ReadLine();
 }
Example #5
0
 private void PlayClicked(object sender, RoutedEventArgs e)
 {
     _player.Play();
 }
Example #6
0
        private static void ManagePlayer(Player player)
        {
            while (true)
            {
                DisplayInfo();
                var cmd = GetCommand();
                switch (cmd)
                {
                    case "l":
                    case "load":
                        Console.WriteLine("Enter path to the playlist:");
                        var path = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(path))
                        {
                            Console.WriteLine("Invalid playlist path.");
                            continue;
                        }
                        try
                        {
                            var pl = DataContractFormatter<Playlist>.Load(path);
                            //todo: обработать исключения
                            player.LoadPlayList(pl);
                            Console.WriteLine("Playlist was loaded.");
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Playlist loading error!");
                        }
                        break;

                    case "pl":
                    case "play":
                        player.Play();
                        break;

                    case "pa":
                    case "pause":
                        player.Pause();
                        break;

                    case "s":
                    case "stop":
                        player.Stop();
                        break;

                    case "i":
                    case "info":
                        DisplayInfo();
                        break;

                    case "se":
                    case "select":
                        return;

                    case "e":
                    case "exit":
                        Environment.Exit(0);
                        return;
                    default:
                        Console.WriteLine("Incorrect command.");
                        continue;
                }
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            int min, max, total = 0;
            var player = new Player();
            var songs  = CreateSongs(out min, out max, ref total);

            player.Songs = songs;
            Console.WriteLine($"TotalDuration: {total}, max duration: {max}, min duration: {min}");

            while (true)
            {
                switch (ReadLine())
                {
                case "Up":
                {
                    player.VolumeUp();
                }
                break;

                case "Down":
                {
                    player.VolumeDown();
                }
                break;

                case "P":
                {
                    player.Play();
                }
                break;

                case "step1":
                {
                    player.VolumeChange1();
                }
                break;

                case "step2":
                {
                    player.VolumeChange2();
                }
                break;

                case "Lock":
                {
                    player.Lock();
                }
                break;

                case "Unlock":
                {
                    player.Unlock();
                }
                break;

                case "Stop":
                {
                    player.Stop();
                }
                break;

                case "Start":
                {
                    player.Start();
                }
                break;

                case "CreateDS":
                {
                    CreateDefaultSong();
                }
                break;
                }
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            var defaultSkin = new ColorSkin();

            using (var player = new Player(defaultSkin))
            {
                player.PlayerStartedEvent += (bool isPlaying) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.PlayerStoppedEvent += (bool isPlaying) =>
                {
                    List <Song> clearList = new List <Song>();
                    Visualise(player, clearList);
                };

                player.PlayerLockedEvent += (bool isLocked) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.PlayerUnlockedEvent += (bool isLocked) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.VolumeChangedEvent += (float inputAmount) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.SongStartedEvent += (Song song) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.SongStoppedEvent += (Song song) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                player.PlaybackAbortedEvent += (bool isAborted) =>
                {
                    Visualise(player, player.PlayingPlaylist);
                };

                while (true)
                {
                    switch (ReadLine())
                    {
                    case "u":
                    {
                        player.VolumeUp();
                    }
                    break;

                    case "d":
                    {
                        player.VolumeDown();
                    }
                    break;

                    case "Loop":
                    {
                        if (player.IsPlaying == false)
                        {
                            player.Start();
                        }
                        player.Play(true);
                    }
                    break;

                    case "-Loop":
                    {
                        player.IsOnLoop = false;
                    }
                    break;

                    case "P":
                    {
                        if (player.IsPlaying == false)
                        {
                            player.Start();
                        }
                        player.Play();
                    }
                    break;

                    case "V":
                    {
                        player.currentSkin.Render("Specify volume: ");
                        float inputAmount = Convert.ToSingle(Console.ReadLine().Replace('.', ','));
                        player.VolumeChange(inputAmount);
                    }
                    break;

                    case "Start":
                    {
                        player.Start();
                    }
                    break;

                    case "s":
                    {
                        player.Stop(player.currentPlaybackDevice);
                    }
                    break;

                    case "a":
                    {
                        player.Abort();
                    }
                    break;

                    case "Lock":
                    {
                        player.Lock();
                    }
                    break;

                    case "Unlock":
                    {
                        player.Unlock();
                    }
                    break;

                    case "Load":
                    {
                        player.currentSkin.Render("Please enter the path to desired directory");
                        string path = Console.ReadLine();
                        player.Load(path);
                    }
                    break;

                    case "Clear":
                    {
                        player.playlist.Songs.ClearAll();
                    }
                    break;

                    case "Shuffle":
                    {
                        player.playlist.Songs = player.Shuffle();
                    }
                    break;

                    case "SortT":
                    {
                        player.playlist.Songs = player.SortByTitle();
                    }
                    break;

                    case "+":
                    {
                        var input = Console.ReadLine();

                        for (int i = 0; i < player.playlist.Songs.Count; i++)
                        {
                            if (player.playlist.Songs[i].Title == input)
                            {
                                player.playlist.Songs[i].Like();
                            }
                        }
                    }
                    break;

                    case "-":
                    {
                        player.currentSkin.Render("Please specify the the title of a song in current playlist that you wish to like");
                        var input = Console.ReadLine();

                        for (int i = 0; i < player.playlist.Songs.Count; i++)
                        {
                            if (player.playlist.Songs[i].Title == input)
                            {
                                player.playlist.Songs[i].Dislike();
                            }
                        }
                    }
                    break;

                    case "SortG":
                    {
                        player.currentSkin.Render("Please specify genre");
                        string   input    = Console.ReadLine();
                        int      inputInt = 0;
                        string[] Genre    = { "PsyTrance", "Electronic", "Hardcore", "DnB", "Drumstep" };

                        for (int i = 0; i < 5; i++)
                        {
                            if (input == Genre[i])
                            {
                                inputInt = i;
                            }
                        }

                        player.playlist.Songs = player.FilterByGenre(inputInt);
                    }
                    break;

                    case "s 0":
                    {
                        var tempSkin = new ColorSkin();
                        player.currentSkin = tempSkin;
                        player.currentSkin.NewScreen();
                    }
                    break;

                    case "s 1":
                    {
                        var tempSkin = new ColorSkin(ConsoleColor.Blue);
                        player.currentSkin = tempSkin;
                        player.currentSkin.NewScreen();
                    }
                    break;

                    case "SaveP":
                    {
                        player.SaveCurrentPlaylist();
                    }
                    break;

                    case "LoadP":
                    {
                        player.LoadPlaylist();
                    }
                    break;

                    case "Exit":
                    {
                        player.Dispose();
                    }
                    break;
                    }
                }
            }
        }