Does flash play .avi or .mpg4 ? If yes, how?

Katax Emperore picture Katax Emperore · Jun 2, 2011 · Viewed 8.4k times · Source

How to load and play .avi or .mpg4 in Flash? Is that possible ?

-> This class can play .flv and also .mp4 .. but for .avi it shows error "Error #2044: Unhandled NetStatusEvent:. level=error, code=NetStream.Play.StreamNotFound"

package src {     
    import flash.display.Sprite;     
    import flash.media.Video;     
    import flash.net.NetConnection;     
    import flash.net.NetStream;      
    import flash.events.Event;
    import flash.events.MouseEvent;

        public class vplayer extends Sprite{                 
            public var vid:Video = new Video(1920,1080);
            private var nc:NetConnection = new NetConnection();
            public var ns:NetStream;
            public var listener:Object = new Object();
            private var _duration:Number = 0; 

            public function vplayer():void{             
                addChild(vid);
                nc.connect(null);
                ns = new NetStream(nc);
                vid.attachNetStream(ns);
                listener.onMetaData = metaDataHandler;
                ns.client = listener;           
                //customClient.onCuePoint = cuePointHandler;
            }
            public function playVideo00(vv:String):void{

                ns.play(vv);
            }
            public function stopVideo00():void{
                ns.close();
            }
            /*public function cuePointHandler(infoObject:Object):void {
                trace("cuePoint");
            }*/
            public function metaDataHandler(infoObject:Object):void {
                _duration = infoObject["duration"];
                trace (" Time:  " + infoObject["duration"]);
            }
            public function get duration00():Number {     
                return _duration; 
            }
        } 
}

.. any help ?

Answer

ecc picture ecc · Nov 19, 2012

If the file is an MP4 on a streaming server, you simply need to prefix your video file name with "mp4:" when making the RTMP call. You need to be sure to only add it to the actual video file, not the full URL.

Example:

If your full video is at rtmp://domain.com/dir/myVideo.mp4 then you would prefix myVideo.mp4 when you call the play() function.

ns.play("mp4:myVideo");

Depending on your streaming server's settings you may or may not need the file extension.