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

查看:41
本文介绍了使用 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,对应于有权观看该视频的帐户.否则,它将失败.使用数据 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天全站免登陆