我有一个奇怪的情况。我正在使用 NexPlayer 在 openGL 模式下渲染流媒体视频。在流式视频(框架布局)的渲染区域之上,只要视频播放器正在缓冲,我就会以不确定模式显示 ProgressBar - 与 youtube 应用程序的功能相当。
在播放器停止缓冲并且我尝试从屏幕上移除进度条之前,这一切都很好。进度条停止动画,但它仍保留在屏幕上,就好像它是视频上的水印一样。 我尝试删除它的方法是更改进度条的可见性;我已经尝试过 View.INVISIBLE 和 View.GONE 但都没有用。 我还尝试将进度条包装在另一个布局中并更改该容器的可见性,但无济于事。
我确实注意到,当我旋转设备时,进度条会消失。
下面是播放器 Activity 的 xml 布局。那里的surfaceview仅在设备不支持OpenGL 2.0的情况下使用。
有没有人知道如何摆脱这个 ProgressBar?
提前致谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="@+id/gl_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
</FrameLayout>
<SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true" >
</SurfaceView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/controlContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#aa000000"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ToggleButton
android:id="@+id/buttonPausePlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_play_pause"
android:textOff=""
android:textOn="" />
<ImageButton
android:id="@+id/buttonStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/ic_media_stop" />
</LinearLayout>
<ProgressBar
android:id="@+id/seekbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:indeterminate="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/loadingContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/loading"
style="@android:style/Widget.ProgressBar.Large.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</LinearLayout>
</RelativeLayout>
编辑:更改 View 可见性的代码:
@Override
public void onBuffering(int progress_in_percent) {
Log.d(TAG, "Buffering " + progress_in_percent + " %");
}
@Override
public void onBufferingBegin() {
Log.d(TAG, "Buffering begin");
loadingContainer.setVisibility(View.VISIBLE);
}
@Override
public void onBufferingEnd() {
Log.d(TAG, "Buffering end");
loadingContainer.setVisibility(View.GONE);
}
这些方法是从 NexPlayer 框架内调用的。我确信他们确实会被调用,因为我在日志中得到了输出。
最佳答案
是的,我想通了。我从 NexPlayer 框架获得的回调不在 UI 线程上。奇怪的是,这并没有在日志中导致任何堆栈跟踪,所以我没有注意到这一点,直到我附加了我的调试器并添加了一个在任何异常时暂停的断点。
我通过创建与上面的代码执行完全相同的操作并将它们发布到我的处理程序来解决此问题。
(尽管我仍然不明白为什么 ProgressBar 会出现在第一位,因为它也在错误的线程上可见:/)
关于android - ProgressBar 在 FrameLayout 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7916636/