You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS and COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS does not trigger related handlers in SimpleBasePlayer when using Media3 1.1.0 #554
With Media3 1.0.0, we could handle cast device volume by implementing COMMAND_GET_DEVICE_VOLUME, COMMAND_SET_DEVICE_VOLUME and COMMAND_ADJUST_DEVICE_VOLUME commands in SimpleBasePlayer. We used cast API to get/set device volume. For implementation, see this and this. Here, RemoteDeviceVolumeProvider is a simple abstraction that deals with the cast API. As a result, we could adjust the cast device volume using volume rockers during an active cast session.
With Media3 1.1.0, the latter two commands are now deprecated in favour of COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS and COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS. However, when we replaced the deprecated commands with the new ones in our existing implementation, the SimpleBasePlayer stopped invoking handleSetDeviceVolume and other related handlers. As a result, nothing happens on pressing volume rockers during a cast playback session.
But if we continue using the deprecated commands, everything works as expected.
Is it a bug or an intended change? More importantly, how do we continue to use volume rockers to adjust cast device volume when the cast session is active while incorporating the latest changes?
@oceanjules Hi there! Yes, I did implement the updated handlers (with flags). Moreover, the updated handlers appear to be working with deprecated commands but not with their replacements. Let me try to reproduce this in a minimal setting.
@oceanjulesHere's a minimal Android project demonstrating this issue. If you uncomment these lines, you see log entries for the handlers in question on running the app and pressing volume rockers on the device. But handlers don't get invoked on commenting out the deprecated commands.
Having tried your minimal example, I can only see this through logcat:
MediaSessionRecord system_server D No routing session for com.example.myapplication
MediaSessionService system_server D Adjusting suggestedStream=-2147483648 by 0. flags=4116, preferSuggestedStream=false, session=null
which comes from the MediaSessionRecord's "canHandleVolumeKey". I guess because isPlaybackTypeLocal() is false.
So I think all these key events are not going through Exoplayer at all, which is why I am not sure how you managed to get those log statement in the handlers working with the provided minimal setup.
I am not getting any entries with the MediaSessionRecord tag. Now I am not aware of how the internals work in the framework, but I think this should add some clarity.
Thank you for providing the Android version, that was the key piece of information that helped me reproduce it.
I have found the issue and we will be patching up a bugfix for it. For reference, these if-statements, should have had the new commands as well. Otherwise, the volumeControlType was set as FIXED, i.e. not changeable
Also for reference, the reason it didn't work for me was because I was testing with Android 12 and 13 and it's a known issue that the hardware buttons and volume of a cast device are currently not working:
Activity
oceanjules commentedon Aug 1, 2023
Hi @ashutoshgngwr,
Could you confirm that you are now overriding the handler that has the following signature:
media/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java
Lines 3060 to 3062 in 5328d64
You can see that this is the handler that is triggered in both the new and deprecated methods in lines 2725 and 2738:
media/libraries/common/src/main/java/androidx/media3/common/SimpleBasePlayer.java
Lines 2716 to 2740 in 5328d64
ashutoshgngwr commentedon Aug 1, 2023
@oceanjules Hi there! Yes, I did implement the updated handlers (with flags). Moreover, the updated handlers appear to be working with deprecated commands but not with their replacements. Let me try to reproduce this in a minimal setting.
ashutoshgngwr commentedon Aug 1, 2023
@oceanjules Here's a minimal Android project demonstrating this issue. If you uncomment these lines, you see log entries for the handlers in question on running the app and pressing volume rockers on the device. But handlers don't get invoked on commenting out the deprecated commands.
oceanjules commentedon Aug 1, 2023
We also have a test that should check this behaviour (that also currently works) which you can use as a template for your minimal example:
media/libraries/common/src/test/java/androidx/media3/common/SimpleBasePlayerTest.java
Lines 3183 to 3218 in 5328d64
ashutoshgngwr commentedon Aug 1, 2023
Couldn't that imply that the problem might be somewhere else?
Why?
oceanjules commentedon Aug 6, 2023
Having tried your minimal example, I can only see this through logcat:
which comes from the MediaSessionRecord's "canHandleVolumeKey". I guess because isPlaybackTypeLocal() is false.
Setting the device info type to Local, gives us:
So I think all these key events are not going through Exoplayer at all, which is why I am not sure how you managed to get those log statement in the handlers working with the provided minimal setup.
ashutoshgngwr commentedon Aug 7, 2023
I am getting the following logs when running my example on an Android 11 (actual device) with the remote device type.
If I replace
*_WITH_FLAGScommands with their deprecated counterparts, I am getting the following.I am not getting any entries with the
MediaSessionRecordtag. Now I am not aware of how the internals work in the framework, but I think this should add some clarity.oceanjules commentedon Aug 7, 2023
Hi @ashutoshgngwr,
Thank you for providing the Android version, that was the key piece of information that helped me reproduce it.
I have found the issue and we will be patching up a bugfix for it. For reference, these if-statements, should have had the new commands as well. Otherwise, the volumeControlType was set as FIXED, i.e. not changeable
media/libraries/session/src/main/java/androidx/media3/session/PlayerWrapper.java
Lines 1032 to 1037 in 5328d64
Also for reference, the reason it didn't work for me was because I was testing with Android 12 and 13 and it's a known issue that the hardware buttons and volume of a cast device are currently not working:
https://issuetracker.google.com/issues/201546605
Fix `PlayerWrapper`'s creation of `VolumeProviderCompat`
Fix `PlayerWrapper`'s creation of `VolumeProviderCompat`
Fix `PlayerWrapper`'s creation of `VolumeProviderCompat`