cordova-plugin-iosrtc icon indicating copy to clipboard operation
cordova-plugin-iosrtc copied to clipboard

Third party app audio issue while app with iosrtc is running in the background

Open vahvarh opened this issue 4 years ago • 13 comments

YOU MUST read first!

Please use Community Forum for general technical discussions and questions.

  • [x] I have used Google with the error message or bug in association with the library and Cordova words to make sure the issue I'm reporting is only related to iOSRTC.
  • [x] I have provided steps to reproduce (e.g. using sample app code https://github.com/cordova-rtc/cordova-plugin-iosrtc-sample or updated extra/renderer-and-libwebrtc-tests.js file).
  • [x] I have provided versions of third party library name, IOS, Xcode and plugin version and adapter.js version if used.

Note: If the checkboxes above are not checked (which you do after the issue is posted), the issue will be closed, removing this checkbox will result in automatic closed issue.

Versions affected

  • Cordova version (e.g 7.1.0): 10.0.0 (latest)
  • Cordova iOS version (e.g 5.1.0): 6.1.0 (latest)
  • Plugin version (e.g 6.0.12): latest and git/master
  • iOS version (e.g 10.2): 11+
  • Xcode version (e.g 11.1 - 11A1027): 13.0
  • WebRTC-adapter version (e.g. 7.4.0): latest
  • WebRTC Framework version (e.g. JSSip 3.1.2): latest

Description

If background music plays (say apple music) and I start application (not even doing any API calls at all), music either stops (if cordova-plugin-background-mode is installed) or gets very loud and crappy (if no cordova-plugin-background-mode is installed).

Steps to reproduce

Music stop:

  1. Connect bluetooth or wired earphones
  2. Install cordova-plugin-iosrtc-sample
  3. delete or comment out scripts from www/index.html (src="js/common.js" and src="js/index-local.js")
  4. compile
  5. start music in player
  6. start application

Music gets loud and crappy:

  1. Connect bluetooth or wired earphones
  2. Install cordova-plugin-iosrtc-sample
  3. delete or comment out scripts from www/index.html (src="js/common.js" and src="js/index-local.js")
  4. cordova plugin remove cordova-plugin-background-mode
  5. compile
  6. start music in player
  7. start application

Expected results

Music continues to play with same volume and quality (since no API calls done yet)

Actual results

Music stops or gets loud and crappy

vahvarh avatar Sep 30 '21 08:09 vahvarh

try:

 <preference name="MANUAL_INIT_AUDIO_DEVICE" default="TRUE"/>

See https://github.com/cordova-rtc/cordova-plugin-iosrtc/issues/654#issuecomment-794110763

hthetiot avatar Sep 30 '21 12:09 hthetiot

See also https://github.com/cordova-rtc/cordova-plugin-iosrtc/issues/654#issuecomment-794121960 (next comment after the one linked above)

hthetiot avatar Sep 30 '21 12:09 hthetiot

Note: that ios shitty shared audio managment not cordova-rtc, but links above should provide workarround. The source code that may need improvment is here: https://github.com/cordova-rtc/cordova-plugin-iosrtc/blob/master/src/PluginRTCAudioController.swift

hthetiot avatar Sep 30 '21 12:09 hthetiot

Changed incorrect issue title "Background music issue when iosrtc even not started" cause iosrtc is started and that not really Background music but any sound from external app.

hthetiot avatar Sep 30 '21 12:09 hthetiot

Music gets loud and crappy:

  1. Connect bluetooth or wired earphones
  2. Install cordova-plugin-iosrtc-sample
  3. delete or comment out scripts from www/index.html (src="js/common.js" and src="js/index-local.js")
  4. cordova plugin remove cordova-plugin-background-mode
  5. set in config.xml: variable name="MANUAL_INIT_AUDIO_DEVICE" value="TRUE"
  6. compile
  7. start music in player
  8. start application

Music gets loud and crappy, then music stops, plays ding and does not continue:

  1. Connect bluetooth or wired earphones
  2. Install cordova-plugin-iosrtc-sample
  3. delete or comment out scripts from www/index.html (src="js/common.js" and src="js/index-local.js")
  4. cordova plugin remove cordova-plugin-background-mode
  5. set in config.xml: variable name="MANUAL_INIT_AUDIO_DEVICE" value="TRUE"
  6. Add to index.html script: var hack=new Audio('ding.mp3');hack.play();
  7. compile
  8. start music in player
  9. start application

vahvarh avatar Sep 30 '21 13:09 vahvarh

Thank for testing existing workaround. Unfortunately I cannot help you more than that only solution now is to tinker with AudioController implementation.

Note: did you cordova prepare after changing "MANUAL_INIT_AUDIO_DEVICE" because if it's false it's not supposed to do anything with audio.

hthetiot avatar Sep 30 '21 14:09 hthetiot

I understand that an issue for you, at the same time not many people listen to music while doing video conference, i guess the issue is when they don't kill the app and it stay in the background after a call.

hthetiot avatar Sep 30 '21 14:09 hthetiot

Not many people listen to music while doing video conference

We are making an application for employees work, and mostly they use it to do OTHER things rather than making calls. Like writing reports or making photos or checking some information (and at THAT time, they, of course, listen to music).

did you cordova prepare

Just in case, did again "cordova prepare ios" and "cordova build ios" after changing "MANUAL_INIT_AUDIO_DEVICE", same result

Interesting effect here (a screen recording), volume is set to about 20%, and at the moment of application start it rapidly jumps to 80% (i did not press button to raise volume). Did it several times, always same result, both with wired and bluetooth headphones. https://easymerch.ru/tmp/RPReplay_Final1633015173.MP4

vahvarh avatar Sep 30 '21 15:09 vahvarh

I will try to investigate based on recent donation that have been made to this project by @studium-inexorabile i can allocate some time to try to fix that issue for the community.

hthetiot avatar Oct 06 '21 17:10 hthetiot

Related: https://stackoverflow.com/questions/62708625/mixing-audio-on-ios/62840934#62840934

hthetiot avatar Oct 08 '21 11:10 hthetiot

Related: https://groups.google.com/g/discuss-webrtc/c/44ogyfkIC0w

hthetiot avatar Oct 08 '21 11:10 hthetiot

Hi! I don't know if I can help anyone with this, but I changed "onload" param to "false" in config.xml (iOS) and problem is solved. Now you can open any music app (like Youtube music or Apple music) and open my app, and now all it's right without bad sound or stops music. When I use the iosrtc plugin to make a videocall for example, the background music stops automatically and all works correctly. This is the only change, and for me, works. Greetings!

litiobat avatar Mar 29 '23 08:03 litiobat

Note: that ios shitty shared audio managment not cordova-rtc, but links above should provide workaround. The source code that may need improvement is here: https://github.com/cordova-rtc/cordova-plugin-iosrtc/blob/master/src/PluginRTCAudioController.swift

I just came here to say this++, been fighting AVAudioSession for years. Even now, the volume changes make no sense. Before a WebRTC call, the volume is what's expected. After a call, sound volume hasn't change in the AVAudioSession, however, it's distinctly lower. There's no amount of setting categories, modes, or options that will change it. Even forked iosrtc and did a deep dive over the last week or so. Seems silly it's this hard.

bkervaski avatar Feb 29 '24 16:02 bkervaski