public void play(string audioType, string fileName)
 {
     //播放 mp3 音乐文件的内置支持
     if (audioType.Equals("mp3", StringComparison.OrdinalIgnoreCase))
     {
         Console.WriteLine("Playing mp3 file. Name: " + fileName);
     }
     //mediaAdapter 提供了播放其他文件格式的支持
     else if (audioType.Equals("vlc", StringComparison.OrdinalIgnoreCase) ||
              audioType.Equals("mp4", StringComparison.OrdinalIgnoreCase))
     {
         mediaAdapter = new MediaAdapter(audioType);
         mediaAdapter.play(audioType, fileName);
     }
     else
     {
         Console.WriteLine("Invalid media. " +
                           audioType + " format not supported");
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            AudioPlayer audioPlayer = new AudioPlayer();

            audioPlayer.Play("mp3", "beyond the horizon.mp3");

            Mp4Player mp4Player = new Mp4Player();

            mp4Player.PlayMp4("alone.mp4");

            VlcPlayer vlcPlayer = new VlcPlayer();

            vlcPlayer.PlayVlc("far far away.vlc");

            Console.WriteLine("\nAdapter: IAudioPlayer play media vlc");
            IAudioPlayer mediaAdapter = new MediaAdapter(vlcPlayer);

            mediaAdapter.Play("vlc", "far far away.vlc");

            Console.ReadLine();
        }