开发者

how to view youtube video

I am finding great difficulties to view YouTube videos in my app.

here is my code:

package com.example.webvideo;

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


public class WebVideo extends Activity {
    /** Called when the activity is fir开发者_StackOverflow社区st created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VideoView vv = (VideoView) findViewById(R.id.videoView);
        MediaController mc = new MediaController(this);
        mc.setAnchorView(vv);
        vv.setMediaController(mc);

        vv.setVideoURI(Uri.parse("http://youtu.be/2OIOOb-0t44"));
        vv.start();


       }
    }

The emulator is showing an error that the video cannot be played.

What am I doing wrong? Am I giving the URL in a wrong format?


I would expect that the URI you need to give is to the actual media file to be played. I wouldn't count on redirects working either... and anyway that redirect you give seems to point to a YouTube web page, which I sure wouldn't expect the video player to be able to render.


http://youtu.be/2OIOOb-0t44 is certainly an invalid URL. Maybe you meant http://youtube.com/watch?v=2OIOOb-0t44?


The URL you are using is for the webpage where you can view it, not for the video itself. The embedding URL appears to be http://www.youtube.com/embed/2OIOOb-0t44, but I think it's HTML5, not flash... you may have to go old school and track down an AVI or MPEG file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜