[expo-av][iOS] Lock screen controls not working
See original GitHub issue🐛 Bug Report
I am using react-native-music-control
for lock screen controls when playing audio in background mode. The pause button on the lock screen works, but when play is pressed again, it does not resume playing. When the function that listens to the lock screen play button press runs, it says that there is no active sound session.
A a workaround, having this function: https://github.com/expo/expo/blob/491dde5dedca1a95efa40026aa119a0b0ec2b4e5/packages/expo-av/ios/EXAV/EXAVPlayerData.m#L359
always return true
results in the lock screen controls working.
The app I am working on is already in production. Is it safe to use this workaround as a temporary fix to get lock screen controls working?
Environment
Expo CLI 2.17.1 environment info: System: OS: macOS 10.14.4 Shell: 5.3 - /bin/zsh Binaries: Node: 11.10.1 - ~/.nvm/versions/node/v11.10.1/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.7.0 - ~/.nvm/versions/node/v11.10.1/bin/npm Watchman: 4.9.4 - /usr/local/bin/watchman IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.5 => 0.59.5 react-navigation: 3.9.1 => 3.9.1 npmGlobalPackages: expo-cli: 2.17.1
iOS
Steps to Reproduce
Create new app with bare template -> add react-native-music-control
as dependency -> configure MusicControl.on('play', ...)
and MusicControl.on('pause', ...)
and other required configurations -> play a sound -> whilst sound is playing lock the device -> on the lock screen press pause -> on the lock screen press play, this should print no active sound session… to error log
Expected Behavior
In the section above, the last step should resume the paused sound, rather than printing an error to the log
Actual Behavior
The last step two section above, i.e. printing to the error log that there is no active av session
Reproducible Demo
Issue Analytics
- State:
- Created 4 years ago
- Comments:22 (16 by maintainers)
Perfect, thank you! I found the wonderful patch-package tool and saved your second patch for now. ✨
I’ve been debugging this to see whether we can get this fixed. What I’ve found so far is that with the latest
expo-av
it doesn’t work because of this check inpromoteAudioSessionIfNecessary
in EXAM.m:This check does not allow audio to be played when the app is in the background. When disabling this check it starts working though. Nevertheless this check serves a purpose and we cannot just disable it. More research and a solid approach for triggering audio in the background is needed. To be continued…