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
Related
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();
I have an audio playing in the background when I am clicking onto a new activity. I want while I am clicking to the next activity, for the audio, to stop.
However, when going back to the original activity I want the audio to start again from the beginning.
Using media player and Android Studio. Here's all the media player code I have so far:
MediaPlayer mediaPlayer = MediaPlayer.create(pagetwo.this,R.raw.audio1);
mediaPlayer.start();
You can use the basic lifecycle methods of your Activity to handle this use case:
Android will call onPause() if you open a new Activity and will call onResume() if you enter/come back to the first activity.
If you call mediaPlayer.start() in onResume() and mediaPlayer.stop() in onPause() you should have the desired behavior.
I am working on a music player and everything is fine the play, stop, and pause buttons.
My problem is that whenever a song is playing and I press the back button and reopen the app the buttons won't work with the current song.
This happens as well when I change the orientation. Is there a way I can save the state of the media player and then obtain the state so that I can stop the song that is being played?
Well, you could use
.getCurrentPosition()
to get how many milliseconds into thew song you are, then use
.seekTo(int milliseconds)
upon resuming or an orientation change, to get to the same spot.
You can use the SeekTo method.
Seek To
Then add:
protected void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putInt(PLAY_TIME, mMediaPlayer.getCurrentPosition());
}
And later in the OnCreate, you just need to check something like this:
if(savedInstanceState != null && savedInstanceState.containsKey(PLAY_TIME)) {
mMediaPlayer.seekTo(savedInstanceState.getInt(PLAY_TIME, 0));
}
Hope this helps
I have a VideoView in one of my Activities and if I try to press the back Button it doesn't take me to the previous Activity and it doesn't give any error messages in the log cat either.
I have tried overriding the onBackPressed() method and I have tried calling the prev Activity using an Intent, but even then the back Button didn't do anything.
This problem only occurs when the video is playing and even after it is finished playing. The only time the back Button works is before the video starts playing. My VideoView also has a MediaController set to it.
Any ideas ?
Thanks!
From CommansWare
Based on the source code, this should work:
Extend MediaController (for the purposes of this answer, call it
RonnieMediaController)
Override dispatchKeyEvent() in RonnieMediaController
Before chaining to the superclass, check for KeyEvent.KEYCODE_BACK,
and if that is encountered, tell your activity to finish()
Use RonnieMediaController instead of MediaController with your
VideoView
Personally, I'd just leave it alone, as with this change your user
cannot make a RonnieMediaController disappear on demand.
Here is the link to the original post.
I have a problem that I want to call a User Defined function on Pause Button Pressed while playing a video file in our App, How can I do that? Please suggest me for right result.
Thanks in advance for any suggestions
VideoView v=new VideoView(this);
Take one Button to pause Video and then call
v.pause();
now after this you can do anything