I am building a mobile app with react-native. In the app, I have a react-native-webview which opens a website with an HTML5 tag. Everything works well when the app is in the foreground, but the audio stops after roughly 30 seconds - 1 minute when the app is put in the background (or the phone is locked).
Ideally, I'd like for it to keep playing. I've seen recommendations on using a foreground service, but I am not sure if that can work, since the webview itself is not in the foreground service?
So far, my attempts at using react-native-foreground-service have not been successful. I also tried using "react-native-background-task" but without success.
Can anyone with more experience with react-native tell me if what I want is feasible (on both Android and iOS), and if so what the best way forward is.
Thanks very much, Philippe
I tried using something like this:
import ForegroundService from 'react-native-foreground-service';
async setupForegroundService() {
// Set up the foreground service
console.log("Definitely made it here!")
await ForegroundService.startService({
id: 1234,
title: "Test Service Title",
message: "Playing audio"
});
render() {
this.setupForegroundService();
}
Even though I've checked that the service gets called (and I've added the proper service and permissions to the Android manifest), it doesn't seem to be solving the problem.