1 Reply Latest reply on Sep 25, 2011 8:00 PM by todayliu@hotmail.com

    flash.media.Video does not work in AIR 3.0 candidate

    todayliu@hotmail.com

      there is my Air3.0 download link  :http://download.macromedia.com/pub/labs/flashplatformruntimes/air3/air3_rc1_sdk_win_090611 .zip

       

      my code: VideoPlayer and my call method:

       

      var video : VideoPlayer = new VideoPlayer(400, 300);

      video.setControlBar(_bar);

      video.play("兵临城下.flv");

       

      I sorry i dont know how to attach my Test video.

       

      system info:

      operation system :Win7 pro   32bit

      cup:I5-2300

      Graphic chips: Geforce 210.

      develop tool:FDT4.0

       

      btw:

      first I downloaded the SDK 4.5,where air3.0 candidate publish,I downloaded it and copy the air 3.0 candidate version into SDK 4.5,cover them.

      if there is any question please mail me:todayliu@hotmail.com

       

       

      package {

                import flash.events.ProgressEvent;

                import flash.media.SoundTransform;

                import flash.events.Event;

                import flash.events.NetStatusEvent;

                import flash.media.Video;

                import flash.net.NetStream;

                import flash.net.NetConnection;

                import flash.display.Sprite;

       

       

                /**

                 * @author Leo

                 */

                public class VideoPlayer extends Sprite {

                          static public const PLAY : String = "play";

                          static public const PAUSE : String = "pause";

                          static public const STOP : String = "stop";

                          private var _ns : NetConnection;

                          private var _nts : NetStream;

                          private var _video : Video;

                          private var _width : Number;

                          private var _totaltime : uint = 0;

                          private var _videoWidth : Number;

                          private var _videoHeigth : Number;

                          private var _fileSzie : uint = 0;

                          private var _height : Number;

                          private var metaObject : Object = new Object();

       

       

                          public function VideoPlayer(width : Number, height : Number) {

                                    _width = width;

                                    _height = height;

       

       

                                    metaObject["onMetaData"] = onMetaData;

                                    metaObject["onImageData"] = onImageData;

                                    metaObject["onTextData"] = onTextData;

                                    metaObject["onCuePoint "] = onCuePoint;

                                    _ns = new NetConnection();

                                    _ns.connect(null);

                                    _nts = new NetStream(_ns);

                                    _nts.addEventListener(NetStatusEvent.NET_STATUS, netStatusListener);

                                    _nts.client = metaObject;

                                    _video = new Video(width, height);

                                    addChild(_video);

                          }

       

       

                          public function play(value : String) : void {

                                    if (_nts != null) {

                                              _nts.close();

                                              _nts = null;

                                              _nts = new NetStream(_ns);

                                              _nts.client = metaObject;

                                    }

                                    _nts.play(value);

                                    _video.attachNetStream(_nts);

                          }

       

       

                          private function netStatusListener(event : NetStatusEvent) : void {

                                    var code : String = event["info"]["code"];

                                    switch (code) {

                                              case "NetStream.Play.Start" :

                                                        if (_control) _control.status = PLAY;

                                                        break;

                                              case "NetStream.Play.StreamNotFound":

                                                        break;

                                              case "NetStream.Buffer.Empty" :

                                                        break;

                                              case "NetStream.Buffer.Full" :

                                                        break;

                                              case "NetStream.Buffer.Flush" :

                                                        break;

                                              case "NetStream.Seek.Notify" :

                                                        break;

                                              case "NetStream.Seek.InvalidTime" :

                                                        break;

                                              case "NetStream.Play.Stop" :

                                                        this.removeEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                                                        _nts.seek(0);

                                                        _nts.pause();

                                                        _control.timeInfo(0, _totaltime);

                                                        break;

                                    }

                          }

       

       

                          private var _control : IVideoControlBar;

       

       

                          public function setControlBar(cls : IVideoControlBar) : void {

                                    _control = cls;

                                    _control.video = _video;

                                    _control.addEventListener(VideoContorlBarEvent.CONTROL, contolListener, false, 0, true);

                                    _control.addEventListener(ProgressEvent.PROGRESS, progressListener, false, 0, true);

                                    _control.addEventListener(Event.CHANGE, volumeChangeListener);

                                    if (_totaltime != 0)

                                              if (!this.hasEventListener(Event.ENTER_FRAME))

                                                        this.addEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                          }

       

       

                          private function progressListener(event : ProgressEvent) : void {

                                    event.stopImmediatePropagation();

                                    if (_nts) {

                                              _nts.pause();

                                              _nts.seek((_totaltime * event.bytesLoaded / 100) >> 0);

                                              _nts.resume();

                                    }

                          }

       

       

                          private function volumeChangeListener(event : Event) : void {

                                    event.stopImmediatePropagation();

                                    _nts && (_nts.soundTransform = new SoundTransform(_control.volume, 1.0));

                          }

       

       

                          private function contolListener(event : VideoContorlBarEvent) : void {

                                    if (_nts == null) return;

                                    switch(event.status) {

                                              case VideoContorlBarEvent.PAUSE:

                                                        _nts.pause();

                                                        if (this.hasEventListener(Event.ENTER_FRAME)) this.removeEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                                                        break;

                                              case VideoContorlBarEvent.PLAY:

                                                        _nts.resume();

                                                        _control.volume = _nts.soundTransform.volume;

                                                        if (_totaltime != 0)

                                                                  if (!this.hasEventListener(Event.ENTER_FRAME))

                                                                            this.addEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                                                        break;

                                              case VideoContorlBarEvent.STOP:

                                                        _nts.seek(0);

                                                        _nts.pause();

                                                        _control.timeInfo(0, _totaltime);

                                                        break;

                                              case VideoContorlBarEvent.CHANGE:

                                                        play(event.url);

                                                        break;

                                    }

                          }

       

       

                          private function onCuePoint(data : Object) : void {

                                    trace(data);

                          }

       

       

                          private function onTextData(data : Object) : void {

                                    trace(data);

                          }

       

       

                          private function onImageData(data : Object) : void {

                                    trace(data);

                          }

       

       

                          private function onMetaData(data : Object) : void {

                                    trace(data);

                                    // duration  filesize   framerate  height  width

                                    _totaltime = uint(data["duration"]);

                                    _fileSzie = uint(data["filesize"]);

                                    _videoWidth = Number(data["width"]);

                                    _videoHeigth = Number(data["height"]);

                                    if (!this.hasEventListener(Event.ENTER_FRAME))

                                              this.addEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                          }

       

       

                          private function showPlayInfoHandler(event : Event) : void {

                                    if (_control != null) {

                                              _control.loaded(_nts.bytesLoaded / _nts.bytesTotal);

                                              _control.timeInfo(_nts.time, _totaltime);

                                    } else {

                                              this.removeEventListener(Event.ENTER_FRAME, showPlayInfoHandler);

                                    }

                          }

                }

      }