Overview
AIR does not currently provide an up-to-date implementation for real-time media streaming. KlugMedia adds it as a native extension. Camera, microphone, encoder and echo cancellation run together in one native session, and ActionScript only sends commands and receives status.
Video is published and received as H.264, voice as Opus, both over standard RTMP. Received video is drawn natively on top of the AIR stage, so it stays sharp and smooth even on older devices.
KlugMedia is in daily use in the PetCam App, our proof of concept, on the App Store, Google Play and the Mac.
Features
- Camera capture and H.264 publishing in one native session
- Native H.264 receive and display, aspect-correct, with crop-to-fill and rotation
- Two-way Opus voice with hardware echo cancellation, both sides talking at once
- Native camera preview, camera switch, torch and zoom
- Snapshots taken straight from the camera image
- MP4 recording of live streams on the Klug streaming server, picture and sound
- Automatic bitrate adaptation on weak networks
- Standard RTMP, so it works with ordinary media servers
Streaming server
KlugMedia comes with matching server software, developed together with the extension and tuned for AIR apps: stream handling, reliable reconnects, the two-way voice relay, MP4 recording and live viewing in a web browser.
Supported platforms
Coming soon: iPad apps on the Mac
On Macs with Apple silicon, the iOS build of an AIR app can run as an iPad app. KlugMedia supports this mode with camera, live video and two-way voice, including external USB cameras. One build then serves iPhone, iPad and Mac. This is in development and will be available soon.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.media</extensionID>
</extensions>
Request camera and microphone permission before the first start. The extension then owns the capture: do not open an AIR Camera or Microphone at the same time.
Quick example
import com.klug.petcam.camera.CameraStreamANE; var media:CameraStreamANE = CameraStreamANE.instance; if ( media.isSupported ) { // camera, H.264 and RTMP in one native session media.startPublish( "rtmp://your.server/live", "station-1", 640, 480, 12, 800 ); }
// play the stream natively inside a rectangle of the stage media.startReceive( "rtmp://your.server/live", "station-1", 0, 0, 640, 480, 0, CameraStreamANE.RECEIVE_FIT );
var voice:OpusVoiceBridge = new OpusVoiceBridge( new NativeOpusCodec(), 48000, 1, 960 ); voice.setVoiceProcessing( true ); // hardware echo cancellation voice.start();
API overview
| isSupported | True where the native media session is available. |
| startPublish(…) | Starts the camera and publishes video and voice over RTMP. |
| stopPublish() | Stops publishing and releases the camera. |
| startReceive(…) | Plays a remote stream natively inside a rectangle of the stage. |
| stopReceive() | Stops playback and removes the native view. |
| showPreview(…) / hidePreview() | Native camera preview over the stage. |
| switchCamera() | Switches between front and back camera while streaming. |
| setTorch(on) | Turns the camera light on or off while streaming. |
| captureSnapshot(w, h) | Saves a JPEG from the live camera image. |
| OpusVoiceBridge | Two-way voice: start, stop, echo cancellation on or off. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| iOS | iOS 17 or later |
| Android | Android 6.0 (API 23) or later |
| macOS | macOS 11 or later |
| Permissions | Camera and microphone |
| Server | Any RTMP server; the matching Klug streaming server is recommended |