-
-
Notifications
You must be signed in to change notification settings - Fork 266
Do lockscreen controls of this library (1.3.0) work on iOs with react-native 6.3.0 and expo-av 8.6.0 #378
Comments
Im also struggling a lot with this: #377 Im still investigating, but so far I've realized the library does not work until you stop the controls once (lol). And since you can only stop the controls after starting. You need something like this: // fake start, necessary so we can stop the plugin safely
MusicControl.enableBackgroundMode(true);
MusicControl.handleAudioInterruptions(true);
MusicControl.enableControl(Command.play, true);
MusicControl.setNowPlaying({});
MusicControl.updatePlayback(data); // you also need this or it wont work...
setTimeout(() => {
// The plugin doesn't work until we stop it at least once...
// so we do it here.
MusicControl.stopControl();
}, 50);
setTimeout(() => {
// Real start.
MusicControl.handleAudioInterruptions(true);
MusicControl.enableBackgroundMode(true);
MusicControl.enableControl(Command.play, true);
MusicControl.enableControl(Command.pause, true);
MusicControl.on(Command.play, onPlay);
MusicControl.on(Command.pause, onPause);
MusicControl.setNowPlaying(data);
}, 100); |
I finally got my hands on a real ios device, and unfortunately my rather hackish solution above only works on an emulator, not on a real device :( |
I tried your "hack" on both the simulator and a real device and it did not work in my project. Maybe you can share your simplest version of the app that worked on the simulator for me to check. I tried to run it on ios 14.4 |
This is my current PoC with the basic needs of my project: https://github.com/PupoSDC/react-native-multimedia-demo it includes a video and audio player in which both are controlled via the native music controls. Meanwhile i fixed the problem with Im not using expo. |
Replacing Expo-av with react-native-sound-player fixed the issue in my app. I do still need the time out fix you proposed. My guess is that it indeed was an issue with expo-av and it's ios settings. |
yeay! Thanks for confirming the timeout fix is needed for you as well, and that insanity is not my own only 😅 |
After some back and forwarding we discovered the above solution / hack only works in development mode. as soon as the app is built, it stops working :( If anyone has any ideas, it would be awesome to hear from you |
Yeah we've tried using expo-av and react-native-music-control to no avail. Thanks for this thread, going to switch to react-native-sound-player as well :) |
Hi everyone 👋 |
The IOS specific formula that worked for me ended up looking something like: MusicControl.handleAudioInterruptions(true);
MusicControl.setNowPlaying(data);
MusicControl.enableBackgroundMode(true);
MusicControl.enableControl(Command.play, true);
MusicControl.enableControl(Command.pause, true);
MusicControl.enableControl(Command.closeNotification, true, {
when: 'always',
});
MusicControl.enableControl(Command.skipBackward, !!onSkipBackward, {
interval: skipInterval,
});
MusicControl.enableControl(Command.skipForward, !!onSkipForward, {
interval: skipInterval,
});
MusicControl.on(Command.play, onPlay);
MusicControl.on(Command.pause, onPause);
MusicControl.on(Command.skipBackward, () => onSkipBackward?.(skipInterval));
MusicControl.on(Command.skipForward, () => onSkipForward?.(skipInterval)); In any case it was still very unstable, requiring all stars to align, and some bugs still existed that I was unable to track down last i worked on this... |
Im tried run your music control ios case on my device and this solution doesnt work in background mode 😔 Could you explain for me one thing?
|
Hi @vedamet, Unfortunately I can't be super useful, Im no longer working on this project, so I am working a bit out of memory + my own notes. I'm not sure what the I know its super frustrating, at the end of the day, the point of react-native is to abstract away these native APIs, but in this particular case, it must be done. |
I have it working on
|
The above
is critical. I'm getting it via
According to expo-av, the default is I think this prevents the lock screen controls from showing up |
After creating a basic player with this library I noticed the lockscreen controls are not showing. On Android everything is working fine, on the simulator in iOs however I can't get it to work.
In an useEffect I set the audio mode
Also I initialize the controls:
After that I only call the play on the soundObject and update the controls:
Any help is appreciated
The text was updated successfully, but these errors were encountered: