TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

[BUG]: `muted` not working on Android 12/13 for Samsung and Pixel devices #4162

Open eweseongyeoh opened 1 month ago

eweseongyeoh commented 1 month ago

Version

6.5.0

What platforms are you having the problem on?

Android

System Version

Android 13

On what device are you experiencing the issue?

Real device

Architecture

Old architecture

What happened?

muted video still play audio when loaded on Samsung/Pixel devices with Android 12 or 13; please note that we have attempted to load the same video on other devices like Huawei/Xiaomi/oppo with similar Android version and they work fine in them.

we have applied a workaround with selectedAudioTrack={{type: SelectedTrackType.DISABLED}} configuration, it isn't ideal, but it works for us.

Reproduction Link

No response

Reproduction

Step to reproduce this bug are:

  1. Load a muted video on Samsung/Pixel devices with Android 12 or 13
  2. Notice video still play audio when loaded
github-actions[bot] commented 1 month ago

Thank you for your bug report. We will review it and get back to you if we need more information.

github-actions[bot] commented 1 month ago

Thank you for your bug report. We will review it and get back to you if we need more information.

freeboub commented 1 month ago

https://developer.android.com/reference/kotlin/androidx/media3/common/Player#setVolume(float) currently we don't check if volume control is available ... I think you have a correct workaround. media3 volume apis are handling volume on player side and it can be disturbing for end user to have 2 parrallel volume management. I can advise to use something like : https://www.npmjs.com/package/react-native-volume-manager to handle volume of the device, not one the player

freeboub commented 1 month ago

I don't reproduce the issue with emulator. It would be interesting to test following patch to see if the log is displayed !

Tested on emulator Pixel 8 API 31 (Android 12)

diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java
index 0714115e..62055c9d 100644
--- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java
+++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java
@@ -2133,7 +2133,12 @@ public class ReactExoplayerView extends FrameLayout implements
     public void setMutedModifier(boolean muted) {
         this.muted = muted;
         if (player != null) {
-            player.setVolume(muted ? 0.f : audioVolume);
+            Player.Commands cmd = player.getAvailableCommands();
+            if (cmd.contains(Player.COMMAND_SET_VOLUME)) {
+                player.setVolume(muted ? 0.f : audioVolume);
+            } else {
+                DebugLog.e(TAG, "player doesn't support volume management");
+            }
         }
     }