Dowemo
0 0 0 0


Question:

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

Best Answer:


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

}




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs