Search code examples
xamarinxamarin.formsvlclibvlclibvlcsharp

Why is MediaPlayerElement not playing video when hosted in a ContentView?


I have a working example of my issue here. Basically: when I place the LibVLCSharp MediaPlayerElement into MainPage.xaml directly, I'm able to get playback. When I try to create a reusable control by hosting the MediaPlayerElement in a ContentView that I can use in several parts of my application, all I get is a black screen. The only difference appears to be hosting it inside a ContentView.

Ultimately, my goal is to create a single, reusable class that I can use in several parts of my Xamarin application to render video without copying and pasting code. I've found that it's most stable to set the properties I want to set (clearing the Play/Stop, etc. controls) in XAML. So I've gravitated to implementing my reusable component as a ContentView and just referencing it in multiple places.

Does anyone have any idea on why I get a black screen in this example?


Solution

  • See this line: https://github.com/kwende/LibVLCSharpContentView/blob/65fd9c2bf1afc97374a9052c86b9c066934f7b7d/LibVLCSharpContentView/LibVLCSharpContentView/VideoPlayer.xaml.cs#L28

    Your MediaPlayer is not a Bindable property/does not raise PropertyChanged, so the VideoView is initialized with a null media player when it loads, and the never changed, even after the start.