Open mknotzer opened 3 years ago
The only thing that can be null in this function is the Uri itself https://github.com/xamarin/XamarinCommunityToolkit/blob/main/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/MediaElement/Android/FormsVideoView.android.cs#L59-L78
the source is not set in the XAML, so why would MediaElement call GetMediaData?
<toolkit:MediaElement x:Name="xVideo" AutoPlay="false" BackgroundColor="Black" HeightRequest="300" HorizontalOptions="Center" ShowsPlaybackControls="False" WidthRequest="500" />
It's probably this https://github.com/xamarin/XamarinCommunityToolkit/blob/0db93526c5c973044c282aa6d14657fcc13e48ea/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/MediaElement/Android/MediaElementRenderer.android.cs#L345 Bind Source to a dummy value before switching it to the real value and see if that fixes the issue.
issue still exists on Android.
<toolkit:MediaElement x:Name="xVideo" AutoPlay="false" BackgroundColor="Black" HeightRequest="300" HorizontalOptions="Center" ShowsPlaybackControls="False" Source="{Binding Source, Source={x:Reference xThis}}" WidthRequest="500" />
Later use of
Source = new Uri(...)
not successful either (iOS and Android), have to use
xVideo.Source = new Uri(...)
instead.
@mknotzer Could you attach a small repro?
On Startup MediaElement (Source not set) causes an unhandled Exception:
{System.NullReferenceException: Object reference not set to an instance of an object. at Xamarin.CommunityToolkit.UI.Views.FormsVideoView+<>c__DisplayClass7_0.b__0 () [0x00006] in <08abc6c084af4622851290c7f2f974ff>:0 at System.Threading.Tasks.…}
at Xamarin.CommunityToolkit.UI.Views.FormsVideoView+<>c__DisplayClass7_0.b__0 () [0x00006] in <08abc6c084af4622851290c7f2f974ff>:0
at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2476
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
Xamarin Toolkit 1.0.3
The view works later despite the exception, playing a video is possible.