1 Reply Latest reply on Apr 23, 2007 10:19 AM by JeffreyGong

    Has anyone actually been able to build a FLV player with Flex 2?

    Chielosos
      I have been playing around with a FLV player in Flex 2, but I keep on running into one big problem: I never get a picture. Sound is not a problem, and all code seems to do exactly what it should. Except for the video showing up... I have tried loads of examples, read all of the docs I could get my hands on, but it all ends the same: no picture.

      The best solution (imho) I found is listed below, but still it does not do what it is supposed to do. Still, I only get audio.

      If there's anyone who's got a player working with the Video object using Flex 2 (SDK), I would *love* to hear your solution.

      Michiel.

      The source:
      package Assets {
      import flash.display.Sprite;
      import flash.net.NetConnection;
      import flash.net.NetStream;
      import flash.media.Video;
      import flash.text.TextFieldAutoSize;
      import flash.text.TextField;
      import flash.events.Event;
      import flash.events.TimerEvent;
      import flash.events.NetStatusEvent;
      import flash.utils.Timer;

      public class simpleFlv extends Sprite{
      private var _video:Video;
      private var _stream:NetStream;
      private var _playbackTime:TextField;
      private var _duration:uint;
      private var _timer:Timer;

      public function simpleFlv(){
      _duration = 0;

      _playbackTime = new TextField();
      _playbackTime.autoSize = TextFieldAutoSize.LEFT;
      _playbackTime.y = 20;
      _playbackTime.x = 20;
      _playbackTime.text = "Buffering …";

      _timer = new Timer(1000);
      _timer.addEventListener(TimerEvent.TIMER, onTimer);
      _timer.start();
      }

      public function playMyFlv(flvUrl:String): void {
      _video = new Video();

      var connection:NetConnection = new NetConnection();
      connection.connect(null);

      _stream = new NetStream(connection);
      _stream.play(flvUrl);

      var Client:Object = new Object();
      Client.onMetaData = onMetaData;
      _stream.client = Client;
      _video.attachNetStream(_stream);

      _stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);

      addChild(_video);
      addChild(_playbackTime);
      }

      private function onMetaData(data:Object): void {
      _duration = data.duration;
      }

      private function onNetStatus(e:NetStatusEvent): void {
      _video.width = _video.videoWidth;
      _video.height = _video.videoHeight;
      }

      private function onTimer(t:TimerEvent): void {
      if( _duration > 0 && _stream.time > 0 ){
      _playbackTime.text = Math.round(_stream.time) + " / " + Math.round(_duration);
      }
      }
      }
      }