A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: setBufferTime for MediaPlayback Component

  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    18

    setBufferTime for MediaPlayback Component

    Is there a way to set the Buffer to a MediaPlayback component?
    And if there is can you give me some examples or code?
    I cannot figure it out it's driving me nuts.

    I dragged the component onto the stage on frame 5
    Filled the parameters in with the flv file info

    I need it to play after it buffers 40 sec.

    Your help would be greatly appreciated.
    Thanks

  2. #2
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67

    Re: setBufferTime for MediaPlayback Component

    Originally posted by hightech
    Is there a way to set the Buffer to a MediaPlayback component?
    And if there is can you give me some examples or code?
    I cannot figure it out it's driving me nuts.

    I dragged the component onto the stage on frame 5
    Filled the parameters in with the flv file info

    I need it to play after it buffers 40 sec.

    Your help would be greatly appreciated.
    Thanks
    As far as I know, Macromedia did not supply any native methods to control the streaming of media into the MediaPlayback component.

    Here is a possible solution off the top of my head. Select your MediaPlayback Component on the main stage, and locate the Actions Panel. Then, try this script and see if it works:
    Code:
    on(load){
    this.setMedia("path/url","FLV");
    this.autoPlay = false;
    bufferTime = 40; //your requested buffer time, arbitrary
    this.totalTime = //whatever the total time is in seconds
    //you can't get 'actual' totalTime until the entire movie is loaded!
    //so you must know the totalTime beforehand
    //if you plan to use it programmatically
    }
    
    onClipEvent(enterFrame){
    //onClipEvent works with components, too!
    //this will continually refrsesh all values as movie is loading
    bytesPerSecond = this.bytesTotal/this.totalTime;
    if(bytesLoaded > (bytesPerSecond * 40)){
      this.play();
      }
    }
    This is a "brain dump", so if anyone can spot any goofs in my code, please share them with the community!

    Hey--this code comes per gratis, so I'm leaving it up to you to determine its validity!

  3. #3
    Member
    Join Date
    Jan 2001
    Posts
    18
    Hey Berry thanks for the reply I've been trying the code with no success but, I'm going to play around with the code a little bit I will post what I come up with.
    In the mean time if you have any other suggestions that would really help.

    Maybe you could help me here, instead of using the mediaplayback is there another way to play an flv using playback buttons similar to the components buttons and if there is can you give me some examples?

    Any other suggestions are welcome
    Thank you so much.

  4. #4
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67
    Originally posted by hightech
    Hey Berry thanks for the reply I've been trying the code with no success but, I'm going to play around with the code a little bit I will post what I come up with.
    In the mean time if you have any other suggestions that would really help.

    Maybe you could help me here, instead of using the mediaplayback is there another way to play an flv using playback buttons similar to the components buttons and if there is can you give me some examples?

    Any other suggestions are welcome
    Thank you so much.
    I goofed on the math! You'll want total KBytes per second, not actual bytes.

    You will have to round-up bytesTotal divided by 1024; i.e.:
    Code:
    Math.ceil(myMovieClip.bytesTotal/1024)
    ....My brain is still fuzzy without a project right in front of me! If I get some time, I will see what I can come up with.....

  5. #5
    Junior Member
    Join Date
    Sep 2003
    Location
    Fresno
    Posts
    8
    I am making a similar attempt, here is the code I am using:

    on(load){
    this.setMedia("mm_hour_ofthe_witch","FLV");
    this.autoPlay = false;
    bufferTime = 40; //your requested buffer time, arbitrary
    this.totalTime = 497;//whatever the total time is in seconds
    //you can't get 'actual' totalTime until the entire movie is loaded!
    //so you must know the totalTime beforehand
    //if you plan to use it programmatically
    }

    onClipEvent(enterFrame){
    //onClipEvent works with components, too!
    //this will continually refrsesh all values as movie is loading
    bytesPerSecond = math.ceil(this.bytesTotal/1024);
    if(bytesLoaded > (bytesPerSecond * 40)){
    this.play();
    }
    }
    I set the totalTime to 497, which I think means 8 seconds and 17 frames. Other than that, every thing is the same.

    The output window is saying that the '}' bracket on line 9 is unexpected. It is also telling me that the onClipEvent only works on movie clips, but your comment says it works on components too.

    Any help would be much appeciated.

  6. #6
    Junior Member
    Join Date
    Sep 2003
    Location
    Fresno
    Posts
    8
    Okay, I am getting closer. I am using the NetConnection to trick my movie into thinking that the external flv is coming from the Flash Communication server.

    var nc:NetConnection = new NetConnection();
    nc.connect(null);
    var ns:NetStream = new NetStream(nc);
    ns.setBufferTime(3);
    vid.attachVideo(ns);
    ns.play("external_flashvideo.flv");
    vidlength=8.17; // set the duration in seconds of your flv
    playStatus = true;
    I pickec up this trick at http://www.bit-101.com/blog/archives/000074.html

    Now I would like to have a preloader for my flv file. Is that possible? If so, please lend a hand...

  7. #7
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67
    Are you trying to delay playback of the video based on an arbitrary amount of time? i.e. 40 seconds before playback. Because if so, there are probably much easier ways to do this.

    As far as I know, Flash FLV videos stream by default. So the video should start playing as immediately as it is available, and buffer as it plays--faster than other media streaming solutions out there, including Real, QuickTime, and Windows Media.

    This would only make sense if the video you are wanting to play is "choking" for some reason, i.e. from a CD. I have had .FLV files that choke when playing back from a CD. But again, that was only at the beginning--as the video was loading. Once it was loaded, however, it streams nicely and buffers as it goes.

    This would make timed buffering entirely a moot point. But if you want to delay the video arbitrarily for 40 seconds, then there should be a different approach.

  8. #8
    Member
    Join Date
    Jan 2003
    Posts
    54
    berry: what sort of different approach did you have in mind?

    my flv with the component is choking cause it starts playing immediately even when it's not buffered enough. therefore i need a way to tell it to buffer enough for example 5 seconds before it starts playing and buffers the rest.

    please advise, thanks.

  9. #9
    Member
    Join Date
    Mar 2002
    Location
    Dayton, Ohio.
    Posts
    67
    Originally posted by daniel@cga
    berry: what sort of different approach did you have in mind?

    my flv with the component is choking cause it starts playing immediately even when it's not buffered enough. therefore i need a way to tell it to buffer enough for example 5 seconds before it starts playing and buffers the rest.

    please advise, thanks.
    Here is the easiest way to do this by far:

    --FIRST: Select your Media component and then open the Actions panel. Add the following lines of code:

    Code:
    on (load){
     this.autoPlay = false;
    }
    *NOTE that you can also do this by launching the "Component Inpsector" from the Properties panel or by choosing "Development Panels" from the file menu under "Windows". In the Component Inspector, there is a checkbox labeled "Automatically Play". Uncheck it.

    --LASTLY: Be sure to give your Media component an instance name. On the timeline where your Media component is located, add enough frames to equal 5 or more seconds (or the amount of time it takes for your video not to "choke"). Create a new layer and label it "Actions", and then place a blank keyframe in the last frame. Now add the following Frame actions to that blank keyframe:

    Code:
    yourMediaComponentInstanceName.play();
    stop(); //only if needed
    And that's it!

    Flash will continue to stream video (media) to the Media component even though it isn't playing right away. Once a certain amount of time has passed, you can trigger the Media component to play using the above ActionScript code.

    Good hunting!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center