如何在应用程序中播放Youtube实时流视频?

问题描述:

我正在尝试使用api密钥在我的应用程序中播放YouTube直播视频,但显示如下错误: Playback on other applications has been disabled by the video owner.

I am trying to play live stream youtube video in my application using api key but it's showing error like: Playback on other applications has been disabled by the video owner.

这是图片描述:

这是我的代码,用于通过使用视频ID加载视频:

Here is my code which is used to load video by using video id:

public class MainActivity extends YouTubeBaseActivity implements
        YouTubePlayer.OnInitializedListener {
    private static final int RECOVERY_DIALOG_REQUEST = 1;
    // YouTube player view
    private YouTubePlayerView youTubeView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
        // Initializing video player with developer key
        youTubeView.initialize(Config.DEVELOPER_KEY, this);

    }
    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                        YouTubeInitializationResult errorReason) {
        if (errorReason.isUserRecoverableError()) {
            errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
        } else {
            String errorMessage = String.format(
                    getString(R.string.error_player), errorReason.toString());
            Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
        }
    }
    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                        YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {

            // loadVideo() will auto play video
            // Use cueVideo() method, if you don't want to play it automatically
            player.loadVideo("ywrPouTDTAE"); //live vid

            // Hiding player controls
          //  player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RECOVERY_DIALOG_REQUEST) {
            // Retry initialization if user performed a recovery action
            getYouTubePlayerProvider().initialize(Config.DEVELOPER_KEY, this);
        }
    }

    private YouTubePlayer.Provider getYouTubePlayerProvider() {
        return (YouTubePlayerView) findViewById(R.id.youtube_view);
    }

}

视频所有者已禁止在其他应用程序上播放.

Playback on other applications has been disabled by the video owner.

如果收到此消息,则说明原始YouTube的上传者已禁止嵌入到android应用等第三方网站上.这是原始YouTube上传者需要更改的设置.

If you get this message, then the uploader of the original YouTube has disabled embedding onto third-party sites like android apps. This is a setting that the original YouTube uploader will need to change.

  1. 访问您的视频管理器.
  2. 找到要更改的视频,然后单击编辑".
  3. 点击视频下的高级设置.
  4. 选中分发选项"部分下的允许嵌入"复选框.
  5. 点击页面底部的保存更改.