Developing Android Applications with Adobe AIR [74]
More information on HTTP Dynamic Streaming is available online at http://www.adobe.com/products/httpdynamicstreaming/ and http://www.flashstreamworks.com/archive.php?post_id=1278132166.
Peer-to-Peer Communication
Real Time Media Flow Protocol (RTMFP) is an Adobe proprietary protocol that enables peer-to-peer communication in Flash Player and the AIR runtime. It opens up possibilities for your applications using video.
We will go over a video example in Chapter 15.
Controls
The methods for controlling the stream are play, pause, resume, seek, and close. You cannot stop the stream because it is still downloading. You need to close it completely.
You can check the progress of the stream by checking its time property. Use that value and increment it to seek ahead in the video. You can also seek to a specific time, of course. With progressive download, you can only seek ahead to points in the video file that have been downloaded. With embedded video and RTMP, you can seek anywhere within the video file at any time.
To monitor these events, register for NetStatusEvent and its info.code object:
function onNetEvent(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetStream.Play.Start" :
break;
case "NetStream.Play.Stop":
break;
case " NetStream.Pause.Notify" :
break;
case " NetStream.Unpause.Notify":
break;
case "NetStream.Buffer.Full":
break;
case "NetStream.Seek.Notify":
break;
}
}
}
You cannot use the Sound object to control the audio part on the video. Use the SoundTransform property instead. Here we are setting the volume to silent:
var transform:SoundTransform = new SoundTransform();
stream.soundTransform = new SoundTransform(0);
YouTube
It is almost impossible to talk about videos without mentioning YouTube. As you most certainly know, YouTube is a file-sharing video site that has changed the propagation of information via video, whether is it pop culture or current events.
YouTube videos can be played on Android devices if they are encoded with the H.264 video codec. Like Google Maps, discussed in Chapter 10, the user is presented with the option to choose between the YouTube local application, if it is installed on his device, and the browser version.
In both cases, you use a URLRequest:
import flash.net.navigateToURL;
import flash.net.URLRequest;
var youTubePath:String = "http://www.youtube.com/watch?v=";
var videoID:String = someID;
navigateToURL(new URLRequest(youTubePath + videoID);
To display the video at full screen, use a different path:
var youTubePath:String = "http://www.youtube.com/watch/v/";
Capturing Video
The native video camera can be used to capture video within AIR.
Video and the CameraUI Class
You can use the native camera within AIR to capture video. Your application needs to have permission. In Flash Professional, select File→AIR Android settings→Permissions→Camera. In Flash Builder, add the following permission:
The flash.media.CameraUI class is an addition to the ActionScript language to support the device’s native camera application. It is a subclass of the EventDispatcher class and is only supported on AIR for mobile.
This object allows you to launch the native camera application to shoot a video while your AIR application moves to the background.
NOTE
When you use the native camera, it comes to the foreground, your AIR application moves to the background, and NativeApplication Event.DEACTIVATE is fired. Make sure you don’t have any logic that could interfere with the proper running of your application, such as exiting.