0

I'm trying to use VideoView from LibVLCSharp for Mac to create a custom renderer in Xamarin.Forms to play a video in Xamarin.Forms mac application. So far I only get audio but no video.

this is my VideoPlayerRenderer for mac implementation

[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);
                    
                }
            }
        }
    }
}

and the VideoPlayer Xamarin.Forms View

   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;
        }
    }

I've tried the same method on UWP and there i get no audio nor video. So i'm wondering if this is going in the wrong direction, and if so, how are you supposed to go about using LibVLCSharp for mac/uwp?

1 Answers1

0

You don't have to create your own renderer since there is already one.

From the LibVLCSharp.Forms documentation :

This package also contains the views for the following platforms:

  • Android
  • iOS
  • Mac

The UWP support for Xamarin.Forms currently has blockers that we expect to get solved by the LVS 4/ libvlc 4 release. See this issue for a detailed explanation.

cube45
  • 3,429
  • 2
  • 24
  • 35
  • sample here: https://code.videolan.org/videolan/LibVLCSharp/-/tree/3.x/samples/Forms/LibVLCSharp.Forms.Sample.Mac – mfkl Jan 25 '21 at 03:49