[Android] Cannot play video when navigating away and back from the video page
See original GitHub issueTo reproduce the bug:
- On the video page, play some video
- Navigate to a new page
- Navigate back to the video page
- Video will not play from this point onward
Reason: On step (1), video plays no problem because isPlayerReady is false and hence “Init()” is excuted
public async Task Play(IMediaFile mediaFile = null)
{
if (VideoViewCanvas == null)
throw new System.Exception("No canvas set for video to play in");
if (isPlayerReady == false)
{
//await Task.Delay(100);
Init();
isPlayerReady = true;
}
...
}
On step (2), navigating away from the video page will trigger the dispose of VideoViewCanvas
On step (4), new VideoViewCanvas is created but “Init()” is not excuted because isPlayerReady is already set to true from the previous play in step 1. Without Init, OnPrepared event handler is not attached to the new VideoViewCanvas and in turn no video renedering because VideoViewCanvas.Start() will not be excuted.
public void OnPrepared(MediaPlayer mp)
{
if(Status == MediaPlayerStatus.Buffering)
VideoViewCanvas.Start();
Status = MediaPlayerStatus.Playing;
}
Walk-around: Add 2 more steps below: 5. Call the Pause method to set the Status = MediaPlayerStatus.Paused 6. Call the Play method again. With Status == MediaPlayerStatus.Paused, VideoViewCanvas.Start() will be excuted
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (4 by maintainers)
Top GitHub Comments
@Apfelcheck I am using MediaManager in ContentView no problem.
Maybe your code has a different problem than the walk around’s.
Fixed in #240