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));
Related
I want to play YouTube videos on Android without using YouTube app. It should play with Android player. We have tried using YouTube app, but we need to play YouTube videos directly with Android player, not using YouTube application.
Is it possible? If it is, how to do it?
try this.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse("your url in rtsp format");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
Its simple just create video view then add a new media controller to it, set the video URL in the video view and start the video it will work.
Add the below Code into your MainActivity.java file.
#Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.videodisplay);
String link="http://www.youtube.com/watch?v=JSnB06um5r4";
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
You better try it on offline file to make sure that the video viewer is working fine (the video is compatible with device) then play it online
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.
How can I open a udp multicast video stream on android ?
I tried this code:
public class androidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse("udp://224.1.1.1:1234");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
but it doesn't work.
Android doesnt support UDP for audio and video playback.
see http://developer.android.com/guide/appendix/media-formats.html
You can use RTP over UDP.
This is with RTSP setup via TCP.
I do this with stock android rom, no third party apps required.
Stagefright framework.
I have a video player in my android app. By default, the MediaController becomes visible upon playing for 3 seconds, if no activity.
The app goes through a series of short clips and that is fine, however, the MediaController pops up every time the video changes.
Is it possible to have it only show on demand (tapping the video view)?
I tried calling controller.hide() and controller.show(0) after I call vidPlayer.start(), but neither have worked. Any ideas?
final MediaController mc = new MediaController(this);
vView.setMediaController(new MediaController(this)
{
#Override
public void hide()
{
mc.show();
}
});
vView.setMediaController(mc);
vView.start();
I am adding MediaController to a VideoView, but it does not show up unless I tap the phone. The controller disappears after a while.
Is there a way I can have the MediaController show always?
Thanks
Chris
As Default mediacontroller will hide in 3 seconds of user's inactivity. you can set the timeout seconds by
new media controller().show(50000);
check this link
The below code shows MediaController always:
VideoView videoView;
MediaController mc;
videoView.setMediaController(new MediaController(this)
{
public void hide()
{
System.out.println("HIDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEHELLLOO");
mc.show();
}
});