Skip to main content
Pouradam
Inspiring
February 6, 2014
Answered

Audio playback stops in iOS when it goes to Standby (unlike Music players, Radio Apps etc).

  • February 6, 2014
  • 1 reply
  • 8784 views

Hi there!

I need my App to continue playing Audio in the background (for iOS) when it is in StandBy mode (Just like Radio Apps and Music player apps do).

So Far I have done these:

1- Render mode is set to CPU (not Direct/nor GPU).

2- I have included this code in the Main class of my app:

package as3

{

          import flash.desktop.NativeApplication;

          ...

 

          public class Main extends MovieClip

          {

                    public function Main()

                    {

              NativeApplication.nativeApplication.executeInBackground = true;

                              ...

                    }

     }

}

3- in the XML file I have included:

...

<iPhone>

<InfoAdditions>

      <![CDATA[

          <key>UIBackgroundModes</key>

          <array>

                     <string>audio</string>

          </array>

          <key>UIDeviceFamily</key>

          <array>

                    <string>1</string>

                    <string>2</string>

          </array>

       ]]>

</InfoAdditions>

</iPhone>

...

What results have been? Now when I press "HOME" button, the app is minimized and it KEEPS PLAYING AUDIO. geat!!

BUT still when I press the POWER button (means in Standby mode) Audio playback stops (Unlike what I want). What can I do to solve this problem?

I am really grateful for your help in this matter.

Technical details))

Adobe Flash Pro cs6

Air 3.9.0.1210 for ios

testing on Ipad 2/IPhone 5 (iOS 7)

This topic has been closed for replies.
Correct answer AsterLUXman

Wow! thanks a lot for your complete reply with details. I would certainly use that for my other projects! unfortunately in my current project I have the following conditions:

1- All Mp3 files are located on a remote server (online) and would be loaded in runtime (6236 MP3 files!)

2- Some are less than 15 sec, some are about 8 minutes!

So if I understand correctly this method can not solve my problem. right?

In the other hand, this app (persian language - written in Java) has the same functionality (loads external mp3s and play them while the iOS device is in standby) easy as pie!

Also there are many other apps loading external MP3 files you know and they keep playing in standby such as this one (Radio App - English).

But anyways I realy appreciate your time and thanks a lot for your prompt reply.

Best of all!


Hi Pouradam,

No, this won't work for your needs, unfortunately.  There may be an app manifest flag that needs to be set, maybe...  I don't know.

1 reply

Pouradam
PouradamAuthor
Inspiring
February 6, 2014

No answer yet? well I have done some research online, maybe it can help you help me!

1-  I suppose I need a method to activate/use iOS "AVAudioSessionCategoryPlayback".

2- It might be possible "via an Adobe AIR iOS Native Extension"?!

So far I have no information how can I really do these stuff in Flash Cs6?? But I think my answer lies in it.

Thanks again for your time.

Inspiring
February 7, 2014

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

Inspiring
February 13, 2014

Hi Pouradam,

No, this won't work for your needs, unfortunately.  There may be an app manifest flag that needs to be set, maybe...  I don't know.


Hi,

This feature works for us in IOS all versions, hitting the power button or home button works.

but render mode has to be set to direct per the api docs.

thx,

Kelly