Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

How to play .mp4 video in videoview in android?

I am working on a video player application, I want to play .mp4 video in the native video view. I am not able to play video using a URL. I am getting the error "Sorry this video cannot be played" and I am also not able to play downloaded video in the native video view either.

My code for playing video in the video view:

String mUrl = "http://www.servername.com/projects/projectname/videos/1361439400.mp4";

VideoView mVideoView  = (VideoView)findViewById(R.id.videoview)
videoMediaController = new MediaController(this);
mVideoView.setVideoPath(mUrl);
videoMediaController.setMediaPlayer(mVideoView);
mVideoView.setMediaController(videoMediaController);
mVideoView.requestFocus();
mVideoView.start();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Finally it works for me.

private VideoView videoView;

videoView = (VideoView) findViewById(R.id.videoView);

Uri video = Uri.parse("http://www.servername.com/projects/projectname/videos/1361439400.mp4");
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  @Override       
  public void onPrepared(MediaPlayer mp) {
       mp.setLooping(true);
       videoView.start();
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...