'Xamarin MediaElement: Disable standard popup on MediaFailed
For some reason I have sometimes problems with the video files I want to play with the MediaElement video player. This is, why I created a MediaFailed method:
public void OnMediaFailed(object sender, EventArgs e)
{
try
{
DisplayAlert("Error", "My Error Message", "Close");
Shell.Current.GoToAsync("..");
}
catch(Exception ex)
{
}
}
<xct:MediaElement
x:Name="Videoelement"
ShowsPlaybackControls="True"
Aspect="AspectFit"
MediaFailed="OnMediaFailed"
/>
This works fine. However there is a standard error popup message "Can't play this video". This standard popup always pops up on top of my costum popup. Is there a way to disable the standard popup?
Here is a Screenshot of the standard popup message: Link
Solution 1:[1]
Try to add the SetOnErrorListener in your VideoPlayerRenderer and override the OnError method,let it return true,
just as folows:
class VideoPlayerRenderer : ViewRenderer<VideoPlayer, Android.Widget.RelativeLayout>,MediaPlayer.IOnErrorListener
{
protected override void OnElementChanged(ElementChangedEventArgs<VideoPlayer> e)
{
....
videoView.SetOnErrorListener(this);
}
public bool OnError(MediaPlayer mp, [GeneratedEnum] MediaError what, int extra)
{
return true;
}
}
Refer: Hide "Can't play this video." Alert for Xamarin Android VideoView Player .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jessie Zhang -MSFT |
