问题描述
我有一些AsyncTask
可以将视频流加载到播放器中,因此我想在执行过程中显示一些加载"屏幕.目前,我的onCreate
代码如下所示:
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
正确显示,然后将内容更改为playerView
时,屏幕变黑,但声音在背景中正常播放.
loadingView
is displayed properly, then when changing content to playerView
, screen goes black, but sound plays properly in background.
我从MediaPlayer的日志中收到了这两个警告:
I get these two warnings from MediaPlayer in the logs:
info/warning (1, 35)
info/warning (1, 44)
我尝试使用ViewSwither
并在onPostExecute
内调用showNextView
,但是行为类似,更改为videoView
时出现黑屏.
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.
当我在此活动中仅使用单个VideoView
时,它可以完美运行并同时显示图像和声音.
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>
此问题似乎有点相似,但将loadingView
可见性切换为INVISIBLE
不适用于我的情况.
this question seems a little bit similar, but switching loadingView
visibility to INVISIBLE
does not work in my case.
推荐答案
我只是使用ProgressDialog.show()
而不是翻转视图,这要简单得多,并且VideoView
可以正确处理它.
I've just used ProgressDialog.show()
instead of flipping views, it is a lot simpler and VideoView
handles it right.
这篇关于VideoView可以正常播放,但在交换全屏视图时不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!