Play M3U8 HTTP Stream through Flash Player using apple-http-osmf
Tried getting my video player to play back Apple m3u8 formatted dynamic stream. After some hassle with the apple-http-osmf component which reads in m3u8 files and prepares them for playback with OSMF I ended up hearing the sound, not the seeing video.
I had been using the MediaPlayer and MediaPlayerSprite classes so far.
After reading this issue I switched to using the HTTPNetStream class, as dani at electroteque.net used that to successfully build a HLS plugin for the Flowplayer.
Now my stream is played back through a regular flash.net.NetConnection.
In order to make it work you need the latest sources from
apple-http-osmf
and the osmf player 2.0
If you get the "Error: Quality level cannot be set at this time." - just comment that line out in HTTPStreamSource.as:330.
Also you want to make sure that within
at.matthew.httpstreaming.HTTPStreamingM3U8Handler.as the RATES_READY event is fired before the INDEX_READY event.
See the working source below or download the demo project (flash builder 4.6) from here
I had been using the MediaPlayer and MediaPlayerSprite classes so far.
After reading this issue I switched to using the HTTPNetStream class, as dani at electroteque.net used that to successfully build a HLS plugin for the Flowplayer.
Now my stream is played back through a regular flash.net.NetConnection.
In order to make it work you need the latest sources from
apple-http-osmf
and the osmf player 2.0
If you get the "Error: Quality level cannot be set at this time." - just comment that line out in HTTPStreamSource.as:330.
Also you want to make sure that within
at.matthew.httpstreaming.HTTPStreamingM3U8Handler.as the RATES_READY event is fired before the INDEX_READY event.
See the working source below or download the demo project (flash builder 4.6) from here
package
{
import at.matthew.httpstreaming.HTTPStreamingM3U8Factory;
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.events.AsyncErrorEvent;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.utils.setInterval;
import org.osmf.media.URLResource;
import org.osmf.net.StreamingURLResource;
import org.osmf.net.httpstreaming.*;
[SWF(width='640',height='360',backgroundColor='#cccccc',frameRate='25')]
public class StreamView extends Sprite
{
private var resource:URLResource;
private var connection:NetConnection;
private var video:Video;
private var stream:HTTPNetStream;
private var filename:String = "http://184.72.239.149/vod/smil:bigbuckbunnyiphone.smil/chunklist-b400000.m3u8";
public function StreamView()
{
addEventListener(Event.ADDED_TO_STAGE, addedComplete);
}
private function addedComplete(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, addedComplete);
stage.scaleMode = StageScaleMode.NO_SCALE;
video = new Video();
video.smoothing = true;
addChild(video);
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);
connection.connect(null);
}
protected function setStream():void {
resource = new URLResource(filename);
stream = new HTTPNetStream(connection, new HTTPStreamingM3U8Factory, resource);
stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
stream.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,errorHandler);
stream.client = this;
video.attachNetStream(stream);
stream.play(resource);
};
protected function errorHandler(evt:ErrorEvent):void {
trace("Error: " + evt.text);
};
private function onNetStatus(e:NetStatusEvent):void
{
trace(e.info.code);
switch(e.info.code){
case "NetConnection.Connect.Success":
setStream();
break;
case "NetStream.Video.DimensionChange":
video.width = video.videoWidth;
video.height = video.videoHeight;
break;
}
}
/** Get metadata information from netstream class. **/
public function onMetaData(... args):void {
var obj:Object = args[0];
trace('onMetaData: ' + obj);
};
}
}
Hi,
AntwortenLöschenIs there a way to made a quality chooser for m3u8?