哪个文件在android youtube播放器中呈现和播放

时间:2014-02-18 07:16:09

标签: android android-youtube-api

我已成功整合YouTube Android Player API我的应用。我很想知道播放器中呈现的文件。每个视频文件可能有多种格式,如320dpi,720dpi&等。

如果我的用户,带宽较低;我可以选择文件格式,或者API自动检测在那种情况下将播放哪个版本,反之亦然。我的代码:

  public class YoutubeVideoActivity extends YouTubeBaseActivity implements
        YouTubePlayer.OnInitializedListener, YouTubePlayer.OnFullscreenListener {

    Activity activity = YoutubeVideoActivity.this;

    public static final String API_KEY = "AIzaSyDN6Q9Pv4seQZqIcjB*********Po5k";
    // public static final String VIDEO_ID = "psY0Botpi84";

    public String new_id;
    private boolean fullscreen;
    private YouTubePlayerView playerView;

    @Override
    protected void onCreate(Bundle arg0) {

        super.onCreate(arg0);
        // Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_youtube_video);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        Intent intent = getIntent();
        String video_link = intent.getExtras().getString("video_link");

        try {
            new_id = video_link.substring("http://www.youtube.com/watch?v="
                    .length());
            if (new_id.equals("")) {
                IndepententTVUtils.showCustomAlert(activity,
                        "Data is not availble. Press back key",
                        R.drawable.ic_new_launcher);
            } else {
                playerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
                playerView.initialize(API_KEY, this);
            }

        } catch (Exception e) {

            IndepententTVUtils.showCustomAlert(activity,
                    "Data is not availble", R.drawable.ic_new_launcher);
        }

    }

    @Override
    public void onInitializationFailure(Provider arg0,
            YouTubeInitializationResult arg1) {

        Toast.makeText(getApplicationContext(),
                "To See this Video, Install Latest YouTube Application",
                Toast.LENGTH_LONG).show();

    }

    @Override
    public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
            boolean wasRestored) {

        player.setOnFullscreenListener(this);

        if (!wasRestored && new_id != null) {

            player.cueVideo(new_id);

        }

    }

    @Override
    public void onFullscreen(boolean isFullscreen) {

        fullscreen = isFullscreen;

    }

}

1 个答案:

答案 0 :(得分:1)

播放器根据用户带宽或互联网速度自动设置视频质量,如果不是这样,则会在播放器中指定setPlaybackQuality。 只有限制选项才能更改播放器设置 here