Exemplo n.º 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;
                    }
                }
            }
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }