如何通过服务器在Android中播放mp4视频

时间:2012-03-08 08:25:17

标签: android android-videoview

我正在使用以下代码播放存储在服务器中的mp4视频....我收到的错误就像这样 - >

此视频无法播放????


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();

2 个答案:

答案 0 :(得分:2)

这可能对你有帮助我在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();
}

}

答案 1 :(得分:0)

始终在URI中传递mp4,3gp等视频格式链接。请尝试以下代码:

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();
相关问题