我们可以禁用使用Android的API中的Youtube视频播放缓冲? [英] can we disable the buffering in Youtube video playing using API in Android?
问题描述
公共类VideoDialog扩展YouTubeFailureRecoveryActivity {
列表<串GT;播放列表;
AlertDialog对话框;
YouTubePlayer球员; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
束束= getIntent()getExtras()。
播放列表=新的ArrayList<串GT;();
播放列表= bundle.getStringArrayList(VIDEO_LINK);
如果(!playlist.isEmpty())
{ 对话框=新AlertDialog.Builder(本).create();
LayoutInflater吹气= LayoutInflater.from(本);
。dialog.getWindow()requestFeature(Window.FEATURE_NO_TITLE);
查看查看= inflater.inflate(R.layout.exvideo_lauout,NULL); //为ImageView的XML布局文件 按钮btnCloseimg =(按钮)view.findViewById(R.id.eximageclose);
btnCloseimg.setOnClickListener(新OnClickListener(){ 公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(player.isPlaying())
{
player.release();
}
playlist.clear();
播放列表= NULL;
完();
}
}); YouTubePlayerView youTubeView =(YouTubePlayerView)视图。 findViewById(R.id.youtube_view);
youTubeView.initialize(Developer_Key开发,这一点); dialog.setView(视图);
WindowManager.LayoutParams LP =新WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow()的getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT-150;
dialog.show();
dialog.setCanceledOnTouchOutside(假);
。dialog.getWindow()setAttributes(LP);
}
其他
{
Toast.makeText(这一点,错误的网址..,Toast.LENGTH_SHORT).show();
} }
@覆盖
保护无效的onDestroy(){
super.onDestroy();
} 公共无效onBack pressed()
{
super.onBack pressed();
如果(player.isPlaying())
{
player.release();
}
playlist.clear();
播放列表= NULL;
完(); } 公共无效onInitializationSuccess(YouTubePlayer.Provider提供商,最终YouTubePlayer球员,布尔wasRestored){
如果(!wasRestored)
{ this.player =玩家;
player.loadVideos(播放);
player.setPlayerStyle(PlayerStyle.CHROMELESS); player.play();
player.setPlayerStateChangeListener(新PlayerStateChangeListener(){ 公共无效onVideoStarted(){
// TODO自动生成方法存根 } 公共无效onVideoEnded(){
// TODO自动生成方法存根 如果(!player.hasNext())
{
//player.cueVideos(playlist);
player.loadVideos(播放);
player.play(); }
其他
{ player.play();
}
} 公共无效onLoading(){
// TODO自动生成方法存根 } 公共无效onLoaded(字符串为arg0){
// TODO自动生成方法存根 } 公共无效onerror的(ErrorReason为arg0){
// TODO自动生成方法存根
Toast.makeText(VideoDialog.this加载错误!,Toast.LENGTH_SHORT).show(); } 公共无效onAdStarted(){
// TODO自动生成方法存根 }
}); }
}
保护YouTubePlayer.Provider getYouTubePlayerProvider(){
返回(YouTubePlayerView)findViewById(R.id.youtube_view);
}}
我们需要扮演一个Android应用程序内的多部影片没有任何延迟,但初始加载时间是高YouTube播放器APi.is有什么办法可以降低视频质量取决于设备???
块引用>解决方案等一下,我发现在设有API的文档的东西。查看
<$p$p><$c$c>/docs/reference/com/google/android/youtube/player/YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)
或只是
YouTubePlayer.PlaybackEventListener.html#onBuffering(布尔)
这似乎有你需要重写回调。
好像有一个
PlayBackEventListener
它为您提供了onBuffering
你正在寻找。public class VideoDialog extends 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); } }
we need to play multiple videos inside an android app without any delay,but initial loading time is high in youtube Player APi.is there any way to reduce video quality depend on device???
解决方案Wait I found something in the docs provided with the API. Look in
/docs/reference/com/google/android/youtube/player/YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)
or just
YouTubePlayer.PlaybackEventListener.html#onBuffering(boolean)
It seems to have the callback that you need to override.
Seems like there's a
PlayBackEventListener
which provides you with theonBuffering
you're looking for.这篇关于我们可以禁用使用Android的API中的Youtube视频播放缓冲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!