0

here this is my code for downloading a video through providing a needed video URL in the coding , the its automatically download in my manner but its not working any body suggest me?

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class Video extends Activity {
    /** Called when the activity is first created. */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.main);

        VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
        MediaController mc = new MediaController(this);
        videoView.setMediaController(mc);
        // (1) Web
        videoView.setVideoURI(Uri.parse("http://www.youtube.com/watch?v=CHVhwcOg6y8"));




        videoView.requestFocus();
        videoView.start();
    }
} 
Crishnan Kandada
  • 651
  • 2
  • 9
  • 24

1 Answers1

2

The Link you have provided http://www.youtube.com/watch?v=CHVhwcOg6y8 , is a HTML page.
The URI to be provided for setVideoURI() should be a media file such as mp4 or avi.

VideoView cannot parse a HTML page. It can only decode and play a video file or stream a video content (in this case Uri should point to the media file, such as http://people.sc.fsu.edu/~jburkardt/data/mp4/cavity_flow_movie.mp4 )
See this: Using VideoView for streaming or progressive-download video

You should use a Webview for opening the YouTube link.

Community
  • 1
  • 1
Karthik
  • 3,509
  • 1
  • 20
  • 26