Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

android - Play private YouTube video using YoutubePlayerView from YoutubeAndroidPlayerAPI?

I've started using YouTube API for Android a month ago. I'm trying to make an Android application which can play some videos which includes my uploaded videos. With the public videos, it works. But with the private videos, YoutubePlayerView shows: "Please sign in".

I couldn't figure out how to sign in and play these videos since YoutubeAndroidPlayerAPI seems not support authentication.

This is what I'm doing with "JurB9k3_Ws4" is my private video ID.

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

    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer,
                                            boolean b) {
            youTubePlayer.cueVideo("JurB9k3_Ws4");
        }

        @Override
        public void onInitializationFailure(YouTubePlayer.Provider provider,
                                            YouTubeInitializationResult youTubeInitializationResult) {

        }
    });
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is not possible with the Android Player API. The only way to play private videos on a device is to implement a WebView in your app, have the user log into their YouTube account, and then play back the Private video in that specific browser session only. YouTube suggests marking videos as Unlisted rather than Private for playback on mobile devices.

More info in this Google Groups post about playing back private videos using the embedded player.

Playing back a private video in an embedded player will only work if you have a YouTube login cookie in your browser that corresponds to an account that is permissioned to watch that video. Otherwise, it will fail. Authentication with the Data API has nothing to do with whether you can play the video back in an embedded player.

...

There's no programmatic way to create a login cookie. The user actually has to login to YouTube.com using the same browser instance that's using the embed, and that can't be scripted.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...