VideoView plays ok, but not visible when swapping fullscreen views

ⅰ亾dé卋堺 提交于 2019-12-24 10:37:28

问题


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.


回答1:


I've just used ProgressDialog.show() instead of flipping views, it is a lot simpler and VideoView handles it right.



来源:https://stackoverflow.com/questions/3788497/videoview-plays-ok-but-not-visible-when-swapping-fullscreen-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!