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.