13 Replies Latest reply on Jun 14, 2009 9:35 PM by mentlity

    Preloading an flv in AS 2.0

    mentlity Level 1

      I have a main.swf that loads other swfs in level 1 . The main.swf automatiaclly loads movie1.swf which has an flv inside. I used an old FL8 scene AS code like this

       

       

      myInterval = setInterval(preload,100);

       

                              
      function preload() {
      if(_root.getBytesLoaded() >= _root.getBytesTotal()){
      gotoAndStop("main",1);

       

      clearInterval(myInterval);
          }
      }

       

       

      is there a way to set the interval to the buffer in the flv lets say when the buffer reaches 50% then play the flv?

       

      because the preloader is not checking for the flv to load it is checking the frames loading and the flv is on one frame follow?

       

      rdere

        • 1. Re: Preloading an flv in AS 2.0
          mentlity Level 1

          OK, I see the bufferLength (NetStream.bufferLength property) should be used here. The flash live doc has a different code for adding a text field and what I wanted to do was to add a posterframe but I see with this function I wont have to as all I need is a graphic or a clip that loops "LOADING"

           

          What I want to do is this:

           

          (Inside the swf with the flv) have a piece of text blink LOADING until the net buffer reaches the point I want it to before the flv plays.

           

          Any help coding this?

          • 2. Re: Preloading an flv in AS 2.0
            kglad Adobe Community Professional & MVP

            there's not really much you can do with this unless you're streaming your flv over rtmp.  otherwise, you can either preload the flv until its completely downloaded (and then play it so it's, in essence, 100% buffered) or you're going to use progressive download to play and download at just about same time.

            • 3. Re: Preloading an flv in AS 2.0
              mentlity Level 1

              yes my flv is being streamed insode the swf from a server. I did manage to find this tutorial

               

              http://www.gotoandlearn.com/play?id=6

               

              I just need to alert the user that the flv is loading so however long it takes to get at least have the flv loaded is when the text will move to the actual flv starting to play.

              • 4. Re: Preloading an flv in AS 2.0
                mentlity Level 1

                That tutorial starts with the code already in the swf from making a video player, I'm in CS3 using as 2.0. and cannot find where the preceding videos show adding the entire code. So as you were saying last post will I be able to preload the flv so a piece of text will blink LOADING until at least 50% of the flv is downloaded?

                 

                My flv is being downloaded from a server.

                 

                any help?

                • 5. Re: Preloading an flv in AS 2.0
                  mentlity Level 1

                  Tried this

                   

                  this.createTextField("buffer_txt", this.getNextHighestDepth(), 10, 10, 300, 22);
                  buffer_txt.html = true;

                   

                   

                  var connection_nc:NetConnection = new NetConnection();
                  connection_nc.connect(null);
                  var stream_ns:NetStream = new NetStream(connection_nc);
                  stream_ns.setBufferTime(8);
                  my_video.attachVideo(stream_ns);
                  stream_ns.play("bkren.flv");

                   

                  var buffer_interval:Number = setInterval(checkBufferTime, 100, stream_ns);
                  function checkBufferTime(my_ns:NetStream):Void {
                      var bufferPct:Number = Math.min(Math.round(my_ns.bufferLength/my_ns.bufferTime*100), 100);
                      var output_str:String = "<textformat tabStops='[100,200]'>";
                      output_str += "Length: "+my_ns.bufferLength+"\t"+"Time: "+my_ns.bufferTime+"\t"+"Buffer:"+bufferPct+"%";
                      output_str += "</textformat>";
                      buffer_txt.htmlText = output_str;
                  }

                   

                  My flv name is bkren.flv

                   

                  it is in the first frame of the swf

                   

                  I added it to the code (in RED)

                   

                  now I hear two instances of the flv playing which means I obviously have to remove one flv.(the one I have in the first frame of the swf? I also changed the buffertime to 8 seconds .

                   

                  I do see black text in the upper left of the swf displaying the time and buffer.

                   

                  Am i on the right track here?

                  • 6. Re: Preloading an flv in AS 2.0
                    kglad Adobe Community Professional & MVP

                    you won't hear two flvs unless you have some other code or an flvplayback component on stage.

                    • 7. Re: Preloading an flv in AS 2.0
                      mentlity Level 1

                      OK after searching around I think I have the correct code to preload by buffer time.

                       

                      But if I test it from the server the buffer runs for about 5 seconds and disappears. Then the video plays but I do not see it I can only hear it. Now the flv is not on the stage, it is being called aby the AS in blue is this correct?

                       

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

                       

                      var ns:NetStream = new NetStream(nc);
                      ns.setBufferTime(30);

                       

                      ns.onStatus = function (info){
                          if(info.code == "NetStream.Buffer.Full"){
                              bufferclip._visible = false;
                          }
                          if(info.code == "NetStream.Buffer.Empty"){
                              bufferclip._visible = true;
                          }
                         
                          if(info.code == "NetStream.Play.Stop"){
                              ns.seek(0);
                          }

                       

                      }

                       


                      theVideo.attachVideo(ns);

                       

                      ns.play ("correctname of flv");

                      • 8. Re: Preloading an flv in AS 2.0
                        mentlity Level 1

                        OK I now see the tut I got this from is

                        http://library.creativecow.net/articles/brimelow_lee/video_basics_6.php

                         

                         

                        I found the first tutorial and it is done in MX , and the tuts are based around building the navigation from scratch in MX and not using the components. I'm in CS3  so I need to get this done using the components , at least the flv playback unless there is another way.

                        • 9. Re: Preloading an flv in AS 2.0
                          kglad Adobe Community Professional & MVP

                          that code uses the video class, not an flvplayback component.  remove your flvplayback component from the stage, click your library's upper right, click new video, click ok.  drag the video object from the library to your stage and give it an instance name of theVideo.

                          • 10. Re: Preloading an flv in AS 2.0
                            mentlity Level 1

                            Ah now we are getting somewhere, the flv is on the client's server 

                            below is the complete code in the first frame of the fla

                             

                            I did as you wrote, remove the flv playback component from the stage, 

                            library, new video, gave it same instance name as the name in the as. 

                            Uploaded and the buffer preloader works as I set it for 25 seconds  

                            then disappears and the flv plays. The second time I tried the flv 

                            loaded in 3 seconds then I realized I needed to clear out the cache 

                            and it seems to be working.

                             

                            Question, now that I have this part done I lose the flv playback 

                            buttons and skins so do I just follow the tute for adding those 

                            components?

                             

                             

                            any help ? almost there!

                             

                            var nc:NetConnection = new NetConnection();

                            nc.connect(null);

                             

                            var ns:NetStream = new NetStream(nc);

                            ns.setBufferTime(25);

                             

                            ns.onStatus = function (info){

                                 if(info.code == "NetStream.Buffer.Full"){

                                      buffer_mc._visible = false;

                                 }

                                 if(info.code == "NetStream.Buffer.Empty"){

                                      buffer_mc._visible = true;

                                 }

                                  

                                 if(info.code == "NetStream.Play.Stop"){

                                      ns.seek(0);

                                 }

                             

                            }

                             

                             

                            theVideo.attachVideo(ns);

                             

                            ns.play ("Brooklyn Renaissance for web2.flv");

                            • 11. Re: Preloading an flv in AS 2.0
                              kglad Adobe Community Professional & MVP

                              you can create your own buttons etc and use the netstream properties and methods to encode their actions.

                               

                              or you could use an flvplayback component but not with that code.

                              • 12. Re: Preloading an flv in AS 2.0
                                mentlity Level 1

                                OK looks like I gotta use the netstream properties navigation which is 

                                fine. So I learned alot from this and I thank you for the help it is 

                                appreciated.

                                 

                                 

                                thx

                                 

                                rdee

                                • 13. Re: Preloading an flv in AS 2.0
                                  kglad Adobe Community Professional & MVP

                                  you're welcome.