Skip navigation
Currently Being Moderated

Flv preloader

Jun 18, 2012 10:24 AM

Hello,

 

I have a project in as2.  It is a quiz that has a video asking the question, one for an correct answer and one for an incorrect answer.  This quiz has 25 question, with 75 videos possible.  I am having problems with the video sticking on the later questions.  I have another discussion on here and have done quite a few things to try to fix this.  My question is, is there a way I can preload a flv file that I have on my website to my flash project, so it is completely loaded before it is needed.  In other words  If question 1 is on frame 100 and with the three frames I will need for my question, correct answer and incorrect answer, I put question 2 on frame 110.  Could I have the 3 videos start to load for question 2 while the user is still on question 1 on frame 100?  So by the time the user answers the question and sees the video answer question 2  videos would be fully loaded.  I have looked for tutorials about this, but have only found ways to make a status bar. 

 

Thanks for your help.

 

 

Mark.

 
Replies
  • Currently Being Moderated
    Jun 18, 2012 11:09 AM   in reply to MARKARKARK

    So the .flv is embedded into the main timeline?

    What do you mean by "problems with the video sticking on the later questions"?

    Are you testing locally and having these problems? or are you testing from a Web server?

    Are you having any sync problems? wrong vid for the question, etc?

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 18, 2012 12:02 PM   in reply to MARKARKARK

    I think that I am understanding most of what you are trying to do.

    So question 1 plays and then a correct or incorrect answer video plays... and so forth and so on???

    Are you using the FLVPlayback component for all the videos?

    and there are 75 vids? Are there cuepoints in each vid? and that cue point moves to another point on the main timeline and in that frame there is a new FLVPlayback component playing the next question?

    Does every video have to download and play in total?

    So all of question 1 vid and all of answer 1 vid has to download and play? or can you answer before the end of question 1 and do you have to watch all of answer 1 before moving to answer 2?

    If you go thru the quiz very slowly, giving all videos plenty of time to download, do you still have delay problems with later questions?

    Are there any other vids loading if you are on Question 10, for example? are 8 & 9 still loading?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 18, 2012 2:17 PM   in reply to MARKARKARK

    I am not mentioning FLVPlayback as a recommendation, rather as a clarification.

    There are only 3 ways to display Flash video that I am aware of.

    1. embed into timeline

    2. use the FLVPLayback

    3. use NetStream

    I'm still not sure which method you are using. The reason this is important to understand is that the method of controlling the video is different for each.

    If the user does not have to wait until the question plays out fully

    You can answer the question midway through each question,

    that means that the answer video could start playing while the previous question video is also loading.

    Over a period of time, say by question 13 or 14, the lag could be because all those question video have to finish downloading... as well as all the answer videos.

    Unless you explicitely stop the download process, each video that is called and starts to download, will continue to download until completion. Pausing or stopping the video may not be stopping the download.

    In the cue points and button actions, is there an explicit command to stop the download, not just the "pause" the video?

    Here is an example of what I am talking about:

    http://www.mrfilmbiz.com/

    Open the page and you'll see a video loading status bar. Above the word "Hollywood" you'll see a "Skip Intro" button. Click the button before the intro loads fully and you'll see that the download is stopped. Now click the "Play Intro" button and you'll see the video start downloading again.

    Pausing the video stops the video from playing yet does NOT stop the downloading.

    This example illustrates that button actions can and should include explicite instructions to FIRST stop the downloading and then do whatever other button action you want.

    So your answer buttons should include as the first line of instruction.... stop the video downloading.

    Here is the actionscript for the "Skip Intro" button.... the video is being played via the NetStream method I mentioned earlier

    skip_btn.onRelease = function() {

    ns.close();

    gotoAndStop("end");

    }

    The important part is that ns.close(); is used as the very first line of button action. This closes the NetStream, stopping the download of the rest of the file.

    I think your lag is due to having so many videos that must download completely. By the time you get to questions 15... there are multiple earlier videos that have not yet finished downloading... hence there is just not enough bandwidth available to accomplish that PLUS download a new question.

    Of course none of this is has to do with "pre-loading". Even if you do preload, there is still the problem of having to download all 75 vids completely.... which may be beyond the bandwidth/time constraints of some users.

    So I still recommend adding the stop download line to the buttons.

    And here is a loader you may want to look into:

    http://www.greensock.com/loadermax/

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 18, 2012 3:45 PM   in reply to MARKARKARK

    The code to stop loading the video needs to go on the answer button (as I illustrated above).... so you answer "A" or "B".... which ever answer you choose it first stops the downloading of the current video BEFORE it even plays the answer video.

    You will find that using NetStream is a much more versatile and powerful means of interacting with video than the FLVPlayback (which I think you are using now).

    There are some great AS2 NetStream video tutorials here:

    http://www.gotoandlearn.com/

    Scroll to the very bottom of the page. Thsoe video tutorials will show you how to create your own custom NetStream vid player.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 1:28 PM   in reply to MARKARKARK

    Been awhile since I've worked with cue points but I think there is a difference in how you use cue points between NewStream and the FLVPlayback component (which you were using before).

    Here is a working version I use to load a couple different .swf files (each which happens to hold another video).

    ns.onCuePoint = function(evt:Object){
        trace(evt.name);
        trace(evt.time);
        if(evt.name == "play_vid1") {
            trace("YO!Loading wide_holder!");
            wide_holder.loadMovie("rm/images/black_bear.swf");
        }

        if(evt.name == "play_vid2") {
      trace("YO!Loading standard_holder!");
            standard_holder.loadMovie("rm/images/sqis.swf");
        }
    };

    Off the top of my head I believe it was this line that I had to change to work with NetStream:

    function(eventObject:Object):

    notice the slight difference in syntax.

    Sorry I don't have any more info. I'd suggest you Google "using Flash cue points with NetStream (NOT the FLVPlayback component)".

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 19, 2012 2:15 PM   in reply to MARKARKARK

    answer_btn.onRelease = function() {

    ns.close();

    gotoAndStop("A10");

    }

    Remember that this is the answer button action. The first line of code just defines that it's a function. "answer_btn" is the instance name of the button.

    The very first line of the function is

    ns.close();

    BEFORE the timeline moves on to the frame labeled "A10"... a name I am using for the answer to Question 10.

    For example... I see the question 10 video... then I choose an answer, before the end of the whole question video. The button action stops the question video from downloading further and takes me directly to answer 10.

    Thinking more about using cue points:

    the answer must play out completely

    If the only reason you are using cue points is to detect the end of the Answer 10 video and then move to Question 11... you don't even need cue points for that.

    Add this code to the same actionscript you are using to play the Answer 10 video... below the netstream player code:

    ns.onStatus = function(info) {

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

      trace("Video complete")   

      gotoAndStop("Q11"); 

      }

    }

    ........when NetStream info funtion detects that the Answer 10 video has stopped at the end...

    trace "Video complete"

    and then gotoAndStop (or gotoAndPlay) Question 11.

    All the above code is actual, working code. You may need to change instance names, etc to match what you are using, but you should be able to adapt this code to your needs.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 7:06 AM   in reply to MARKARKARK

    I see that you are using frame numbers... I'd suggest that in the future you use frame labels instead. For example, when debugging the code gotoAndStop(100); is not as meaningful as gotoAndStop("Q10");

    Note that you need the double quotes when using frame labels.

    OK, here is a working NetStream cue point:

    var ns:NetStream = new NetStream(nc);

    video_screen.attachVideo(ns);

    /* Name of your video, with correct path, goes here */

    ns.play("my_video.flv");



    ns.onCuePoint = function(evt:Object){

        trace(evt.name);

        trace(evt.time);

        if(evt.name == "jump_100") {

            trace("YO !Jump to 100!");

            gotoAndStop(100);

        }  

    };

    Reading this code:

    set a new variable "ns" which is a new NetStream

    attach a video to "video_screen"... the instance name of the video on the stage

    now use that variable "ns" to play a video with file name "my_video.flv"

     

    use ns to listen for an "event" type cue point Object

    when the cue point is detected trace the event name and time

    if the event name is exactly equal to "jump_100"

    then trace "YO !Jump to 100!"

    and then gotoAndStop at frame 100

     

    For this exact code to work, your NetStream variable must be named "ns"

    In the video you play, there must be a cue point of the "Event" type with the name "jump_100"

    There must be at least 100 frames in the timeline.

     

    Take it in small steps;

    First make sure you can play the video using NetStream ... that's all.

    Next, add the trace to detect the cue point... if you can't detect it, of course it won't do anything.

    Only after you can successfully play the video and detect the cue point, should you attempt the cue point action (jump to frame 100).

     

    Hope this gets you closer.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 8:03 AM   in reply to MARKARKARK

    You are most welcome!

    Glad you got it working.

    If you found any of my posts as answering or helpful, please mark them so others looking for help will also know where to look.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 10:15 AM   in reply to MARKARKARK

    Use "if" statements, as in

    ns.onCuePoint = function(evt:Object){
        trace(evt.name);
        trace(evt.time);
        if(evt.name == "play_vid1") {
            trace("YO!Loading wide_holder!");
            wide_holder.loadMovie("rm/images/black_bear.swf");
        }

        if(evt.name == "play_vid2") {
      trace("YO!Loading standard_holder!");
            standard_holder.loadMovie("rm/images/sqis.swf");
        }
    };

    if cue 1 do this

    if cue 2 do this, etc.

    Best wishes,

    Adninjastrator

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 20, 2012 11:01 AM   in reply to MARKARKARK

    Use multiple "if" statements in the same onCuePoint function... just one function, multiple choices for that function

    ns.onCuePoint = function(evt:Object){

        trace(evt.name);

        trace(evt.time);

        if(evt.name == "c1") {

            trace("YO !Jump to 25!");

            gotoAndPlay(25);

        }

    if(evt.name == "c2") {

            trace("YO !Jump to 38!");

            gotoAndStop(38);

        }

         MORE IF STATEMENTS CAN GO HERE....

    };

    If the cue is c1, do this, if c2 do this other thing, etc. down a list of if statements

    You can have as many if's as needed and you could also add an "else" statement (if the cue doesn't match any of the if statements) at the end, before the final closing bracket if you wanted.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points