I haven’t played much with net stream, but it seems to be the only way to get an MP4 to stream. I usually use the FLVComponent but its not working.
Anyway, I made a class and my video is not appearing for some reason. The metadata is reading in fine and it is connecting. It just doesnt seem to play.
//create an instance of the class
import com.ronnieswietek.MP4Player;
var player:MP4Player = new MP4Player("rtmp://digitalout.fcod.llnwd.net/a3870/o35/u/","mp4:test/backyard_bombshells.mp4");
addChild(player);
The class:
package com.ronnieswietek
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import fl.video.*;
public class MP4Player extends Sprite
{
private var video :Video;
private var nc :NetConnection;
private var ns :NetStream;
private var cc :Object;
private var server :String;
private var stream :String;
public function MP4Player(server:String,stream:String)
{
addEventListener(Event.ADDED_TO_STAGE, init);
this.server = server;
this.stream = stream;
}
private function init(e:Event):void
{
cc = new Object();
cc.onMetaData = metaDataHandler;
cc.bwDone = onBWDone;
nc = new NetConnection();
nc.client = cc;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncError);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
nc.connect(server);
}
private function netStatus(event:NetStatusEvent):void
{
var info:Object = event.info;
trace(info.code);
if (info.code == "NetConnection.Connect.Success")
{
video = new Video();
ns = new NetStream(nc);
ns.client = cc;
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncError);
video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, playheadUpdate);
video.attachNetStream(ns);
ns.play(stream);
addChild(video);
}
}
private function asyncError(e:AsyncErrorEvent):void
{
trace("AsyncErrorEvent: " + e);
}
private function netSecurityError(e:SecurityErrorEvent):void
{
trace("netSecurityError: " + e);
}
private function onBWDone(info:Object):void
{
}
private function metaDataHandler(info:Object):void
{
video.width = info.width;
video.height = info.height;
}
private function playheadUpdate(e:VideoEvent):void
{
trace(e);
}
}
}