AAC / MP4 not working in ActionScript 3 NetStream

I am trying to play a remote AAC file in ActionScript 3 in Flash CS3 and am currently using this code:

var url:String = " http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a ";
var connect_nc:NetConnection = new NetConnection();
connect_nc.connect(null);
var stream_ns:NetStream = new NetStream(connect_nc);
stream_ns.play(url);

(This is based on: http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html )

No errors are generated, but sound is not reproduced. I get the same behavior with a local AAC file and with a local MP4 video.

If I use a URL or a file path that is not a streaming file, I get a NetStream.Play.StreamNotFound error message, which I assume means that the stream was found in the case of a valid URL. If I use local FLV, its sound plays very well.

If I add the following listener and trace (evt.info.code) to netStatusHandler, I can only see any codes (e.g. NetStream.Play.Start) tracked by FLV. No codes are traceable with AAC or MP4. stream_ns.addEventListener (NetStatusEvent.NET_STATUS, netStatusHandler);

The same applies to adding this listener (i.e. the onMetaData argument is tracked only with FLV, and not with other file types), and the metaDataListener is defined as an object using the onMetaData method, which tracks its argument.
stream_ns.client = metaDataListener;

Any ideas on what might be wrong here, or how to diagnose it?

Thanks!

+4
source share
3 answers

Everything in ActionScript 3.0 is event-based (with a few random exceptions that use callbacks).

You need to listen to NetStatusEvent with info.code "NetConnection.Connect.Success" to enable the call to the NetStream.play () function.

Something works here (I just wrote it now and tested it for you):

 package { import flash.display.Sprite; import flash.net.NetConnection; import flash.net.NetStream; import flash.events.NetStatusEvent; import flash.events.AsyncErrorEvent; import flash.events.Event; public class MainDocument extends Sprite { private var _connection:NetConnection=new NetConnection(); private var _netStream:NetStream=null; private var _strM4AURL:String="http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a"; //constructor public function MainDocument():void { this._connect(); } private function _connect():void { this._connection.close(); this._connection=new NetConnection(); this._connection.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler); this._connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler); this._connection.connect(null); } private function _netStatusHandler(event:NetStatusEvent):void { trace(event.info.code); switch (event.info.code) { case "NetConnection.Connect.Success": this._requestAudio(); break; } } private function _requestAudio():void { if(this._netStream!==null) this._netStream.close(); this._netStream=new NetStream(this._connection); this._netStream.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler); this._netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler); this._netStream.checkPolicyFile=false; this._netStream.play(this._strM4AURL); } private function _asyncErrorHandler(event:AsyncErrorEvent):void { trace(event); } } } 

See the ActionScript 3.0 Language Reference for more information.

+1
source

As stated here http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html what you are doing right.

 var connect_nc:NetConnection = new NetConnection(); connect_nc.connect(null); var stream_ns:NetStream = new NetStream(connect_nc); stream_ns.play("RE-Sample.m4a"); 

However, a link to the ActionScript Language about nestream is found here: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#play%28%29

declares that:

play () method

...

...

When you use this method without Flash Media Server, there are security concerns. A file in an isolated environment with a local trusted or local network can download and play a video file from a remote sandbox, but cannot access the data of deleted files without explicit permission as a cross-domain access policy file. In addition, you can prevent the use of the SWF file running in Flash Player using this method by setting the allowNetworking parameter of the object and embed the tags in the HTML page containing the SWF content.

... ...

Parameters ... arguments - the location of the video file to play, as a URLRequest object or string. In Flash Player and in AIR content outside the application sandbox, you can play local video files that are stored in the same directory as the SWF file or in a subdirectory; however, you cannot go to a higher level directory.

So this is probably a security issue.

0
source

The good likelihood of what Oliver says is true, since you are not getting any feedback from NetStream-related event listeners, and you are getting StreamNotFound response.

StreamNotFound, when you do not connect to the FMS, means that you either made a mistake or do not see it due to a security problem.

0
source

All Articles