VideoView 播放正常,但在交换全屏视图时不可见
我有一些 AsyncTask
将视频流加载到播放器中,因此我想在执行时显示一些加载屏幕。目前我的onCreate代码如下所示:
final View loadingView = getLayoutInflater().inflate(R.layout.video_loading, null);
final View playerView = getLayoutInflater().inflate(R.layout.player, null);
final VideoView videoView = (VideoView) playerView.findViewById(R.id.canvas);
Log.d(TAG, "Running video player for video " + videoId);
new VideoPlayingTask(this, videoView.getHolder()) {
protected void onPreExecute() {
setContentView(loadingView);
super.onPreExecute(); // it creates or re-uses (resetting it before)
// MediaPlayer instance inside and sets display using setDisplay to the passed holder
};
protected void onPostExecute(FileInputStream dataSource) {
setContentView(playerView);
videoView.requestFocus();
super.onPostExecute(dataSource); // it sets data source,
// prepares player and starts it
};
}.execute(videoId);
loadingView正确显示,然后将内容更改为playerView时,屏幕变黑,但声音正常播放背景。
我在日志中从 MediaPlayer 收到这两个警告:
info/warning (1, 35)
info/warning (1, 44)
我尝试使用 ViewSwither
并在 onPostExecute
内调用 showNextView
,但行为是类似,更改为 videoView
时黑屏。
我已经尝试过将两个内部布局放置在当前内部并手动切换其可见性的方式,这对我也没有帮助。
当我在此活动中仅使用单个 VideoView
时,它可以完美运行并显示图像和声音。
video_loading.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar android:layout_width="@dimen/small_progress_side"
android:layout_height="@dimen/small_progress_side" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/caching_video" />
</LinearLayout>
player.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="@+id/canvas"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
这个问题似乎有点相似,但是将 loadingView
可见性切换为 INVISIBLE
在我的情况下不起作用。
I have some AsyncTask
that loads a video stream into the player, so I want to show some Loading screen while it performs. Currently my onCreate
code looks like this:
final View loadingView = getLayoutInflater().inflate(R.layout.video_loading, null);
final View playerView = getLayoutInflater().inflate(R.layout.player, null);
final VideoView videoView = (VideoView) playerView.findViewById(R.id.canvas);
Log.d(TAG, "Running video player for video " + videoId);
new VideoPlayingTask(this, videoView.getHolder()) {
protected void onPreExecute() {
setContentView(loadingView);
super.onPreExecute(); // it creates or re-uses (resetting it before)
// MediaPlayer instance inside and sets display using setDisplay to the passed holder
};
protected void onPostExecute(FileInputStream dataSource) {
setContentView(playerView);
videoView.requestFocus();
super.onPostExecute(dataSource); // it sets data source,
// prepares player and starts it
};
}.execute(videoId);
loadingView
is displayed properly, then when changing content to playerView
, screen goes black, but sound plays properly in background.
I get these two warnings from MediaPlayer in the logs:
info/warning (1, 35)
info/warning (1, 44)
I've tried to use ViewSwither
and to call showNextView
inside onPostExecute
, but the behavior was similar, black screen when changing to videoView
.
I've tried the way with two inner layouts laying inside current and switch their visibility manually, and this also not helped to me.
When I use just single VideoView
in this activity, it works perfectly and shows both image and sound.
video_loading.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar android:layout_width="@dimen/small_progress_side"
android:layout_height="@dimen/small_progress_side" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/caching_video" />
</LinearLayout>
player.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="@+id/canvas"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
this question seems a little bit similar, but switching loadingView
visibility to INVISIBLE
does not work in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚使用了
ProgressDialog.show()
而不是翻转视图,它要简单得多,并且VideoView
可以正确处理它。I've just used
ProgressDialog.show()
instead of flipping views, it is a lot simpler andVideoView
handles it right.