question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Cannot play video when navigating away and back from the video page

See original GitHub issue

To reproduce the bug:

  1. On the video page, play some video
  2. Navigate to a new page
  3. Navigate back to the video page
  4. 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:closed
  • Created 6 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aivietcommented, Aug 19, 2017

@Apfelcheck I am using MediaManager in ContentView no problem.

Maybe your code has a different problem than the walk around’s.

0reactions
aivietcommented, Sep 20, 2017

Fixed in #240

Read more comments on GitHub >

github_iconTop Results From Across the Web

Youtube video continues to play after navigating away from ...
When I navigate away from a youtube video to the youtube home page, I hear the audio from that last video begin to...
Read more >
How to Fix Videos Not Playing on Android Phone
Read on to know how to fix videos not playing on Android phone when your mobile videos do not play properly or give...
Read more >
Video Not Playing on Android Phone? Try These Ways to Fix!
In this post we will show you how to fix video not playing on Android device issues. Click here and get the detailed...
Read more >
Troubleshoot video errors, buffering, and freezing - Android
Troubleshoot video errors, buffering, and freezing. Many factors can cause video playback issues, such as internet or device connection. If a video is...
Read more >
This Trick Lets YouTube Play In The Background!
Your browser can't play this video. Learn more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found