开发者

How to run a video hosted on YouTube or a private server in Android?

I have about 3 videos that i cannot install with my app on DROID due to their huge size. Now we have decided to host them on a private server or YouTube. How can i run these videos开发者_JAVA技巧 in Android? Thank you


If you do want to use a private server, you can just use Android's media features, playing a video with them is pretty simple if you have it in the proper format:

http://developer.android.com/guide/topics/media/index.html

Look especially at "Playing from a File or Stream". You can use setDataSource of the MediaPlayer to point to a remote location:

myMediaPlayer.setDataSource(myContext, "http://www.example.com/myVideo.3gp");

If you do choose to use YouTube, the problem is that the native format of YouTube is FLV which I don't think the MediaPlayer supports (as Flash support isn't completely available on Android, even with the install of the Flash Player, someone correct me if I'm wrong). YouTube does provide mobile versions, but the resolution is really poor and does not really suit high-end Android devices. There are versions for iPhone and Android apparently (for the native app), but I haven't found a way to get the URL.

Your best bet is with a private server.


You can use Intents to run start the native YouTube app on the phone. Read more here: Android YouTube app Play Video Intent


I have this code here and am getting the message: "This Video Cannot Be Played". Why?

package com.feelsocial.games.androidskillz;

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

public class AndroidSkillz extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        VideoView video = (VideoView)findViewById(R.id.VideoView01);

        Uri uri = Uri.parse("http://developer.avenuesocial.com/maxood.mov");
        MediaController mc = new MediaController(this);
        video.setMediaController(mc);
        video.setVideoURI(uri);
        video.start();
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜