3 Replies Latest reply on Dec 26, 2010 9:42 PM by Mykola3296

    Loading VideoElement and URL




      I try to load VideoElement with this function and event.loadState reports it as ready.

      But it does the same if I change URL to nonexistant.

      What I'm doing wrong here?


              public function startLoadingVideo():void {
                  netLoader = new NetLoader();
                  var urlResource:URLResource = new URLResource("http://mysite.coml/myvideo.flv");
                  var videoPart:VideoElement = new VideoElement ( urlResource, netLoader );
                  var videoPartLoadTrait:LoadTrait = videoPart.getTrait( MediaTraitType.LOAD ) as LoadTrait
                  videoPartLoadTrait.addEventListener(LoadEvent.LOAD_STATE_CHANGE, onLoadStateChange);
                  trace("Video bytes loaded: " + videoPartLoadTrait.bytesTotal);     




              public function onLoadStateChange(event:LoadEvent):void {
                  trace( "VideoElement is: " + event.loadState  + " -bytes- " + event.bytes);


      Thank you in advance,


        • 1. Re: Loading VideoElement and URL



          That is because of flash way to play video.

          The Load trait in case of video element prepares server connection when using RTMP and creates objects required for playback NetStream, client for it etc. Actual stream request goes in PlayTrait. In case of progressive video (your case): netStream.play("http://server.com/file.flv") command issued upon PLAY request, resulting in StreamNotFound error if pointed to nonexisting file. so there is no actual "loading" of video in the first place.

          • 2. Re: Loading VideoElement and URL
            kioshin10 Level 1



            Thank you very much for answer. But what functions to use if I want to just preload

            bunch of files and only after start to play (i.e. they all have been preloaded)?


            Thank you in advance,


            • 3. Re: Loading VideoElement and URL
              Mykola3296 Level 2

              I'm afraid there is no direct way to do it in OSMF.

              I guess you need something like:

              1) A bunch of proxy elements that implement custom load traits.

              2) Set a buffer time of video elements to something enough for you - so playback does not start before it is enough video buffered.

              4) Begin playback in LoadTrait while "blocking" all other traits - playback would not start unless the buffer is filled.

              3) Manage the BufferFull stream message in custom load trait, pause a stream and rise LoadState.READY upon that event.

              4) "Unblock" the rest of VideoElement traits.

              Then if you put your videos in parallel they should not start while all of them are in LoadState.READY.

              Something like this, I guess.

              Also there have been other posts here concerning the prebuffering already - so you may serch for them.


              Best regards!