Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in some device when changing orientation black screen #7155

Closed
447zyg opened this issue Mar 28, 2020 · 8 comments
Closed

in some device when changing orientation black screen #7155

447zyg opened this issue Mar 28, 2020 · 8 comments
Assignees
Labels

Comments

@447zyg
Copy link

447zyg commented Mar 28, 2020

androidx project

implementation 'com.google.android.exoplayer:exoplayer:2.11.3'
pre version also have this problem
in v2.9.6 is not black screen. but screen is stuck
but voice is continue it's no problem

activity code

public class MainActivity extends Activity {

private PlayerView video_view;

private ViewGroup video_container;

private Button full, start;

private SimpleExoPlayer player;

private String videoUrl = "https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv";

private Activity self() {
    return MainActivity.this;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    video_container = findViewById(R.id.video_container);

    video_view = findViewById(R.id.video_view);
    start = findViewById(R.id.start);
    full = findViewById(R.id.full);


    player = new SimpleExoPlayer.Builder(self()).build();
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(self(), Util.getUserAgent(self(), ""));
    final MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).
            createMediaSource(Uri.parse(videoUrl));

    video_view.setPlayer(player);

    start.setOnClickListener(view -> player.prepare(videoSource));

    full.setOnClickListener(view -> {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        if (video_view.getParent() instanceof ViewGroup) {
            ((ViewGroup) video_view.getParent()).removeView(video_view);
            ViewGroup.LayoutParams layout = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            ViewGroup group = findViewById(android.R.id.content);
            group.addView(video_view, layout);
        }
    });

}


@Override
public void onBackPressed() {
    if (isLand(self())) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        getWindow().getDecorView().setSystemUiVisibility(0);
        if (video_view.getParent() instanceof ViewGroup) {
            ((ViewGroup) video_view.getParent()).removeView(video_view);
            ViewGroup.LayoutParams layout = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            video_container.addView(video_view, layout);
        }
    }
}

public static boolean isLand(@NonNull Context activity) {
    Resources resources = activity.getResources();
    assert resources != null;
    Configuration configuration = resources.getConfiguration();
    Assertions.checkState(configuration != null);
    return resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}

}

layout

<FrameLayout
    android:id="@+id/video_container"
    android:layout_width="match_parent"
    android:layout_height="211dp">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/video_view"
        app:surface_type="surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

<Button
    android:id="@+id/full"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="full" />

<Button
    android:id="@+id/start"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="start" />

i set the activity
android:configChanges="keyboardHidden|orientation|screenSize"
in AndroidManifest

in Meizu PRO7-s. it's MT cpu

in most of device it's work well

sss

app:surface_type="texture_view"
app:surface_type="surface_view"

same problem

@ojw28
Copy link
Contributor

ojw28 commented Mar 28, 2020

Try using

android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"

If that doesn't help, please share a complete project that reproduces the issue (e.g., via GitHub), rather than pasting individual files into an issue. It's much more efficient for us to take a look that way, and also ensures we're doing the same thing as your project.

@447zyg
Copy link
Author

447zyg commented Mar 30, 2020

@ojw28 Sorry for not replying in time
Try using

android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"

it's no work also

this is complete project url

https://github.com/447zyg/exo_test

thanks

@ojw28
Copy link
Contributor

ojw28 commented Mar 30, 2020

The surface to which the video is being rendered is destroyed and recreated by the way you switch to fullscreen. This happens because you remove the PlayerView from the layout and re-add it.

When this happens, you run into the platform limitation that's discussed quite extensively in #677, meaning that the transition is only smooth if the device supports DummySurface, which not all devices do.

It's a bit awkward, and is more difficult the more complicated your UI is, but you can fix this across all devices by making sure the SurfaceView (or equivalently, PlayerView) is always part of the view hierarchy. In your simple activity, you can achieve this by changing the code that removes the PlayerView's parent and re-adds the PlayerView, to instead hide the two buttons and adjust the PlayerView's bounds to entirely fill its parent. Hence you avoid having to remove the PlayerView at any point.

@447zyg
Copy link
Author

447zyg commented Mar 31, 2020

@ojw28
ok i know thanks
but youtube app in this device fullscreen is no problem
it's strange

@ojw28
Copy link
Contributor

ojw28 commented Mar 31, 2020

I'm pretty sure YouTube avoid detaching the view from the hierarchy, as I've described.

@Taranlayal10
Copy link

I am facing this issue with switchTargetView also. Is there any way to add dummy surface while rotation to stop black screen

@ojw28
Copy link
Contributor

ojw28 commented Apr 5, 2020

DummySurface is already used on devices that support it. It relies on APIs that do not exist on older devices, and are unreliable on some slightly newer devices, and therefore it's not possible to use it on every device.

@ghost
Copy link

ghost commented May 12, 2020

I am also facing this issue on manually rotating the screen

@google google locked and limited conversation to collaborators Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants