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

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

Open
3 tasks done
vahvarh opened this issue Sep 30, 2021 · 13 comments
Open
3 tasks done

Comments

@vahvarh
Copy link

vahvarh commented Sep 30, 2021

YOU MUST read first!

Please use Community Forum for general technical discussions and questions.

  • 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.
  • 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).
  • 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

@hthetiot
Copy link
Contributor

hthetiot commented Sep 30, 2021

try:

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

See #654 (comment)

@hthetiot
Copy link
Contributor

See also #654 (comment) (next comment after the one linked above)

@hthetiot
Copy link
Contributor

hthetiot commented Sep 30, 2021

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 hthetiot changed the title Background music issue when iosrtc even not started External music issue while iosrtc is running Sep 30, 2021
@hthetiot
Copy link
Contributor

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 hthetiot changed the title External music issue while iosrtc is running Third party app audio issue while app with iosrtc is running in the background or not Sep 30, 2021
@hthetiot hthetiot changed the title Third party app audio issue while app with iosrtc is running in the background or not Third party app audio issue while app with iosrtc is running in the background Sep 30, 2021
@vahvarh
Copy link
Author

vahvarh commented Sep 30, 2021

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

vahvarh commented Sep 30, 2021

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
Copy link
Contributor

hthetiot commented Oct 6, 2021

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
Copy link
Contributor

hthetiot commented Oct 8, 2021

@hthetiot
Copy link
Contributor

hthetiot commented Oct 8, 2021

@hthetiot hthetiot modified the milestones: 8.0.x, triage May 12, 2022
@litiobat
Copy link

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
Copy link

bkervaski commented Feb 29, 2024

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.

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

No branches or pull requests

4 participants