1

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();
    }
} 
Bob
  • 22,810
  • 38
  • 143
  • 225
user1425825
  • 15
  • 2
  • 6

3 Answers3

2

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

yorkw
  • 40,926
  • 10
  • 117
  • 130
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
1

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

Community
  • 1
  • 1
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
0

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();
yorkw
  • 40,926
  • 10
  • 117
  • 130
mohamed
  • 303
  • 1
  • 6
  • 19