公共类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 Player APi中的初始加载时间很长。有没有办法降低视频质量取决于设备???
答案 0 :(得分:-1)
等等我在API提供的文档中发现了一些内容。看看
/docs/reference/com/google/android/youtube/player/YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)
或仅YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)
似乎有你需要覆盖的回调。
似乎有PlayBackEventListener
为您提供了您正在寻找的onBuffering
。