Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Ambient sound still silencing background

$
0
0

In my iOS app, I want to play sound without interrupting background music. I see no reason why Pandora or iTunes cant be playing while they use it.

here is the code that I am using to play the sound file:

var play = function(file, typeEnum)
{
    //file: file to be played.
    //typeEnum: index of playback modes. 
    //supported modes:
    var modes = [
    Ti.Media.AUDIO_SESSION_CATEGORY_AMBIENT, 
    Ti.Media.AUDIO_SESSION_CATEGORY_SOLO_AMBIENT, 
    Ti.Media.AUDIO_SESSION_CATEGORY_PLAYBACK,
    Ti.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD
    ];
    //make sure the typeEnum is valid
    typeEnum = Math.max(Math.min(typeEnum || 0,modes.length-1),0); 
    //set the session category
    Ti.Media.setAudioSessionCategory(modes[typeEnum]);
    //confirm the session category
    console.log("Playing sound as "+Ti.Media.audioSessionCategory);
    //play sound
    var player = Ti.Media.createSound({url:file});
    player.play();
    player=null;
};
Sound plays no problem, but if I try to use Ti.Media.AUDIO_SESSION_CATEGORY_AMBIENT, it still pauses the background music, sometimes. Sometimes it works perfectly. What can I do to improve this function to guarantee proper playback?

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>