Android使用YouTubeAndroidPlayerApi设置YouTube视频质量

时间:2014-05-14 05:46:14

标签: android youtube-api android-youtube-api

我正在使用YouTubePlayer在我的应用中播放YouTube视频。这是我从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);
}
 }

}

视频播放效果不错,但我只想设置视频的质量。默认情况下,我只能在youtubeplayer中设置CC和HQ质量。但我想在youtube中设置高清质量或不同的视频质量(240p,360p,480p,720p,如果有的话)。 It is said here that we can set video quality by calling setPlaybackQuality function but i could find it.

任何建议都将不胜感激。感谢。

0 个答案:

没有答案