问题
I am able to display a 3gp video from server. But when I tried to play an mp4 video it displayed an alert saying that Sorry,this video cannot be played. Please help me in this regard.
package com.play.video;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class PlayvideofromserverActivity extends Activity
{
private VideoView vView;
private String vSource;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vView = (VideoView)findViewById(R.id.vview);
vView.requestFocus();
vSource ="http://server.com/testvideo.mp4";
vView.setVideoURI(Uri.parse(vSource));
vView.setMediaController(new MediaController(this));
vView.start();
}
}
回答1:
Try this code. It help you.
myVideoView.setMediaController(new MediaController(this));
myVideoView.setVideoPath(videoSource);
myVideoView.requestFocus();
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
myVideoView.start();
}
});
Thanks
回答2:
Android doesn't always play mp4.
MP4 is just a container - the video and audio stream inside it will both be encoded in different formats.
Android natively only supports certain types of formats.
There is a list here:
http://developer.android.com/guide/appendix/media-formats.html
Make sure the video and audio encoding type is supported
. Just because it says "mp4" doesn't automatically mean it should be playable.
Credit goes to Ken Wolf
回答3:
Try this code
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
String s=Common.videofilepath;
//Set the path of Video or URI
videoView.setVideoURI(Uri.parse(Common.videofilepath));
//Set the focus
videoView.requestFocus();
videoView.start();
来源:https://stackoverflow.com/questions/10991515/how-to-play-an-mp4-video-from-server-in-android