cordova-rtc / cordova-plugin-iosrtc

Cordova iOS plugin exposing the WebRTC W3C API
MIT License
688 stars 341 forks source link

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

Open vahvarh opened 3 years ago

vahvarh commented 3 years ago

YOU MUST read first!

Please use Community Forum for general technical discussions and questions.

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

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

hthetiot commented 3 years ago

try:

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

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

hthetiot commented 3 years ago

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

hthetiot commented 3 years ago

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 commented 3 years ago

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.

vahvarh commented 3 years ago

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
hthetiot commented 3 years ago

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 commented 3 years ago

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.

vahvarh commented 3 years ago

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

hthetiot commented 3 years ago

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 commented 2 years ago

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

hthetiot commented 2 years ago

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

litiobat commented 1 year ago

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!

bkervaski commented 7 months ago

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.