SwiftAudio
SwiftAudio copied to clipboard
Remote commands not enabling as expected
Describe the bug Let met start by saying I don't do much with Swift; I'm using this library as a part of react-native-track-player.
Our app implements skipBackward and skipForward. Randomly, the iOS lock screen will display the standard rewind button instead of the skip backward button.
I'm led to believe this is some kind of race condition but am not comfortable enough with Swift to confirm.
To Reproduce This must be tested on a device as iOS simulator does not show media controls.
These steps won't cause the exact scenario I mentioned above, but I believe it's the same bug.
- In Example/SwiftAudio/AudioController.swift, add skipBackward and skipForward as remote commands. Use an interval other than 60 seconds, like:
.skipForward(preferredIntervals: [30]),
.skipBackward(preferredIntervals: [30]),
- Open RemoteCommandController.swift and make the following change:
internal func enable(commands: [RemoteCommand]) {
commands.forEach { (command) in
self.enable(command: command)
}
+
+ self.enable(command: RemoteCommand.skipBackward(preferredIntervals: [60]))
+ // usleep(10000)
+ self.enable(command: RemoteCommand.skipForward(preferredIntervals: [60]))
}
The skipBackward icon should say 60 and the skipForward icon should say 30, even though it should say 60.
- Uncomment the added
usleepand test again. Both buttons should now say 60. (Obviously usleep is not a solution, it's just the only way I've been able to guarantee the expected behavior in my test.)
Expected behavior Media controls should display the skipBackward and skipForward icons.
Screenshots
Incorrect behavior:

Expected behavior:

Device 1:
- Device: iPhone 7
- OS: iOS 13.2 and iOS 13.3
Device 2:
- Device: iPhone 11 Pro
- OS: iOS 13.3.1
I am also using this in react-native-rack-player. Seeing strange behavior related to the remote commands getting re-enabled every time the track changes.
When I get time, I will try to see if I can reproduce the behavior in the SwiftAudio example (outside of react native).
In my case, I don't actually want to change the remote commands ever, after the first time they are set. It seems odd that they are disabled and then re-enabled every time, even thought they never change. Also RNTP does not use the feature of including commands in the track item itself.
Related: https://github.com/jorgenhenrichsen/SwiftAudio/pull/66