我有一些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
and 调用showNextView
inside onPostExecute
,但行为相似,更改为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
不起作用。