Reputation: 41480
I have gotten a NetConnection and NetStream set up and the streaming mp3 is playing fine. The only problem is the metadata is not received even though NetStream's client has been set. Any idea what could have caused this?
Code snippet:
// set up NetConnection ... private function netStatusHandler(e:NetStatusEvent):void { if (e.info.code == "NetConnection.Connect.Success") { // NetConnection's connection established successfully netStream = new NetStream(nc); netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); netStream.client = new NetStreamClient(); netStream.play("mp3:music/123456"); } } class NetStreamClient { public function onMetaData(info:Object):void { trace("onMetaData"); } public function onPlayStatus(info:Object):void { trace("onPlayStatus"); } }
Upvotes: 3
Views: 7998
Reputation: 75
I had same problem but this code will help .
private var videoURL:String="video.flv";
private function connectStream():void
{
var objClient:Object=new Object();
objClient.onMetaData=objFunction;
stream = new NetStream(connection);
stream.client=function objClient():void{};
stream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler);
var video:Video = new Video();
video.attachNetStream(stream);
video.y=50;
video.x=50;
stream.play(videoURL);
}
Upvotes: 1
Reputation: 242
before the netStream.play( ) call add this:
netStream.onMetaData = function(infoObject:Object) {
trace('on metadata:');
for (var propName:String in infoObject) {
trace(propName + " = " + infoObject[propName]);
}
};
does this work?
Upvotes: 1
Reputation: 1
var client:Object = new Object( );
client.onMetaData = function(metadata:Object):void {
trace(metadata.duration);
};
videoStream.client = client;
Upvotes: 0
Reputation: 11
I think there could be problem with security restrictions - flash differs "content" and "data", content (audio, video, image) is played even from another domain but data from this domain are unaccesible. Audio or video are contents but metaData are data. It is similiar to the situation with images: you can load and display image from another domain but you can't read its bitmapData. Crossdomain should solve it
Upvotes: 1
Reputation: 6715
Your code looks fine, the thing is flash cant read metadata of files sometimes. It happen to me on flv videos. Just get output from better program, aftereffects solve my problems for videos. And last thing if you thing you doing somthing wrong you can check loadermax.
http://www.greensock.com/loadermax/
Upvotes: 0
Reputation: 1942
The problem is
- The metadata event listener is triggered after a call to the
NetStream.play() method, but before
the video playhead has advanced.- Classes should not be nested And you cannot have multiple classes in the same file.
- You can call a pause method immediately after play just for the purpose of triggering metadata event.
An example of onMetaData usage
var video:Video = new Video();
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");
video.attachNetStream(ns);
function ns_onMetaData(item:Object):void {
trace("metaData");
// Resize video instance.
video.width = item.width;
video.height = item.height;
// Center video instance on Stage.
video.x = (stage.stageWidth - video.width) / 2;
video.y = (stage.stageHeight - video.height) / 2;
}
function ns_onCuePoint(item:Object):void {
trace("cuePoint");
trace(item.name + "\t" + item.time);
}
Am i right in assuming you are using flex?
Upvotes: 0