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.
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 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.
There are two activities, Start Activity is composed VideoView and Main Activity(listview) overlays on VideoView. Because I don't know how to overlay Listview transparently on videoview at one activity. That's why I used two activity.
StartActivity(videoView) -> MainActivity(Listview)
The problem is that when I finish this app using back key, only ListView is killed. So I have to press back key again for killing videoView. I have searched all info, but I can't find out.
when you go to Listview from videoview, at that time use finish() with intent. just like below
Intent mIntent = new Intent(Activity_Listview.this,
Activity_videoview.class);
startActivity(mIntent);
finish();
What you probably want to use ("to overlay the listview") is a fragment.
Since your app will only use 1 activity it will exit immediately when the back button is pressed. This would be the correct way to do the thing you described instead of trying to kill 2 activities with 1 back-key press.
When launching MainActivity(Listview) you could use startActivityForResult (http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int) ) and in the setResult method you can add some information which then to trigger the finishing of StartActivity(videoView).
Please note that these are only tricks. The correct implementation would be to use Fragments (as user3249477 suggested).
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
I have an application with a list of video files with play button. When the user clicks play button, a separate activity starts through intent where the video is played. What I want is that when I click the back button when the video file finishes, I want the mainActivity to be refreshed (the mainActivity is the activity that started the activity for playing video file).
Any useful suggestions please??
Put your "refresh"-code in the Main-Activity's onStart-method.
See Androids Activity Lifecycle.
You could use startActivityForResult(Intent, int) and then handle the different results.