none
我使用 WPF 里的 MediaPlayer 类 重复播放一段 WMV 视频 ,长时间播放会发生 Mediaplayer 黑屏的现象,并且不会有播放错误和播放完成事件的产生,这是为什么? RRS feed

  • 问题

  • 代码如下:
    private void Initialize(string videopath)
    {
                   MediaPlayer player = new MediaPlayer();
                    player.MediaFailed += new EventHandler<ExceptionEventArgs>(Media_MediaFailed);
                    player.MediaOpened += new EventHandler(Media_Opened);
                    player.MediaEnded += new EventHandler(Media_PlayEnded);
                    player.Open(new Uri(videopath));
                    VideoDrawing videodrawing = new VideoDrawing();
                    videodrawing .Rect = new Rect(0, 0, 640, 480);
                    aVideoDrawing.Player = player;
    }

     private void Media_Opened(object sender, EventArgs e)
     {
                MediaPlayer player = sender as MediaPlayer;
                if (player.Source == null)
                    return;
                player.Play();       
     }

     private void Media_PlayEnded(object sender, EventArgs e)
     {
                MediaPlayer player = sender as MediaPlayer;
               srting videopath = player.Source.OriginalString;
                Initialize(videopath);     
     }

    private  void Media_MediaFailed(object sender, ExceptionEventArgs e)
    {  
                 Console.WriteLine("Error ocored:" + e.Message);
    }
    • 已编辑 浅尝WPF 2010年1月6日 8:31
    • 已移动 KeFang Chen 2010年1月7日 2:11 wpf category (发件人:Visual C#)
    2010年1月6日 4:04

全部回复