- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Android YouTube API 示例在我的应用中创建无边框 YouTube 播放器。我遇到一个问题,即缓冲/加载进度条继续显示在我的视频上,即使它已加载并开始播放。我可以通过一些小的修改在 FragmentDemoActivity
示例中重现它:
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
没有触发错误。
视频缓冲后开始播放。播放器是无 Chrome 的。然而,缓冲微调器永远不会消失。这是一个错误,还是我在做我不允许做的事情?
最佳答案
我也遇到了,确实是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
的位置已更改,请分享以便我可以编辑我的答案,谢谢!
关于android - YouTube 安卓 API : YouTubePlayerFragment loading spinner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35270668/
我正在使用 YoutubePlayerFragment 类来播放视频。我想添加一个 GestureListener,但他们没有设置手势检测器的方法。我试过:
我想在带有 backstack 的 Activity 中使用 YouTubePlayerFragment。因此,当我按下后退按钮时, fragment 会消失,并且在以后的某些操作中(例如单击按钮)会
我正在尝试使用YouTube API在viewpager中播放YouTube视频。我的片段由一个FrameLayout组成,在其中播放视频。该视频正在加载,但是在我播放后立即停止。 错误日志显示为:
编辑 cjohn捕获了缺失的一 block 。我忘记在 YTPlayerFragment 上调用 init()。 Android 开发新手。我试图将 YouTube 视频放入 YouTubePlaye
我有一个 RecyclerView,里面有 CardView。我希望每个 CardView 都有自己的 YouTubePlayerFragment。即使它们不能同时全部激活,我什至无法在任何 Card
我试图在方向改变时继续播放 YouTubePlayerFragment。 代码如下所示: @Override public View onCreateView(LayoutInflater infla
我正在尝试在 Youtube 应用程序中复制视频最小化,如图所示 here .为了实现这一点,我尝试使用 Draggable Panel图书馆。当我运行示例时,我注意到视频在播放过程中最小化时不会缩放
我希望将 YouTubePlayerFragment 覆盖在我的自定义视频 ListView 上,但收到错误 [应用程序不幸停止]。这是我的布局文件: Activit
Activity 的相关部分: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(
我正在处理 YouTubePlayerFragment 集成。在 YouTubePlayerFragment 中初始化 YouTubePlayer 时,它从另一个应用程序获取音频,并且该特定应用程序停
我正在使用 Youtube API 在我的 Android 应用程序中播放 Youtube 视频。它在较新的手机上运行良好,但当我尝试在运行 Gingerbread 的设备上运行时,出现错误: Una
我想要一个包含 2 或 3 个 YouTube 视频的小 View ,嵌入在更宽的布局中(仅限平板电脑)。用户应该能够在视频之间切换(同时保持在同一个 Activity/屏幕上)。是否可以使用 You
当我播放某些视频时出现错误,显示“此视频包含来自 wmg 的内容。在某些网站上播放受到限制” 有人知道在我的播放器中播放这个视频吗? 提前致谢 最佳答案 它说: 此视频包含来自 WMG 的内容。它在某
我想在水平 ScrollView 中显示多个 YouTube 视频。为此,我正在动态添加 YouTubePlayerFragments。这是我的代码 fragment : //set videos
YouTubePlayerFragment 在 CollapsingToolbarLayout 中不工作(播放)。 我想从 youtube android api 播放 youtube 视频。在 Co
我正在使用 Android YouTube API 示例在我的应用中创建无边框 YouTube 播放器。我遇到一个问题,即缓冲/加载进度条继续显示在我的视频上,即使它已加载并开始播放。我可以通过一些小
我正在开发一个安卓应用程序。在此应用程序中,我希望使用 AppCompatActivity 在 ListView 或 RecyclerView 中使用 youtube 播放器播放 youtube 视频
我正在使用 Android YouTube API 示例在我的应用中创建无边框 YouTube 播放器。我遇到一个问题,即缓冲/加载进度条继续显示在我的视频上,即使它已加载并开始播放。我可以通过一些小
我正在尝试在我的 Fragment 中播放视频。但是,我无法让它工作。如果我扩展“YoutubeFailureRecovery”,我会得到: 09-06 21:56:40.472: E/Android
我在我的android项目中实现TouTube Api。我在YouTubePlayerFragment之前的“as”下一行出现错误,“此转换无法成功”。我正在用片段初始化youtube播放器。我已经在
我是一名优秀的程序员,十分优秀!