Mac 和 UWP 中 LibVLCSharp VideoView 的自定义渲染器 (Xamarin.Forms)

问题描述

我正在尝试使用 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 用于 mac/uwp?

解决方法

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

来自LibVLCSharp.Forms documentation

这个包还包含以下平台的视图:

  • 安卓
  • iOS
  • 苹果

UWP 对 Xamarin.Forms 的支持目前具有我们希望通过 LVS 4/libvlc 4 版本解决的阻止程序。有关详细说明,请参阅 this issue