VideoView plays normally but does not appear when switching full-screen views

I have AsyncTaskone that downloads the video stream to the player, so I want to show the loading screen during its execution. Currently my code is onCreateas follows:

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);

loadingViewis displayed correctly, and then when the content changes to the playerViewscreen, it turns black, but the sound plays correctly in the background.

I get these two warnings from MediaPlayer in the logs:

info/warning (1, 35)
info/warning (1, 44)

I tried to use ViewSwitherand call showNextViewinside onPostExecute, but the behavior was similar, the black screen when changing to videoView.

I tried the path with two internal mockups lying inside the current and switched their visibility manually, and that also did not help me.

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 .

+1
1

ProgressDialog.show() , , VideoView .

0

Source: https://habr.com/ru/post/1764097/


All Articles