
public class FragmentDemoActivity extends AppCompatActivity implements YouTubePlayer.OnInitializedListener { @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.fragments_demo); YouTubePlayerFragment youTubePlayerFragment = (YouTubePlayerFragment) getFragmentManager().findFragmentByID(R.ID.youtube_fragment); youTubePlayerFragment.initialize(DeveloperKey.DEVELOPER_KEY,this); } @OverrIDe public voID onInitializationSuccess(YouTubePlayer.ProvIDer provIDer,YouTubePlayer player,boolean wasRestored) { if (!wasRestored) { player.setPlayerStyle(YouTubePlayer.PlayerStyle.chromeless); player.loadVIDeo("nCgQDjiotG0",10); } } @OverrIDe public voID onInitializationFailure(YouTubePlayer.ProvIDer provIDer,YouTubeInitializationResult youTubeInitializationResult) {}} 我已经将FragmentDemoActivity改为继承AppCompatActivity而不是YouTubeFailureRecoveryActivity,因为文档说这很好.我还在onInitializationSuccess中将播放器样式更改为无边框.最后,我已将cueVIDeo更改为loadVIDeo,只是为了触发自动播放.
这种情况发生在包括Nexus 5X在内的多种设备上.我正在使用库版本1.2.2. onInitializationFailure中未触发任何错误.
视频在缓冲后开始播放.该播放器是无铬的.然而,缓冲旋转器永远不会消失.这是一个错误,还是我在做一些我不允许做的事情?
解决方法 我也遇到了这个,它看起来真的像个BUG.以下是我设法解决它的方法.在onInitializationSuccess中,在播放器上设置PlaybackEventListener.覆盖onBuffering并执行以下 *** 作:
VIEwGroup ytVIEw = (VIEwGroup)ytplayerFragment.getVIEw();Progressbar progressbar;try { // As of 2016-02-16,the Progressbar is at position 0 -> 3 -> 2 in the vIEw tree of the Youtube Player Fragment VIEwGroup child1 = (VIEwGroup)ytVIEw.getChildAt(0); VIEwGroup child2 = (VIEwGroup)child1.getChildAt(3); progressbar = (Progressbar)child2.getChildAt(2);} catch (Throwable t) { // As its position may change,we fallback to looking for it progressbar = findProgressbar(ytVIEw); // Todo I recommend reporting this problem so that you can update the code in the try branch: direct access is more efficIEnt than searching for it}int visibility = isBuffering ? VIEw.VISIBLE : VIEw.INVISIBLE;if (progressbar != null) { progressbar.setVisibility(visibility); // Note that you Could store the Progressbar instance somewhere from here,and use that later instead of accessing it again.} findProgressbar方法,在YouTube代码更改时用作后备:
private Progressbar findProgressbar(VIEw vIEw) { if (vIEw instanceof Progressbar) { return (Progressbar)vIEw; } else if (vIEw instanceof VIEwGroup) { VIEwGroup vIEwGroup = (VIEwGroup)vIEw; for (int i = 0; i < vIEwGroup.getChildCount(); i++) { Progressbar res = findProgressbar(vIEwGroup.getChildAt(i)); if (res != null) return res; } } return null;} 这个解决方案对我来说非常好,在播放器缓冲时启用Progressbar,而在播放器缓冲时启用它.
编辑:如果使用此解决方案的任何人发现此错误已修复或Progressbar的位置已更改,请分享,以便我可以编辑我的答案,谢谢!
总结以上是内存溢出为你收集整理的YouTube Android API:YouTubePlayerFragment加载微调器全部内容,希望文章能够帮你解决YouTube Android API:YouTubePlayerFragment加载微调器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)