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

Keep audio on background #176

Closed
gwendall opened this issue Apr 29, 2020 · 31 comments
Closed

Keep audio on background #176

gwendall opened this issue Apr 29, 2020 · 31 comments

Comments

@gwendall
Copy link

Right now, switching to another app or locking the phone shuts the sound down. Is there a way to keep it running ?

@LichKing-2234
Copy link
Collaborator

you may need to add foreground service to the android code.
https://docs.agora.io/en/faq/android_background

@fritzfr
Copy link

fritzfr commented Oct 14, 2020

@LichKing-2234 Any chance you have more info on how to integrate this? Shouldn't this be included in this SDK?

@LichKing-2234
Copy link
Collaborator

LichKing-2234 commented Oct 28, 2020

Although we will not integrate Callkit (iOS) and ConnectionService (Android) in the SDK in the near future, if you just want the app to keep calling in the background, you can call setParameters('{"che.audio.opensl":true}'); on the Android platform(>2.3.2), enable Background Modes and select the Audio, Airplay, and Picture in Picture, and Voice over IP options on the IOS platform.

image

@LichKing-2234 LichKing-2234 pinned this issue Nov 17, 2020
@tak-bro
Copy link

tak-bro commented Nov 19, 2020

@LichKing-2234 Where should I add the code setParameters('{"che.audio.opensl":true}');? Could you please tell me how to add Android code on React Native project?

@LichKing-2234
Copy link
Collaborator

LichKing-2234 commented Nov 19, 2020

@tak-bro RN SDK also export setParameters function

@tak-bro
Copy link

tak-bro commented Nov 20, 2020

@tak-bro RN SDK also export setParameters function

Thanks!

@eyalcohen4
Copy link

eyalcohen4 commented Dec 12, 2020

Hi fellows,
I can't find setParameters in the react-native SDK nor in the react-native-agora package.
WDYMN when u say RN SDK also export setParameters function?

UPDATE: Found it.
For anyone looking in the future, the setParameters method sits on the RtcEngine instance.

@arya-man
Copy link

@LichKing-2234 what do you mean by export the function? Is await this.agora.setParameters('{"che.audio.opensl":true}'); not enough? If so, what extra thing are we supposed to do?

@LichKing-2234
Copy link
Collaborator

@eyalcohen4 any problem?

@dhavalagile
Copy link

audio not working when app goes in backgroud after 1 min.

I had set await _engine.setParameters('{"che.audio.opensl":true}');

@LichKing-2234
Copy link
Collaborator

@arya-man
Copy link

arya-man commented Feb 7, 2021

Any success on starting a foreground service? I have no android coding experience, so for me its super confusing

@hongzhou85
Copy link

How about for iOS? any web document or information on this? I want to keep audio on as well when app goes into background.

@LichKing-2234
Copy link
Collaborator

@hongzhou85 #176 (comment)

@hongzhou85
Copy link

Does this need to add background processing and fetch to the info,plist for iOS on xcode?

@hongzhou85
Copy link

I have successfully enabled this on iOS by enabling the VoIP and Audio modes. How do we do it on React native Android?

@LichKing-2234
Copy link
Collaborator

@hongzhou85 I have commented above.

@jaymovaliya
Copy link

@hongzhou85 , can you share some code SS for doing this?

@hongzhou85
Copy link

Although we will not integrate Callkit (iOS) and ConnectionService (Android) in the SDK in the near future, if you just want the app to keep calling in the background, you can call setParameters('{"che.audio.opensl":true}'); on the Android platform(>2.3.2), enable Background Modes and select the Audio, Airplay, and Picture in Picture, and Voice over IP options on the IOS platform.

image

@jaymovaliya this one for ios would work

@hongzhou85
Copy link

For Android, I'm going to attempt this for foreground service.
https://github.com/Raja0sama/rn-foreground-service

Another paid alternative may be this:
https://notifee.app/react-native/docs/android/foreground-service

Otherwise, for React Native you would have to code the headless js, which has little example on how to do it.

@shahabt24
Copy link

I have successfully enabled this on iOS by enabling the VoIP and Audio modes. How do we do it on React native Android?

How did you do this?
I checked those options in background mode in XCode but the app still closes after 5 second going to background

@OscarJuniusDev
Copy link

My app also closes after exactly 5 seconds in background, although the user is in an active call. Have you found a solution for this?

@shahabt24
Copy link

shahabt24 commented Dec 25, 2021

My app also closes after exactly 5 seconds in background, although the user is in an active call. Have you found a solution for this?

Hi,
Sorry for delay, yes I found the solution,
In IOS, you have to check things comes above in XCODE then put all the functions related to redux and storage in this:

if (AppState.currentState === 'active') {
      //do whatever you want
}

In ANDROID, you have to run a foreground service which is listed below,

ANDROID FOREGROUND SERVICE:

I use this package for foreground service: @supersami/rn-foreground-service

import ReactNativeForegroundService from '@supersami/rn-foreground-service';

export const initForegroundService = () => {
  return new Promise((result) => {
    ReactNativeForegroundService?.add_task(() => {}, {
      delay: 100,
      onLoop: true,
      taskId: 'taskid',
      onError: (e: any) => {},
    });
    result(true);
  });
};
export const removeForegroundService = () => {
  ReactNativeForegroundService?.remove_task('taskid');
};

export const startForegroundService = () => {
  ReactNativeForegroundService?.start({
    id: 144,
    title: '...',
    message: '...',
  });
};
export const stopForegroundService = () => {
  if (ReactNativeForegroundService) {
    ReactNativeForegroundService?.stop();
  }
};

@SamarthKejriwal
Copy link

Follwing this #176 (comment) approach has rejected my ios app from app store saying that -

Your app declares support for VoIP in the UIBackgroundModes key in your Info.plist, but it does not include any Voice over IP services.

Next Steps

To resolve this issue, please revise your app to either add VoIP features or remove the "voip" setting from the UIBackgroundModes key.

We recognize that VoIP can provide "keep alive" functionality that is useful for many app features. However, using VoIP in this manner is not the intended purpose of VoIP.

@hongzhou85
Copy link

Follwing this #176 (comment) approach has rejected my ios app from app store saying that -

Your app declares support for VoIP in the UIBackgroundModes key in your Info.plist, but it does not include any Voice over IP services.

Next Steps

To resolve this issue, please revise your app to either add VoIP features or remove the "voip" setting from the UIBackgroundModes key.

We recognize that VoIP can provide "keep alive" functionality that is useful for many app features. However, using VoIP in this manner is not the intended purpose of VoIP.

I believe this reply means you have not utilized any VoIP features in your App, so including it is not required. Appstore do not accept additional permission request without having actual features using the permission.

@nyoung697
Copy link

Hey @SamarthKejriwal did you get this sorted? My app just got rejected from Apple for the exact same reason. Why is this being suggested as an approach? Is there another solution to keep audio in background?

@cranberry08
Copy link

I got the same thing… any advice

@nyoung697
Copy link

@cranberry08 I removed the VOIP background mode and just left in the Audio, Air Play, Picture in Picture.

https://docs.agora.io/en/Voice/ios_audio?platform=iOS#additional-settings-and-permissions

Those docs there led me to try that out.

Apple accepted our app and it seems to work fine when in the background.

Apple review did ask me to make a video demonstrating why I needed background audio capabilities.

@cranberry08
Copy link

cranberry08 commented Apr 16, 2022 via email

@abhijith-sys
Copy link

is there any updates form agora sdk for enabling the voice call even if the app is in the background?.what is the best solution for this problem

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

No branches or pull requests