PhoneGap Media Plugin - iOS - Play Sounds As Sound Effects - ios

I'm using the latest PhoneGap (3.3.0) and the Media plugin - I'm not using it in a music app or anything - I just need to use my sounds for notifications (like when a new message is received). I'm using my iPad and the volume of alert sounds is always controlled by the hardware buttons on the side, which controls the Sound Effects volume, but the Media Plugin sounds are controlled by the media volume instead. It's a major problem because users with their vibrate switch on may get an unwelcome sound effect, while others will expect the sound effects to play according to the Sound Effects volume level and be surprised when they see a message they didn't hear come in. Is there a way, besides push notifications, for my app to receive sound effects that actually behave as sound effects?
I set playAudioWhenScreenIsLocked to false hoping that it would make the sound play as an actual Sound Effect, but apparently it just makes the sound obey the hardware mute switch.
var snd = new Media("sounds/xylo.wav");
snd.play({ playAudioWhenScreenIsLocked : false });
Thanks

Related

Airplay background streaming like Spotify / Amazon Music

Is it possible to do Airplay audio streaming like Spotify or Amazon Music. When i setup an Airplay stream with Audio from my App the screen (on the Apple-TV) turns black and shows only the progressbar.
Is it possible to show the small hint in the top corner with all the audio information which disappears after a few Seconds and don't block the whole Apple TV Ui?
Or is this kind of a Spotify / Amazon Music privilege?
We had this problem as well. I believe that there are some bugs here in Apple's court, but we found a decent workaround that seems to be pretty safe from side effects.
We found that setting the player's allowsExternalPlayback field to NO would sometimes correctly stream the audio without the blank video screen (along with correct display of the now playing information, correct response to volume rocker etc...). However, we found that very often it would fail to play anything at all.
Doing some runtime introspection, we found that the player would always correctly buffer from the network. But when it would hit the isPlaybackLikelyToKeepUp event, it would set the player's rate field to 1 indicating that it is playing, but more often than not, not actually play the audio. No errors were reported and so from all we could tell, the player itself thinks that it is indeed playing when it is not. We found this hangup to only occur when we had set an AirPlay device for audio output.
So we found that in certain event callbacks and other key places, if we added a simple one-liner:
if( self.avPlayer.rate == 1 ){ self.avPlayer.rate = 1; }
It would kick whatever internal hold ups were causing the player to not actually AirPlay and correctly stream the audio. If the player was already correctly playing, then no harm done.

ios setting to neatly bypass iphone mute

I am working on an app that, among other things, provides alarms in emergencies. I would like to add a setting that will allow users to receive alarms with sound even if their phone is muted. As far as I am aware, this could be hacked by playing an mp3 through media services, as if the app was a music player left to play in the background, but that doesn't seem extremely kosher.
Does anyone know a 'neater' way to do this? Can I somehow allow my users to prioritise my app over the mute button?
Thank you very much.

Using the TTS Synthesizer in iOS when the app is ALREADY on the background

I would like to play a sound and use the AVSpeechSynthesizer to speak out some strings. The point is that I want these to happen when the device is already locked and then some events happen which triggers them.
I've found lots of info about how to play sound on the background, but this means that playback starts when the app is active and then the playback could continue, if the screen is being locked (after the start of playback). I've done all the tricks but can't hear a sound, which is triggered when the device is locked (and app is already on the background). However this works with iOS 8.3 simulator almost out-of-the-box, but not with a device.
So how to resolve this? Should I actually use some notification stuff to produce the desired outcome? I'm not too familiar with the notifications, so is there any other workarounds or is the notifications way easier than I think?
Cheers,
Mikko

Phonegap media stops system music

Phonegap media play method has a magic option playAudioWhenScreenIsLocked = false that does good job:
Prevents app music from playing when app is in background;
Makes app music obey the hardware "mute" button: without this option your app will ignore if user device is muted and play sound anyway.
But there is third hidden magic in this option. It stops current playing song from native Music app. Most of all it's annoying when I want to play short single sound.
Actually I would like to implement this scenario:
Music: Check if system music is playing on the app start. If it is not, play my app music, otherwise let user enjoy his own media.
Sound FX: Just play my little sound once and don't spoil anything.
And never play anything in background and when device is muted! Even if system Music app can let itself do so.
Has anyone managed to do something similar?
Thank you.
Ended up using https://github.com/floatinghotpot/cordova-plugin-nativeaudio (https://build.phonegap.com/plugins/2291)
Be aware: simple sound effects are not working in Simulator.

Detect mute event and status on iPhone and other iOS devices in PhoneGap app?

There seem to be a few threads floating around this topic but no definitive answer: if a user loads the app with sound enabled but later mutes his/her iPhone, how can we detect this in PhoneGap? Is there a callback for this event? The docs don't seem to list anything.
A second, related question: how to detect the status of the mute button? If someone has mute enabled, how do you detect this to avoid playing audio? The media.play() method only seems to have an option concerning whether to play audio when the screen is locked.
Thanks!
I wanted our app to don't play sounds when the iPhone is muted.
After hours of searching I decided to try with the following parameter and works as expected:
myMedia.play({ playAudioWhenScreenIsLocked : false });
The documentation doesn't say anything that this parameter will make the sound to not play when the iPhone is muted, but it behaves like that.
I'm using PhoneGap 2.6.0 and the docs says:
Pass in this option to the play method to specify whether you want to
play the audio of the media file when the screen is locked (this
defaults to true if not set). If this is set to true, it will ignore
the state of the hardware mute button.
Bad documented?

Resources