9 Replies Latest reply on Aug 24, 2009 4:20 PM by kglad

    AS2/CS4 Netstream problem...

    gray14

      I'm currently building a custom flv player and need some help.  Maybe I'm missing something, I'm not sure.  The main problem is that the FLV doesn't load/play, which most likely causes the secondary problems, such as the bufferClip always visible and no way to test the video and audio scrubbers.

       

      ----CODE----

      var nc: NetConnection = new NetConnection();
      nc.connect(null);
      var ns: NetStream = new NetStream(nc);
      ns.setBufferTime(5);

      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"){
        gotoAndStop("end");
      }
      }

      //video location
      videoPlace.attachVideo(ns);
      ns.play("URL of FLV");

      //audio control
      _root.createEmptyMovieClip("vSound",_root.getNextHighestDepth())
      vSound.attachAudio(ns);

      var so:Sound = new Sound(vSound);
      audioControl.audioScrub.onEnterFrame=function(){
      so.setVolume(100-this._y);
      }

      audioControl.audioScrub.onPress=function(){
      this.startDrag(false,this._x,0,this._y,100);
      }

      audioControl.audioScrub.onRelease = audioControl.audioScrub.onReleaseOutside = function(){
      this.stopDrag();
      }

      //restart button
      controlBar.restartBtn.onRelease = function(){
      ns.seek(0);
      }

      //Play and Pause button
      controlBar.playpause.onRelease = function(){
      ns.pause();
      }

      //setup the video interval
      var vidInt = setInterval(videoStatus, 100);
      var amtLoad:Number;
      var duration:Number;
      ns["onMetaData"] = function(obj){
      duration = obj.duration;
      }

      function videoStatus(){
      amtLoad = ns.bytesLoaded/ns.bytesTotal;
      loader_mc.loadBar._width = amtLoad * 560;
      loader_mc.scrubber._x = ns.time/duration * 560;
      }

      //scrubber code
      var scrubInt;

      loader_mc.scrubber.onPress = function(){
      clearInterval(vidInt);
      scrubInt = setInterval(scrubIt,10);
      this.startDrag(false,0,this._y,560,this._y);
      }

      loader_mc.scrubber.onRelease = loader_mc.scrubber.onReleaseOutside = function(){
      clearInterval(vidInt);
      vidInt = setInterval(videoStatus,100);
      this.stopDrag();
      }

      function scrubIt(){
      ns.seek(Math.floor((controlBar.loader_mc.scrubber._x/560) * duration));
      }

      ----END CODE----

       

      Thank you for your help in advance.  If you need anymore info, just let me know.
      ~gray14

        • 1. Re: AS2/CS4 Netstream problem...
          kglad Adobe Community Professional & MVP

          what's the following line suppsed to do

           

          ns.play("URL of FLV");

          • 2. Re: AS2/CS4 Netstream problem...
            gray14 Level 1

            I'll replace what's inside the quotes with the actual FLV URL (for example, http://www.thissite.com/video.flv)

            *not an actual link

            • 3. Re: AS2/CS4 Netstream problem...
              kglad Adobe Community Professional & MVP

              put an flv in the same directory as your embedding html and use that file name in your play method and retest.  make sure you have a video class instance on stage with instance name:

               

              videoPlace

              • 4. Re: AS2/CS4 Netstream problem...
                gray14 Level 1

                Okay, I did that.  The video loads and plays, which is good.  Now a couple more problems come to light:

                 

                1) The video scrubber (_root.loader_mc.scrubber) drags where it should, but the video doesn't react as it should.  The video should play at the time that corresponds with the position of the scrubber.

                 

                2) There is no sound, which I'm guessing has to do with that audioControl and audioScrub code I wrote.

                 

                Never mind that second one.  I had the sound turned off on my PC ((stupid me, lol)).  I have another question, purely for asthetic reasons:

                 

                How do I write the code so the playpause button changes from a play symbol to a pause symbol when paused and vice versa?

                • 5. Re: AS2/CS4 Netstream problem...
                  kglad Adobe Community Professional & MVP

                  1.  sometimes you refer to loader_mc.scrubber and sometimes controlBar.loader_mc.scrubber.  at most, one is correct.

                   

                  2.  among the ways to do this would be to create two keyframes on your playpause timeline.  one would correspond to the play graphic, the other the pause graphic.

                  1 person found this helpful
                  • 6. Re: AS2/CS4 Netstream problem...
                    gray14 Level 1

                    Oh, wow, didn't realize I did that.  Okay, that's fixed.

                     

                    As for the playpause, I have it set up as an MC with 4 frames: playon, playoff, pauseon, pauseoff.  The "on" frames are for the .onPress function and the "off" frames are for the .onRelease, .onReleaseOutside, .onRollOver and .onRollOut functions.  I'm guessing in order for the right state to show ("playoff" when video is playing, "pauseoff" when video is paused), I'd need an if/else statement.  How would I set that up?  Would I use something like this?

                     

                    ---CODE---

                    controlBar.playpause.onPress=function(){
                    if(ns.pause()){

                    controlBar.playpause.gotoAndStop("playon");

                    ns.play();

                    }

                    else{

                    controlBar.playpause.gotoAndStop("pauseon");

                    ns.pause();

                    }

                    ---END CODE---

                    • 7. Re: AS2/CS4 Netstream problem...
                      kglad Adobe Community Professional & MVP

                      use toggle-logic:

                       


                      controlBar.playpause.onPress=function(){
                      if(this.toggle){  // or !this.toggle if this starts paused

                      controlBar.playpause.gotoAndStop("playon");

                      ns.play();

                      }

                      else{

                      controlBar.playpause.gotoAndStop("pauseon");

                      ns.pause();

                      }

                      this.toggle=!this.toggle

                      }

                       

                      1 person found this helpful
                      • 8. Re: AS2/CS4 Netstream problem...
                        gray14 Level 1

                        That worked!

                         

                        Thank you so much for all your help

                        • 9. Re: AS2/CS4 Netstream problem...
                          kglad Adobe Community Professional & MVP

                          you're welcome.