我正在尝试使用 LibVLCSharp for Mac 中的 VideoView 在 Xamarin.Forms 中创建自定义渲染器,以在 Xamarin.Forms mac 应用程序中播放视频。到目前为止,我只得到音频但没有视频。
这是我用于 mac 实现的 VideoPlayerRenderer
[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?