Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

macos - Custom renderer for LibVLCSharp VideoView in Mac and UWP (Xamarin.Forms)

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?

question from:https://stackoverflow.com/questions/65873518/custom-renderer-for-libvlcsharp-videoview-in-mac-and-uwp-xamarin-forms

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...