Copy link to clipboard
Copied
Hi there!
I have an App that loads an MP3 from a URL and then play it (Flash cs6 - Air 3.9)
In Android (when I publish it as APK) , when user press Power, or Minimize the App, the sound keeps playing (as I want it)
But same code in iOS, when I press Home or Power, the sound get "PAUSED", and keep playing only after I re-activate my App.
I tried to solve it with this line of code:
NativeApplication.nativeApplication.executeInBackground = true;
But no success.
Would anyone please help me what should I do to prevent iOS from PAUSING the sound in my APP after pressing Home and/or Power ?
Thank you in advanced.
Hi Pouradam,
I know it sucks.
On iOS, the only way to have a sound be played while the app is minimized, is if the app is actually running in the background ( obviously ). To do this, in the app manifest, you need to set UIBackgroundModes = audio, like so:
<InfoAdditions>
<![CDATA[
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
]]>
</InfoAdditions>
However, ever since "batterygate" on iPhone4, Apple has been tig
...Copy link to clipboard
Copied
Please correct me If I have posted this question in the wrong topic?!
Copy link to clipboard
Copied
no, this is the correct forum.
i just don't think i can be helpful because (imo) that behavior is expected (and desirable in iOS) and is unexpected (and undesirable in android).
Copy link to clipboard
Copied
Hi Pouradam,
I know it sucks.
On iOS, the only way to have a sound be played while the app is minimized, is if the app is actually running in the background ( obviously ). To do this, in the app manifest, you need to set UIBackgroundModes = audio, like so:
<InfoAdditions>
<![CDATA[
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
]]>
</InfoAdditions>
However, ever since "batterygate" on iPhone4, Apple has been tightening its policy on apps that are needlessly running in the background. If the sound is meant to play continuously ( ex: music player ), then they will *probably* be ok with it. But if the sound is intermittent ( even if it is the alarm sound of an alarm-clock ), they will probably disallow it.
So, if you want your app to play intermittent sounds while in the background, your only chance is to set up notifications, and associate a sound to the notifications if you can.
However, should you try the local notification route, using Juan Carlos Pazmino's ANE, be advised that the sound feature is broken at the moment, at least on iOS 5.1.1. Also, back when it was working, I wasn't able to choose the sound via the app: all I got was the standard "ding" sound. Maybe push notifications are more robust.
Cheers.
Copy link to clipboard
Copied
Wow!! Hi AsterLUXman and thank you so much for your complete reply!
I was nearly forgot what I wanted to do and still I have not found any solution for that.
My App is something like a Music player, so based on your note I can do that hopefully!
Now, may I ask if it is possible I do it INSIDE flash? I mean is that possible I code this inside my App or I have to change the XML as mentioned??
Thanks again - Ali
Copy link to clipboard
Copied
As far as I know, you can only enable the UIBackgroundmodes via the app manifest.
Copy link to clipboard
Copied
Ok thank you so much for your help I will give it a try
Copy link to clipboard
Copied
Hi friend! (AsterLUXman)
Your solution solved the problem of keep playing Audio in the Background (when user press HOME button), but still it will stop the sound as soon as iOS device enter stand by mode (Power Button). Also I have asked this as a new Question, still no reply and I wonder maybe you have the solution for this too?!
Cheers,
Ali
Copy link to clipboard
Copied
Hi Pouradam,
What worked for me, in the end, is the use of Distriqt's Local Notification API.
http://distriqt.com/native-extensions
This ANE allows you to play your own sound sample ( up to 30 secs long on iOS according to the doc, though it seems to work if longer so I would check with Distriqt ), along with the notification. The sound sample needs to be a *.caf on iOS, and either *.wav or *.mp3 on Android, and needs to be packaged into the root folder of the *.ipa or *.apk ( just add it to the adt.bat command line, after the icon paths ).
This sound will be audible even if the device is idling ( standby ) on either platforms. On iOS, the sound can be made to replay every minute, whereas on Android, the sound can be made to be looping ( via the 'flags' property ), until the local notif is cancelled by the user or the app.
Note that for both platforms ( iOS and Android ), the local notification is scheduled ahead of time and will run even if the app has since been closed ( on Android, the ANE uses the AlarmManager ). The only exception, on Android, is if the app is force-closed, which will cancel the notification, but closing the app properly ( either by the OS, if it runs out of ram, or in AS3, via NativeApplication.nativeApplication.exit() ) won't cancel the notification.
The downside of local notifs is that they don't execute code, per se, however they can pass a data payload ( text ) back to the app, if it is running ( even if minimized ), which a handler can receive to do stuff. For the handler to work while the app is minmized on IOS, you will have to have one of the UI background modes set to true.
Note: my need for the sound to be heard even in standby was for a beeping alarm-clock, so I am not really needing to play long bits of music. I also added music player functionality to my app but I am not requiring that the music be heard while in standby. However, to prevent the device to go into standby when the app is running in the foreground, I use NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE, whenever the app is activated ( on Android, you will also need the following manifest tags:
<manifest><uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/></manifest>
). Also: don't forget to turn off the KEEP_AWAKE when the app is deactivated by the user, e.g. goes into the background ( see: NativeApplication.nativeApplication's Event.ACTIVATE / Event.DEACTIVATE ).
Find more inspiration, events, and resources on the new Adobe Community
Explore Now