by Nathan Weber
Table of contents
27 August 2012
This series of tutorials is designed for developers with an intermediate to advanced understanding of ActionScript 3 and building Adobe AIR applications. Familiarity with Flash Builder, Java, and Objective-C will also be helpful.
Additional required other products
Lately, I've been focused on writing native extensions for Adobe AIR. The project I'm currently working on requires numerous custom behaviors, many of which I could only deliver using native extensions. I've learned a great deal, particularly since I haven't coded extensively with iOS or Android.
In this tutorial series, I share what I've learned and show you how to create your own AIR native extension for both iOS and Android. At the end of the series you will have a fully functional and useful native extension. You can also download the completed extension for your own use via the GitHub link above or at the end of this tutorial.
Changing the volume of a video while it's playing in Flash Player in a web browser is easy, particularly if you're using Open Source Media Framework (OSMF). You simply change the value assigned to
MediaPlayer.volume. Unfortunately, when the video is playing in an Adobe AIR application on a mobile device, changing the value assigned to
MediaPlayer.volumedoes not produce the behavior that you might expect.
Both Android and iOS have a system-wide media volume. Pressing the hardware volume buttons while media is playing causes the media volume to be adjusted. The system volume is applied to the Adobe AIR application and overrides the volume set by the user within the Adobe AIR application. This leads to a problem when the AIR application is set at full volume, but the system media volume is muted. If you want to use a slider control in your application to control the audio (or if you have any UI elements or logic that is based off of the volume) you're in trouble as you will be accessing the wrong volume.
To solve this problem, you can create a native extension that interacts with the native layer to modify the system media volume, instead of using the usual methods within AIR to change the volume.
The volume native extension must have two parts. The first part is a method that can be called in AIR to adjust the system volume. The second part is a mechanism for notifying AIR whenever the user changes the system volume, either by using the hardware volume buttons or by using a different application.
The native extension has four parts:
- the ActionScript library
- a default implementation written in ActionScript
- the iOS native code
- the Android native code
The next three tutorials in this series will walk through each part, discussing how to write the code and potential pitfalls to consider. In the final part I cover building the ANE file.
If you are only interested in using the finished volume native extension you can get it here.
Note: If you plan on using the extension on iOS you must compile the IPA (both debug and release versions) from a Mac. It is possible to specify an external iOS SDK on Windows with AIR 3.3; however, Flash Builder for Windows does not yet support this option. You must also specify the location of the iOS SDK in the native extension settings for iOS in Flash Builder. If you'd like more information on why that is or how to do it, see Part 3 of this series.
To learn how to build the ActionScript library and the default implementation, proceed to Part 2 of this series.