Help with capturing pause/resume with VideoView with MediaController after video starts - android

...
mVideoView = (VideoView) findViewById(R.id.video);
mVideoView.setKeepScreenOn(true);
final Intent intent = getIntent();
mHeadline = intent.getStringExtra("headline");
String liveVideoUrl = intent.getStringExtra("live_video_url");
mVideoView.setVideoPath(liveVideoUrl);
mMediaController = new MediaController(this);
mVideoView.setMediaController(mMediaController);
mVideoView.start();
...
I need to capture when the user presses the pause/play buttons. The VideoView encapsulates Media Player hence how do I capture the play/pause events? Thanks.

Create a class that extends VideoView and use this class in your layout which is assigned to mVideoView.

Related

Change a video that plays in a VideoView whenever I want. Manually

I have an activity that has a button, when I click this button another activity opens and plays a video defined by me from sdcard (or phone).
The problem: I want to change which video will play always when I wish.
Example: first I pre-define to play a video about Mario. Later, I want that the same button plays a video about Luigi, then I do some method that allow me to make this trade. Or any user that use the app.
Anybody could help me how can I do this?
Here's the basic code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
video_player = (VideoView) findViewById(R.id.video_frame);
media_Controller = new MediaController(this);
dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.widthPixels;
video_player.setMinimumWidth(width);
video_player.setMinimumHeight(height);
video_player.setMediaController(media_Controller);
video_player.setVideoPath("/sdcard/videoplay.mp4");
video_player.start();
}
In button click dynamatically change video url as per your wish store string url.
//first activity
Intent intent = new Intent(getActivity(), VideoFullScreenActivity.class);
intent.putExtra("URL", url);
startActivity(intent);
//video activity
if (intent.hasExtra("URL")) {
urlVideo = intent.getStringExtra("URL");
}
video = (VideoView) findViewById(R.id.videoView);
media = new CustomMediaController(this);
media.setAnchorView(video);
video.setMediaController(media);
video.setVideoURI(Uri.parse(urlVideo));
video.requestFocus();
video.seekTo(current);
video.start();

display time on android media controller

Am I missing something? Once I play a video using videoview, I cannot see the current time of the video on the media controller. (Running app on a ICS device, there is no time; however on a Honeycomb device there is time)
Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
// Use a media controller so that you can scroll the video contents
// and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView
.setVideoURI(Uri
.parse("rtsp://v6.cache5.c.youtube.com/CiILENy73wIaGQmCZld_oqDeJhMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
videoView.start();
}
Actually I noticed the time is there but it's so dim and I cannot see it. Is there any way that I can change the theme of the media controller?
The answer is kind of general to all of the controllers such a mediacontroller, dialog, toast, etc.
you can use ContextThemeWrapper:
instead of:
MediaController mediaController = new MediaController(this);
you can use:
MediaController mediaController = new MediaController(new ContextThemeWrapper(this,R.style.CustomTheme));

can anyone explain this code of media controller?

can anyone explain this code of media controller?
videoview = (VideoView) findViewById(R.id.player);
videoview.setVideoURI(Uri.parse("android.resource://"+ getPackageName()+ "/" +R.raw.sample));
videoview.start();
MediaController controller = new MediaController(this);
controller.setMediaPlayer(videoview);
videoview.setMediaController(controller);
The code gets a VideoView by its id, sets the uri of the file to play to an embedded resource and starts playback.
Then it attaches a MediaController to the view which renders the progress bar and some controls to play / pause the video.

Returning to application after videoplayback

I have an application that has a list of videos with a play button. When I click on video, a separate activity is called through intent. When the video is finished, it remains there and it doesn't go back to the original application unless I press back button. Is there any way in which the application returns back to the main activity after the video playback is finished? Here is the code for my video creation
public void onCreate(Bundle onSavedInsance) {
super.onCreate(onSavedInsance);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.videoview);
Intent i = getIntent();
Bundle extras = i.getExtras();
filename = extras.getString("videofilename");
mVideoView = (VideoView) findViewById(R.id.VideoView);
mc = new MediaController(this);
mVideoView.setMediaController(mc);
mc.setAnchorView(mVideoView);
mVideoView.setMediaController(mc);
mVideoView.setVideoPath(filename);
//mVideoView.setVideoPath(video.getAbsolutePath());
mVideoView.requestFocus();
mVideoView.start();
}
If you are using a VideoView, you can add a listener to determine when the video has finished playing:
mVideoView.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
finish();
}
});

Android-Media Player

I am new to android. I am trying to play a video from sdcard.
this is the sample code I have used:
public class videoa extends Activity {
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
// (1) Web
//videoView.setVideoURI(Uri.parse(
//"http://www.bogotobogo.com/Video/sample.3gp"));
//"http://www.bogotobogo.com/Video/sample.mp4"));
//"http://www.bogotobogo.com/Video/sample.mov"));
/* (2) SD card */
//videoView.setVideoPath("/sdcard/sample.3gp");
videoView.setVideoPath("/sdcard/robot.avi");
//videoView.setVideoPath("/sdcard/sample.mov");
// videoView.setVideoURI(Uri.parse(
//"file:///sdcard/sample.mov"));
videoView.requestFocus();
videoView.start();
}
}
I have launched manually And set the target as -sdcard C:/android-sdk-windows/tools/sdcard.img.
When i have launched the emulator it shows Video Cannot be Displayed.
Please help me out.
You try interchanging the 2 lines
final String MEDIA_PATH = new String("/sdcard/robot.avi");
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setVideoPath(MEDIA_PATH);
videoView.setMediaController(mc);
videoView.requestFocus();
videoView.start();

Categories

Resources