【问题标题】:Custom renderer for LibVLCSharp VideoView in Mac and UWP (Xamarin.Forms)Mac 和 UWP 中 LibVLCSharp VideoView 的自定义渲染器 (Xamarin.Forms)
【发布时间】:2021-04-28 14:15:50
【问题描述】:

我正在尝试使用 LibVLCSharp for Mac 中的 VideoView 在 Xamarin.Forms 中创建自定义渲染器,以在 Xamarin.Forms mac 应用程序中播放视频。到目前为止,我只得到音频,没有视频。

这是我的 VideoPlayerRenderer for mac 实现

[assembly: ExportRenderer(typeof(Player.VideoPlayer), typeof(Player.Mac.VideoPlayerRenderer))]
namespace Player.Mac {
    public class VideoPlayerRenderer : ViewRenderer<VideoPlayer, LibVLCSharp.Platforms.Mac.VideoView> {

        LibVLCSharp.Platforms.Mac.VideoView video_view;

        public VideoPlayerRenderer() {

        }

        protected override void OnElementChanged (ElementChangedEventArgs<VideoPlayer> e) {
            base.OnElementChanged (e);

            if(e.OldElement != null) {
            }
            if(e.NewElement != null) {
                if(Control == null) {
                    video_view = new  LibVLCSharp.Platforms.Mac.VideoView();
                    
                    video_view.MediaPlayer = e.NewElement.get_media_player();
                    
                    SetNativeControl(video_view);
                    
                }
            }
        }
    }
}

和 VideoPlayer Xamarin.Forms 视图

   public class VideoPlayer : View {
        LibVLC lib_vlc;
        MediaPlayer media_player;

        public VideoPlayer() {
        }

        public void init(LibVLC lib_vlc, MediaPlayer media_player) {
            this.lib_vlc = lib_vlc;
            this.media_player = media_player;
        }

        public void play() {
            this.media_player.Play();
        }

        public MediaPlayer get_media_player() {
            return this.media_player;
        }
    }

我在 UWP 上尝试了相同的方法,但我没有收到音频或视频。所以我想知道这是否朝着错误的方向发展,如果是这样,你应该如何使用 LibVLCSharp for mac/uwp?

【问题讨论】:

    标签: macos xamarin.forms uwp libvlcsharp


    【解决方案1】:

    您不必创建自己的渲染器,因为已经有一个。

    来自LibVLCSharp.Forms documentation

    此包还包含以下平台的视图:

    • 安卓
    • iOS
    • 苹果机

    UWP 对 Xamarin.Forms 的支持目前有一些阻碍,我们希望 LVS 4/libvlc 4 版本能够解决这些阻碍。详细解释见this issue

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 2014-08-29
    • 2017-01-07
    • 2016-05-31
    • 2018-10-22
    • 1970-01-01
    • 2014-08-13
    相关资源
    最近更新 更多