Android set YouTube video quality using YouTubeAndroidPlayerApi

南楼画角 提交于 2020-02-08 05:20:20

问题


I am using YouTubePlayer to play youtube video in my app. Here is the code I have got from Sample sdk:

 package com.example.androidyoutubeapiplayer;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubePlayer.Provider;

import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {

public static final String API_KEY = "AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA";
public static final String VIDEO_ID = "o7VVHhK9zf0";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

YouTubePlayerView youTubePlayerView = (YouTubePlayerView)       findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
}

@Override
 public void onInitializationFailure(Provider provider,
    YouTubeInitializationResult result) {
Toast.makeText(getApplicationContext(), "onInitializationFailure()",
        Toast.LENGTH_LONG).show();
}

@Override
public void onInitializationSuccess(Provider provider,
    YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
    player.cueVideo(VIDEO_ID);
}
 }

}

Videos are playing well but I just want to set the quality of the video. By default i can only set CC and HQ quality in youtubeplayer. But i want to set HD quality or like different video qualities in youtube (240p,360p,480p,720p if available). It is said here that we can set video quality by calling setPlaybackQuality function but i could find it.

Any suggestion would be appreciated. Thanks.

来源:https://stackoverflow.com/questions/23646537/android-set-youtube-video-quality-using-youtubeandroidplayerapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!