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

iOS video intermittently plays muted #11246

Closed
kevgrig opened this issue Dec 7, 2020 · 7 comments
Closed

iOS video intermittently plays muted #11246

kevgrig opened this issue Dec 7, 2020 · 7 comments
Labels

Comments

@kevgrig
Copy link
Contributor

kevgrig commented Dec 7, 2020

🐛 Bug Report

Summary of Issue

We found on at least three different iPhones (varying models) that our app videos intermittently don't play audio through phone speakers even when the phone's volume is 100%. I have an older iPhone SE and I can actually reproduce the issue 100% of the time with the Expo Video example. If I play the same mp4 from Safari on the phone, it works fine. Interestingly, if I plug headphones in, the audio works fine which seems to be similar to issue #9915. More interestingly, if I try to perform a screen recording of the issue, it goes away. This is a critical issue for us because we're a video-based app so we are willing to help and run any diagnostics you would like!

Environment - output of expo diagnostics & the platform(s) you're targeting

$ expo diagnostics

  Expo CLI 4.0.8 environment info:
    System:
      OS: Linux 5.9 Fedora 33 (Workstation Edition) 33 (Workstation Edition)
      Shell: 5.0.17 - /bin/bash
    Binaries:
      Node: 14.14.0 - /usr/bin/node
      Yarn: 1.22.10 - /usr/bin/yarn
      npm: 6.14.8 - /usr/bin/npm
    npmPackages:
      expo: ~39.0.2 => 39.0.5
      react: 16.13.1 => 16.13.1
      react-dom: 16.13.1 => 16.13.1
      react-native: https://github.com/expo/react-native/archive/sdk-39.0.4.tar.gz => 0.63.2
      react-native-web: ~0.13.12 => 0.13.18
    npmGlobalPackages:
      expo-cli: 3.27.4
    Expo Workflow: managed

Bug on iPhone SE with iOS 14.2 (for example). Works fine on Android.

Reproducible Demo

  • Snack: https://snack.expo.io/@git/github.com/kevgrig/expovideomuted
  • Source: https://github.com/kevgrig/expovideomuted
  • App.js:
    import React from 'react';
    import { View } from 'react-native';
    import { Video } from 'expo-av';
    
    export default function App() {
      return (
        <View style={{ flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center' }}>
          <Video
            source={{ uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4' }}
            rate={1.0}
            volume={1.0}
            isMuted={false}
            resizeMode="cover"
            shouldPlay={true}
            isLooping={true}
            style={{ width: 300, height: 300 }}
            useNativeControls={true}
          />
        </View>
      );
    }
    

Steps to Reproduce

  1. Ensure phone volume is 100% and output is set to the phone's speakers (not earphones, earbuds, etc.)
  2. Open https://snack.expo.io/@git/github.com/kevgrig/expovideomuted
  3. Audio doesn't work

Very interestingly, I tried to record a video of my iPhone screen and when I do this, the issue goes away. As soon as I turn off screen recording and try again, the issue comes back.

Expected Behavior vs Actual Behavior

Expect that the mp4 plays audio out of the phone speaker but observe that it doesn't.

Log

I connected XCode to the device, launched the Console, reproduced the problem, and exported the log: https://raw.githubusercontent.com/kevgrig/expovideomuted/master/diagnostics/console.txt

Based on my viewing of the Console, the video loads and starts playing at approximately 18:51:15. I believe the process ID of the Expo app is 445.

@kevgrig
Copy link
Contributor Author

kevgrig commented Dec 7, 2020

I'm just guessing but maybe some of these messages from the console log might be related?

  1. 18:51:18.771078-0800 mediaserverd 34: 0x5368 com.apple.coremedia default <<<< CENTRAL >>>> playercentral_establishIfPlayerIsSilentAndTellMXSession: [0x105b2e050] <private> Established that player is 'Muted' (by HasEnabledAudio == false)
  2. 18:51:18.773474-0800 mediaserverd 34: 0x5385 com.apple.coreaudio debug AudioSession_SubServer.cpp:638:AudioSessionInfoAccessor: <--- Invalid opaque ID: 0xffffffff

@kevgrig
Copy link
Contributor Author

kevgrig commented Dec 7, 2020

Also see this:

  1. 18:51:18.846118-0800 mediaserverd 34: 0x5363 default Task <DC638B1B-FD21-485E-BE9D-BC5451A98051>.<9> finished with error [-999] Error Domain=NSURLErrorDomain Code=-999 UserInfo={NSErrorFailingURLStringKey=<private>, NSErrorFailingURLKey=<private>, _NSURLErrorRelatedURLSessionTaskErrorKey=<private>, _NSURLErrorFailingURLSessionTaskErrorKey=<private>, NSLocalizedDescription=<private>}

@petrbela
Copy link
Contributor

petrbela commented Dec 11, 2020

Do you by any change have silent mode turned on on those devices? If so, there's an issue about it in TheWidlarzGroup/react-native-video#204. They ended up adding a prop to ignore the silent setting but not sure if a similar one exists in the expo video library.

Edit: You can enable it in Expo by setting playsInSilentModeIOS (it's a global setting so you may want to call it as an effect in your App component, or change it any time later):

import { Audio } from 'expo-av'

  useEffect(() => {
    Audio.setAudioModeAsync({ playsInSilentModeIOS: true })
  }, [])

@kevgrig
Copy link
Contributor Author

kevgrig commented Dec 11, 2020

@petrbela Wow, you were totally right, thanks! I feel embarrassed that I didn't know about the physical silent button on the iPhone SE (I rarely use iPhones). I was just pressing the volume up button on the phone which show a visual cue on the left of the phone that suggests the volume is going up, and Safari was playing the mp4 with sound. I would have guessed that the iPhone would give some subtle cue that it's in silent mode when one is pushing the volume up button!

The Audio.setAudioModeAsync({ playsInSilentModeIOS: true }) solution worked. I hope this was the same issue observed on the other phones we tested with, so I'll double check. Thanks again!

@kevgrig
Copy link
Contributor Author

kevgrig commented Dec 12, 2020

Confirmed with another user that the issue is resolved with Audio.setAudioModeAsync({ playsInSilentModeIOS: true }). Thanks again!

@kevgrig kevgrig closed this as completed Dec 12, 2020
@sethgw
Copy link

sethgw commented Mar 2, 2021

Could someone give me a little pointer on this example snack?

https://snack.expo.io/@fluid/expo-av-video-silentmode

I can't for the life of me get Audio.setAudioModeAsync({ playsInSilentModeIOS: true }) to do anything in iOS. The video is always muted when the silentMode is on

@fabiodevn1
Copy link

Someone managed to solve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants