2
votes

How to Play mp4 Video in Android Emulator Using Remote URL ? I used following code but this code give me error "Sorry, this video cannot be played".

07-05 16:58:19.525: INFO/AwesomePlayer(34): mConnectingDataSource->connect() returned -1007
07-05 16:58:19.525: ERROR/MediaPlayer(1242): error (1, -1007)
07-05 16:58:19.525: ERROR/MediaPlayer(1242): Error (1,-1007)
07-05 16:58:19.525: DEBUG/VideoView(1242): Error: 1,-1007

My Code is:-

public class VideoPlayerController extends Activity {
     @Override
     public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);          
                VideoView videoView = (VideoView) findViewById(R.id.VideoView);
                MediaController mediaController = new MediaController(this);
                mediaController.setAnchorView(videoView);
                String Video="http://s509.photobucket.com/albums/s338/eveanthony/?action=view&current=Video013.mp4";
                videoView.setMediaController(mediaController);
                videoView.setVideoURI(Uri.parse(Video));
                videoView.start();
            }
}
3
The emulator did not play mp4 videos for me either. I tested with device and it worked well. By the i pasted the video url in my browser and the video link seems to be broken..Varun
Mp4 Video is Working on Emulator But not from remote URL only from Local file.Dipak Keshariya
Did you try it on a device. For me, only 3gp played on emulator and on device I was able to play mp4 as well. As I mentioned, the video url in the question seems to be broken.Varun
No I tried it on Emulator.and it is Working Very Well but play only Local File.Dipak Keshariya

3 Answers

9
votes

You need to execute the app on original device rather than emulator since it does not supports playing video files. In rare cases it may but it really depends upon your system configurations.

2
votes

Android 4.1.2 version seems to play mp4 video in the emulator in youtube app, not elsewhere. I tested it. Both Intel and non-Intel version work. 4.0.3 did not play them.

0
votes
private VideoView myVideoView;
private int position = 0;
private ProgressDialog progressDialog;
private MediaController mediaControls;

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   private static final String Videos_URL = "*Your_URI*";

    // Get the layout from video_main.xml
    setContentView(R.layout.activity_main);

    // Find your VideoView in your video_main.xml layout
    myVideoView = (VideoView) findViewById(R.id.videoView);

    // Create a progressbar
    progressDialog = new ProgressDialog(this);
    // Set progressbar title
    progressDialog.setTitle("Anything u Want");
    // Set progressbar message
    progressDialog.setMessage("Loading...");

    progressDialog.setCancelable(false);
    // Show progressbar
    progressDialog.show();

    try {
        Uri video = Uri.parse(Videos_URL);
        myVideoView.setVideoURI(video);
        myVideoView.setMediaController(mediaControls);
    } catch (Exception e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }

    myVideoView.requestFocus();
    myVideoView.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            progressDialog.dismiss();
            myVideoView.seekTo(position);
            if (position == 0) {
                myVideoView.start();
            } else {
                myVideoView.pause();
            }
        }
    });

}

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putInt("Position", myVideoView.getCurrentPosition());
    myVideoView.pause();
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    position = savedInstanceState.getInt("Position");
    myVideoView.seekTo(position);
}

}