LibVLCSharp版本
1 2 3
| <PackageReference Include="LibVLCSharp" version="3.6.6" /> <PackageReference Include="LibVLCSharp.WPF" version="3.6.6" /> <PackageReference Include="VideoLAN.LibVLC.Windows" version="3.0.16" />
|
现象播放RTSP视频流时在VideoView播放正常,但会弹出一个窗体同时播放,窗体名VLC (Direct3D11 output)
代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public partial class MainWindow : Window { private LibVLC m_libVLC; public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; m_libVLC = new LibVLC(); } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { VideoView.MediaPlayer = new LibVLCSharp.Shared.MediaPlayer(m_libVLC); VideoView.MediaPlayer.Play(new Media(m_libVLC, new Uri(uri))); } }
|
故障原因
打断点调试发现,Loaded时间执行两次,第一次执行在VideoView播放正常,第二次执行弹出VLC (Direct3D11 output)
窗
解决方法: 控制只初始化和播放一次
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public partial class MainWindow : Window { private LibVLC m_libVLC; public MainWindow() { InitializeComponent(); this.Loaded += MainWindow_Loaded; m_libVLC = new LibVLC(); } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { VideoView.MediaPlayer ??= new LibVLCSharp.Shared.MediaPlayer(m_libVLC) { Media = new Media(m_libVLC, new Uri(uri)) }; if (!VideoView.MediaPlayer.IsPlaying) VideoView.MediaPlayer.Play(); } }
|