Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-6495

Media plugin : Need way to set session category for iOS

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: cordova-plugin-media
    • Labels:
      None
    • Environment:

      iOS, all

      Description

      I need a way to play a sound effect (the occasional "beep") in my Cordova app without it shutting down any other Audio Sessions. Currently any sound from my app will cancel iTunes/Spotify/etc background music.

      Apple has a bunch of "Audio Session" categories which determine how an app's audio will mix with other audio streams. The documentation is here : https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html

      Anyway, the only 2 audio session categories mentioned in the Media plugin are hard-wired in there and not configurable. It should probably be more of an option, the way that playAudioWhenScreenIsLocked and numberOfLoops are options. The category I needed was AVAudioSessionCategoryAmbient. For now I've simply hard-wired it in for my project, but I'm going to need to patch the plugin after every plugin upgrade, etc.

      Also worth noting, the setCategory function should probably be called before the prepareToPlay function (it's not, currently). Without doing that, setting the category wasn't having any effect for me. Found the solution here : http://stackoverflow.com/questions/10377959/on-ipad-why-does-avaudiosessioncategoryambient-stop-the-music-playing-in-ipod

      I'm not an iOS programmer, and Objective-C and github both confuse the hell out of me so you probably don't want me contributing my code to the plugin, but hopefully these notes can be of help to someone better qualified.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              phoenician Paul Kane
            • Votes:
              5 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated: