我们可以在Android中使用API禁用Youtube视频播放中的缓冲吗?



公共类VideoDialog扩展YouTubeFailureRecoveryActivity {

    List<String> playlist;
    AlertDialog dialog;
    YouTubePlayer player;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        requestWindowFeature(Window.FEATURE_PROGRESS);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        Bundle bundle = getIntent().getExtras();
        playlist=new ArrayList<String>();
        playlist=bundle.getStringArrayList("VIDEO_LINK");
        if(!playlist.isEmpty())
        {
            dialog = new AlertDialog.Builder(this).create();
            LayoutInflater inflater = LayoutInflater.from(this);
            dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
            View view = inflater.inflate(R.layout.exvideo_lauout, null); // xml Layout file for imageView
            Button btnCloseimg=(Button)view.findViewById(R.id.eximageclose);
            btnCloseimg.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    if(player.isPlaying())
                    {
                        player.release();
                    }
                    playlist.clear();
                    playlist=null;
                    finish();


                }
            });
            YouTubePlayerView youTubeView = (YouTubePlayerView)view. findViewById(R.id.youtube_view);
            youTubeView.initialize(DEVELOPER_KEY,this);

            dialog.setView(view);
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT-150;
            dialog.show();
            dialog.setCanceledOnTouchOutside(false);
            dialog.getWindow().setAttributes(lp);
        }
        else
        {
            Toast.makeText(this,"Error in URL..",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
    public void onBackPressed()
    {
        super.onBackPressed();
        if(player.isPlaying())
        {
            player.release();
        }
        playlist.clear();
        playlist=null;
        finish();
    }
    public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer player,boolean wasRestored) {
        if (!wasRestored) 
        {
            this.player=player;
            player.loadVideos(playlist);
            player.setPlayerStyle(PlayerStyle.CHROMELESS);
            player.play();

            player.setPlayerStateChangeListener(new PlayerStateChangeListener() {
                public void onVideoStarted() {
                    // TODO Auto-generated method stub
                }
                public void onVideoEnded() {
                    // TODO Auto-generated method stub
                    if(!player.hasNext())
                    {
                        //player.cueVideos(playlist);
                        player.loadVideos(playlist);
                        player.play();
                    }
                    else
                    {
                        player.play();
                    }

                }
                public void onLoading() {
                    // TODO Auto-generated method stub
                }
                public void onLoaded(String arg0) {
                    // TODO Auto-generated method stub
                }
                public void onError(ErrorReason arg0) {
                    // TODO Auto-generated method stub
            Toast.makeText(VideoDialog.this,"Loading Error!!",Toast.LENGTH_SHORT).show();
                }
                public void onAdStarted() {
                    // TODO Auto-generated method stub

                }
            });
        }
    }

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

}

我们需要在android应用程序中播放多个视频而没有任何延迟,但youtube播放器APi的初始加载时间很高。有没有办法降低视频质量取决于设备??

等一下,我在API提供的文档中找到了一些东西。查看

/docs/reference/com/google/android/youtube/player/YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)

或者仅仅是YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)

似乎有你需要重写的回调。

似乎有一个PlayBackEventListener为您提供您正在寻找的onBuffering

相关内容

  • 没有找到相关文章

最新更新