【问题标题】:Embedding LIb.VLC in winform Application在winform应用程序中嵌入LIb.VLC
【发布时间】:2021-10-18 13:52:27
【问题描述】:

这个问题参考了我之前的问题Embedding VLC player in WInform Application in .Net Core. Core.Intialize() Giving Exception

我想运行播放器一段时间,在此期间视频应该重复播放。目前的代码看起来像这样......

Core.Initialize();
            var libvlc = new LibVLC();
            // Make VideoView control
            VideoView vv = new VideoView();
            vv.MediaPlayer = new MediaPlayer(libvlc);
            vv.Dock = DockStyle.Fill;
            // Add it to the form
            Controls.Add(vv);

            var uri = new Uri(@"C:\vid.3gp");
            // Use command line options as Options for media playback (https://wiki.videolan.org/VLC_command-line_help/)
            var media = new Media(libvlc, uri, ":input-repeat=65535");
            vv.MediaPlayer.Play(media);

            //Set fullscreen
            this.FormBorderStyle = FormBorderStyle.None;
            this.Size = Screen.PrimaryScreen.Bounds.Size;
            this.Location = Screen.PrimaryScreen.Bounds.Location;

如何在特定时间后关闭播放器。目前,即使我关闭带有播放器视频的表单,也会在后台继续播放,直到我关闭整个应用程序。

只是为了通知这个winform应用程序是在.netcore3.1中创建的。

问候。

【问题讨论】:

    标签: c# .net libvlc


    【解决方案1】:

    将 MediaPlayer 创建为类字段并调用它以在您的 WinForm 应用程序中启动/暂停/停止它。

    private LibVLC _libVlc;
    private MediaPlayer _mediaPlayer;
    ...
    
    // Call this method in your constructor/initializer
    private void StartMediaPlayer(string videoUrl)
    {
        using var media = new Media(_libVlc, new Uri(videoUrl), ":input-repeat=65535");
        _mediaPlayer = new MediaPlayer(_libVlc)
        {
            Media = media
        };
    
        _mediaPlayer.Play();
    }
    
    // Method to stop media player
    private void button1_Click(object sender, EventArgs e)
    {
        _mediaPlayer.Stop();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多