11

I have tried to play a youtube video by its URL by my android program. I have used setVideoURI(uri); function also to set URI, as suggested by other POSTs in stackoverflow regarding this. But I am getting Couldn't open file on client side, trying server side error. Can you please figure out what is the problem with my code.

But I am able to play any local video by commented code.

Here is my android code-

public class VideoActivity extends Activity {

    //MediaPlayer song= new MediaPlayer();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        VideoView videoView = (VideoView)this.findViewById(R.id.VVSimpleVideo);
        MediaController mc = new MediaController(this);
        mc.setAnchorView(videoView);
        mc.setMediaPlayer(videoView);
        videoView.setMediaController(mc);
        //String _path = "mnt/sdcard/Movies/MyCameraApp/video6.mp4";
        String _path = "http://www.youtube.com/watch?v=E43mgXNl0xc";
        Uri uri=Uri.parse(_path);
        videoView.setVideoURI(uri);
       //videoView.setVideoPath(_path);

        videoView.requestFocus();
        videoView.start();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_video, menu);
        return true;
    }
}

Here is the Log Error-

  10-11 04:51:23.480: D/MediaPlayer(4714): Couldn't open file on client side, trying server side
10-11 04:51:26.130: E/MediaPlayer(4714): error (1, -2147483648)
10-11 04:51:26.130: E/MediaPlayer(4714): Error (1,-2147483648)
10-11 04:51:26.130: D/VideoView(4714): Error: 1,-2147483648
10-11 04:51:26.190: D/dalvikvm(4714): GC_CONCURRENT freed 174K, 4% free 6785K/7047K, paused 4ms+3ms

Thanks in Advance.

Vishal
  • 673
  • 3
  • 12
  • 24
  • You need to play video rtsp format in video view. – Hardik Joshi Oct 11 '12 at 04:54
  • You can refer these links to play video from url: http://stackoverflow.com/questions/2620049/how-to-play-video-from-url http://stackoverflow.com/questions/10597800/android-play-video-from-url – kittu88 Oct 11 '12 at 04:54

3 Answers3

3

Once you get the You tube url..., Substring the Video_ID from the Url.See the example below i have given.

once you get the rtsp link you can play video in VideoView Here is example.

For example: If this link is the video http://www.youtube.com/watch?v=E43mgXNl0xc

Then E43mgXNl0xc is the Video_ID.

Use this video id to play video in videoview.

Refer these two links:

Link 1

Link 2

Once you get the rtsp link you can play it in VideoView.

Also check my answer Here.

Community
  • 1
  • 1
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0

On Android devices, you can use an Intent for Youtube videos:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=E43mgXNl0xc"));
startActivity(browserIntent);                          
Vincent Durmont
  • 813
  • 8
  • 16
Deepanker Chaudhary
  • 1,694
  • 3
  • 15
  • 35
0

i had the same issue none of the answers worked for me, The issue is that video format is not proper this video worked for me

String vidAddress = "http://www.html5videoplayer.net/videos/toystory.mp4";
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52