简体   繁体   中英

AIR 2.7 for iOS playing audio in the background?

Update

With the latest Adobe AIR 3 Beta, Adobe added this functionality to their SDK.

http://labs.adobe.com/technologies/flashplatformruntimes/air3/

iOS Background Audio Playback Support — Developers can now write multitasking iOS applications that can play audio while in the background, including music or voice chat from a conferencing application.

--------- Original post ---------

With the new release of AIR SDK 2.7 and Flash Builder 4.5.1 you can "Take advantage of new features in iOS 4 like multitasking…" (from http://www.adobe.com/products/air/features/ )

Searching a bit I found out that this "multitasking" does not include true background process, like playing audio while the app is in the background!

I know this is new but does someone knows if it is possible to keep audio playing in the background?

With Air 3.0 you can have background music thanks to the UIBackgroundModes UIKit Keys (http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html):

Just change your /src/-app.xml file like this:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/3.0"> <!-- changed from 2.7 to 3.0 -->
    ...
    <iPhone>
        <InfoAdditions><![CDATA[
            <key>UIDeviceFamily</key>
            <array>
                <string>1</string> <!-- app will run on IPhone -->
                <string>2</string> <!-- app will run on IPad -->
            </array>
            <key>UIBackgroundModes</key>
            <array>
                <string>audio</string> <!-- audio background mode key -->
            </array>
        ]]></InfoAdditions>
        <requestedDisplayResolution>high</requestedDisplayResolution>
    </iPhone>
</application>

Successfully tested on IPhone 4 and IPad 1.

Of course, you must have Air 3 SDK installed in order to use this feature. Air 3 is shipped with FB 4.6.

If using FB 4.5, Air 3 SDK must be manually installed within Flash Builder 4.5. Installation procedure:

1. Locate the "old" SDKs

They are located in the Flash Builder directory, in my case this was c:\\program files(x86)\\adobe\\flash builder 4.5\\sdks

2. Make a copy of the previous SDK

Copy a previous SDK (I used SDK 4.5.1 for that) and rename the copied folder to AIR3SDK (or a different name if you like)

3. Overwrite the copied (!) SDK with the AIR3 SDK

Copy all files from the AIR3 SDK into the copied folder. It should ask you to overwrite files quite a couple of times. After this, you should have a working AIR3 SDK installed.

4. Set a name for the new SDK

I had to to this with the Beta2 - go to the new SDK directory and edit flex-sdk-description.xml - change the content from Flex 4.5.1 to AIR3 SDK.

5. Add the new playerglobal.swc from Flash Player 11

Download the current Flash Player 11 "playerglobal.swc" from http://labs.adobe.com/downloads/flashplayer11.html and put it into the correct folder. From the SDKs root folder this was: /frameworks/libs/player/11.0/ (I had to create the 11.0 folder myself and then just put the file in there and rename it to plain "playerglobal.swc")

6. Add the AIR3 SDK to Flash Builder

Under "Project Settings - Flex Compiler" for a project, choose the new SDK as SDK to use for the project. If the SDK does not show up, go to "configure Flex SDKs", then "Add" and select the newly created folder. The new AIR3 SDK should now be included in the dropdown list as a compiler for that project.

Don't forget to add -swf-version=13 as a compiler flag on the same screen.

After doing all this, I was able to use the new features, compile my projects and well, work with it

Air 3 SDK procedure source: http://forums.adobe.com/thread/899921

My understanding is that the text you have quoted there simply refers to the ability for the application to be frozen and unfrozen as iOS users manipulate other applications, allowing you to return to your previous view/state when the user returns to the application and nothing more.

I don't think, even if you specify the UIBackgroundMode of audio, that your audio will ever play in the background with AIR 2.7. Later versions, I imagine will come with that functionality.

These are the iOS phone keys to be described in the app XML. Most of them are not available in AIR 2.7

Anyhow, we must recognize, what a job has Adobe done. Unbelievably productive workflow for the mobile app development workflow for mobiles, and desktop.

The are the currently supported iOS keys in AIR 2.7 . The one we need for audio is UIBackgroundModes "audio"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM