ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Support setting SimpleExoPlayerView background/shutter color

Open or-dvir opened this issue 9 years ago • 6 comments

- Search existing issues, including issues that are closed. i only found this thread: https://github.com/google/ExoPlayer/issues/2821 but the question there is regarding surface view, and not exoPlayer components. **- Consult our FAQs, supported devices and supported formats pages. did not find my answer there

Issue description

i would like to change the background of SimpleExoPlayerView. right now, while the video is loading for the first time (meaning not buffering in the middle of streaming) the background is black. i would like to change it to white. using android:background in xml or exoPlayerView.setBackground() in code does not work. changing the foreground does change the color, but it also blocks (or hides) all the other UI element, including the video.

Reproduction steps

play any video that takes time to initially load

Version of ExoPlayer being used

2.5.1

Device(s) and version(s) of Android being used

LG G3 API 23. LG K10 API 23. Uniden prime C471 API 18.

in the layout file exo_simple_player_view.xml, which is found here: https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/res/layout/exo_simple_player_view.xml there is a view with id "exo_shutter" which has a black background - im assuming this is the cause of my problem? some might say to just do this (pseudo code):

int resId = getResources().getIdentifier("exo_shutter", "id", getPackageName());
findViewById(resId).setBackground(Color.white);

but it is not good practice to relay of inner id's like that... if they change in a future version i will get null pointer exception. unless, can you guarantee that this will not be changed in the future and is safe to do?

or-dvir avatar Aug 15 '17 08:08 or-dvir

Yes, the shutter is the problem and your suggested approach of relying on exo_shutter will work for now. It is actually a documented id (see here), so it's not quite has hacky as you might think, although I agree it's definitely not ideal.

Question: Are you attempting to change the color only when the shutter is visible (e.g. when there's no video playing at all), or do you also want to change the color of any letter-boxing bars around the video during playback?

ojw28 avatar Aug 16 '17 08:08 ojw28

thanks! that link you provided pretty much answers my question. at least i think it does... before i try it i want to make sure i understood correctly. right now i am overriding the controllers and i made a file called exo_playback_control_view.xml, and that file is the entire layout that is being inflated as my video controllers. if i understood correctly from the docs you sent (please correct me if im wrong) i need to create a file called exo_simple_player_view.xml and inside it create a single view with id exo_shutter and then simply change its' background to whatever color i want. please keep in mind that i only want to change this shutter view, and keep everything else as the default (exo_content_frame, exo_subtitles, exo_artwork etc). unlike the controllers layout file which is inflated in it's entirety, exoPlayer looks for specific id's inside exo_simple_player_view.xml and if they are not found then it goes to a default implementation? is this correct?

as for your question, in my specific use case i am not using letter-boxing (that is until management will change their minds) so i was only referring to the first case "when the shutter is visible". however coloring the letter-boxing is a good idea in my opinion - the more control i have as a developer the better :)

or-dvir avatar Aug 16 '17 10:08 or-dvir

Overriding exo_simple_player_view.xml is similar to overriding exo_playback_control_view.xml (you need to provide the entire layout in both cases). Both are described in this blog post (although note that some of the information may be a little out of date, since the library has evolved a little since then).

This is marked as an enhancement because we should just provide a way to programmatically change the shutter color, and we'll do that at some point. Until then, your original approach of changing it programmatically using the view ID is probably the simplest thing you can do.

ojw28 avatar Aug 16 '17 12:08 ojw28

thanks a lot for your help. i did it and it worked

or-dvir avatar Aug 17 '17 07:08 or-dvir

Additional change: e92667ba5b58cbda9695c8168d3f8fa810da8288

ojw28 avatar Nov 13 '17 17:11 ojw28

Hello, I'm not sure if I should create new issue for this ( I've created issue #3741 ) but setting SimpleExoPlayerView.setShutterBackgroundColor(Color.TRANSPARENT) seems that doesn't work on couple Samsung devices. I found that on Samsung Galaxy S7 Edge (SM-G935F) Android 7, Samsung Galaxy J5 (Android 6) when preparing player (changing source) shutter is black although should be transparent and make last viewing frame vissible. It's working fine on other Android 6, 7, 8 devices/emulators. (Huawei P9 Lite Android 6, Xiaomi mi 4 Android 7.1)

I tried also customizing ui components

This happens with 2.6.0 ExoPlayer.

hare989 avatar Jan 19 '18 15:01 hare989