now I'm developing an android Video on Demand or Audio on Demand Player, I notice there's a function in package android.net.Uri, part of my code of play the video or audio is like this:
Play Audio part:
mPlayer = new MediaPlayer();
mPlayer = MediaPlayer.create(this, Uri.parse("http://.../MJ.mp3"));
mPlayer.setLooping(true);
mPlayer.start();
Play Video Part:
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
String vidAddress = "https://.../ABC.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
vidView.start();
I'm wondering does this satisfy the video or audio on demand request? In an other word, when I play the audio or video using the URI function, does it work like Youtube, which downloads just part of the video and plays the video, or download the whole file first then play it?
Related
I am developing a video based android application. I want to play a video (Video Format: mp4) from a URL. But it's not live stream video stored in the server. Get video URL from JSON object and playing video. The video is playing but not in a good manner.
Sometimes the audio is mismatched then take more time to play some take more time to buffer. But with the same video and same wifi speed I have on my system when playing with chrome it's playing well. I don't know what I am doing wrong? I also tried with android video view but the same problems occurred.
My code to start video player
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(uri), "video/*");
startActivity(intent);
My code to playing with video view
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
What android version did you try? Because https is not supported before android 3.1.
Check supported protocols and media formats here
You can use the MediaPlayer to do this.
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Map<String, String> headers = new HashMap<String, String>();
headers.put("rtsp_transport", "tcp");
headers.put("max_analyze_duration", "500");
mMediaPlayer.setDataSource(context, Uri.parse(videoUrl), headers);
Please tell me why this would work on with MediaPLayer and not in videoView? And how to make it work with a video view?
Videos are downloaded form an API and saved in this folder I created:
File mediadir = cw.getDir("tvr", Context.MODE_PRIVATE);
VideoView
final Uri uri = Uri.parse(path);
// path = /data/data/com.foo.app/tvr/video.mp4
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoURI(Uri.parse(path));
videoView.start();
Error VideoView Sorry, this Video cannot be player and error (1, -2...)
MediaPlayer --- THIS WORKS
FileInputStream fileInputStream = new FileInputStream(path);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fileInputStream.getFD());
pl.prepare();
pl.start();
The basic reason is the MODE_PRIVATE, which disallow VideoView and MediaPlayer from playing non-World Readable files, unless you pass the FD as you have.
Here's a more detailed explanation
I am using following code to play mp4 videos which is stored in sever.... And i am get error like this->
This Video can not be played????
Uri video = Uri.parse("http://129.0.0.....");
MediaController mediaController = null;
mVideoView.setMediaController(mediaController);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://129.0.0....")));
mVideoView.setVideoURI(video);
mVideoView.setVideoPath("http://129.0.0......");
mVideoView.requestFocus();
mVideoView.start();
This might be helpful to you i have used this in android 2.3.3.
public void videoPlayer(String path, String fileName, boolean autoplay){
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//the VideoView will hold the video
VideoView videoHolder = new VideoView(this);
//MediaController is the ui control howering above the video (just like in the default youtube player).
videoHolder.setMediaController(new MediaController(this));
//assing a video file to the video holder
videoHolder.setVideoURI(Uri.parse(YOUR_SERVER_VIDEOFILE_URL));
//get focus, before playing the video.
videoHolder.requestFocus();
if(autoplay){
videoHolder.start();
}
}
Always pass the mp4,3gp etc video format link in URI.Try this code:
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp"));
videoView.requestFocus();
videoView.start();
How to play more than one video from one activity in my android application? I have the following code:
VideoView vd = (VideoView) findViewById(R.id.surface_view);
String movieurl = Environment.getExternalStorageDirectory() + "/content1/bio_brain.mp4";
mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoPath(movieurl);
vd.start();
MediaPlayer can play one video at a time. It has an OnCompletionListener callback you can register to get notified when playback stops. Then you can play the second video.
I want to play mp4 video using tag on Webview. I have few constraints for not to use HTML5 tag. I have looked code to play YouTube video on webview. But YouTube uses .flv format. I have .mp4 video to play.
Thanks in advance.
You could play the video directly, without a WebView:
VideoView videoView = new VideoView(this);
setContentView(videoView);
Bundle extra = getIntent().getExtras();
if (null != extra && extra.containsKey("url")) {
String url = extra.getString("url");
Uri uri = Uri.parse(url);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(uri);
videoView.start();
}