Android - dismissing Webview with html5 video - android

I'm using a Webview, playing different html5 videos (internal tag and Youtube videos).
When closing the Webview I tried loading a blank page + hiding the view + pausing the webview. The Webview seems to be closed correctly and the video stops playing.
The problem is on Galaxy S4 + S2, when opening the Webview again and playing another video. The new video is been paused immediately after being played. When I press "play" again, the video is automatically paused again. This will happen with every video that I'll try to load (Youtube and internal ), until I'll kill my app. After killing my app everything will work normally again.
Is it possible that the first view/video is not terminated so each new video will automatically be paused, in order to prevent the two to play at the same time?
Tnx!
Yaniv

After struggling with this issue for few days, I found the solution. It appears that when closing the Webview, the Mediaplay probably did not have focus, which prevented him from pausing/dismissing. This prevented all other Webviews with Mediaplayers from playing (automatically paused each time trying to play, with no ability to resume).
When adding this code:
#Override
protected void onPause() {
super.onPause();
((AudioManager)getSystemService(
Context.AUDIO_SERVICE)).requestAudioFocus(
new OnAudioFocusChangeListener() {
#Override
public void onAudioFocusChange(int focusChange) {}
}, AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
The problem was completely solved. The Mediaplayer was dismissed/paused (not sure which, have to check), and a new Webview with a new Mediaplayer can gain focus and play normally.
Hope it could help other people struggling with this issue..

Related

VideoView stop playing when fragment goes into pause/stop state

I am using a videview to play a video in my fragment when i press the phone home button while video playing and bring the app to foreground again video stops.What is guess is onPause of activity is called that makes the fragment state to reinitialize of some similar reason.Kindly suggest some solution.
Regards:Ali

Video stop in WebView

My Activity contains webView. Sometimes webView contains video. When watching the video in webView and press the back button, I go on to another Activity, but the video continues to play and I hear the sound of video. How can I solve this problem? Thank you in advance.
Couple different options:
if you want to completely stop the video, make sure you call finish() when clicking back.
You can do that like this on your Activity:
#Override
public void onBackPressed() {
this.finish();
}
Activity will be destroyed and video will stop.
If you want to stop the video but not destroy the activity, edit your question and show some of your code so I can give you more options.
This is a solution that works for me: How to stop youtube video playing in Android webview?
mWebView.onPause();

Application gets hanged on pressing back button when video is buffering in video view

I am playing video on video view, the issue which i am facing is that when user press back button, the application gets stuck for some time and then onStop method is called of that activity, i don't know why the application is taking time in calling onStop method. Please can anyone help me out.
What jaydroider said is right. You have to override onBackPressed method as follows
#Override
public void onBackPressed() {
<stop your video here>
super.onBackPressed();
}
It is important that you stop the video before calling super.onBackPressed(); so that your application does not get stuck.
You should stop video on onPause() not on onBackPressed(). Because user may use the Home key while using your app. This will stop playing video whenever your screen is not visible to user.

How to implement the Pause action for the android VideoView?

In my Application i am going to Play the VideoView.
I am not using the Media Controller for variour option like Play, Pause and Stop.
Instead of that i am Using Single Button to Use Play and Pause Functionality.
I have Implement like Below Code:
case R.id.playVideoBtn:
if(myVideoView.isPlaying()){
myVideoView.pause();
}else{
//MediaController ctlr=new MediaController(this);
// ctlr.setMediaPlayer(myVideoView);
//myVideoView.setMediaController(ctlr);
myVideoView.start();
}
break;
Now i am wonder about how to implement the Pause functionality for the same Button Click.
Please help me for it.
Thanks.
From VideoView.java I found...
start() goes with pause(), but resume() goes with suspend() (the latter pair causing the screen to blank out).
And for your solution look at this example Playing Video

Video is not shown when returning to app

I have an activity with MediaPlayer and Button. The MediaPlayer contains a VideoView (using MediaPlayer.getDisplay(VideoView.getHolder())). When the button is pressed it pause the MediaPlayer and open a browser. returning to app suppose to continue the video (MediaPlayer .start())
When the activity started the video is plays and shown as expected but when i press the button and then I press return to the app the video is not shown but the sound is working.
Any idea how to make the video visible?
-Z

Categories

Resources