使用来自YoutubeAndroidPlayerAPI的YoutubePlayerView播放私人YouTube视频? [英] Play private YouTube video using YoutubePlayerView from YoutubeAndroidPlayerAPI?

查看:74
本文介绍了使用来自YoutubeAndroidPlayerAPI的YoutubePlayerView播放私人YouTube视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个月前,我开始使用Android版YouTube API.我正在尝试制作一个可以播放一些视频的Android应用程序,其中包括我上传的视频.使用公共视频,它可以正常工作.但是对于私人视频,YoutubePlayerView会显示:请登录".

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".

我不知道如何登录播放这些视频,因为YoutubeAndroidPlayerAPI似乎不支持身份验证.

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

这就是我使用"JurB9k3_Ws4"做的私人视频ID.

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) {

        }
    });
}

推荐答案

Android Player API无法做到这一点.在设备上播放私人视频的唯一方法是在您的应用中实现WebView,让用户登录其YouTube帐户,然后在仅特定浏览器会话中播放私人视频.YouTube建议将视频标记为不公开,而不是私有,以便在移动设备上播放.

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.

此Google网上论坛帖子中的更多信息使用嵌入式播放器播放私人视频.

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

只有在以下情况下,才能在嵌入式播放器中播放私人视频:您的浏览器中有一个YouTube登录Cookie,它对应于有权观看该视频的帐户.否则,它将失败.使用Data API进行身份验证与是否进行身份验证无关您可以在嵌入式播放器中播放视频.

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.

...

没有编程的方式来创建登录cookie.用户实际上必须使用相同的浏览器实例登录YouTube.com正在使用嵌入,并且无法编写脚本.

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.

这篇关于使用来自YoutubeAndroidPlayerAPI的YoutubePlayerView播放私人YouTube视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆