Mailing List
Home
Forum Home
Flash Pro
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
FLV file stops loading when you pause

FLV file stops loading when you pause

2005-11-02       - By Joe Laffey

 Back
Reply:     1     2     3     4     5  

On Wed, 2 Nov 2005, Stevio wrote:
> -- -- Original Message -- -- From: "Joe Laffey" <joe@(protected)>
> To: "Mailing list for professional Flash designers and developers"
> <flashpro@(protected)>
> Sent: Wednesday, November 02, 2005 3:53 PM
> Subject: Re: [flashpro] FLV file stops loading when you pause
>
>
>> On Wed, 2 Nov 2005, Stevio wrote:
>>
>>> Something I have noticed with playing videos through Flash 8 using a FLV
>>> file, is that if you start playing the video, but then pause it using the
>>> default controls they give you, then the video stops preloading.
>>>
>>> This is annoying because if you start playing a video file, and the video
>>> has not loaded enough yet and your connection is slow, you would perhaps
>>> pause it to allow it to load further, but instead it just stops
>>> preloading.
>>>
>>> Any suggestions?
>>
>>
>> Does this happen when you load the FLV manually using NetStream ?
>>
>> I am still using Flash Pro MX2004. But I have had very good luck making a
>> playback mechanism using NetStream. I mainly did this because other
>> players, like the MediaPlayer in Flash, or Quicktime itself, tend to start
>> playback WAY too soon when "streaming" (progressive download where it
>> starts to play before being downloaded all the way). This leads to hiccups
>> in the playback because the buffer gets emptied. So I built my own player
>> with a bigger buffer. I measure the bandwidth using a SetTimeout, average
>> it over the last few seconds, and then calculate the remaining time based
>> on the bytesLoaded and bytesTotal.
>>
>> Hope this is of some help...



> Actually I am not sure if what I said is right. The clip may still be loading
> even when I hit pause.
>
> Are you able to share any code on how you did things?
>


Here are some code snippets. Feel free to use them, but maybe stick a
credit someplace (even in comments).

Much of this stuff is from MM's example code.


This is the frame script from frame 1. This frame should cover up the
movie with another graphic or image. Also, you don't want to show your
playback controls (if any) until the frame labeled "ready".



//set the progress bar to a scale of 0.
prog._xscale = 0;

// Create a NetConnection object
var netConn:NetConnection = new NetConnection();
// Create a local streaming connection
netConn.connect(null);
// Create a NetStream object and define an onStatus() function
var ns:NetStream;
ns = new NetStream(netConn);

// Attach the NetStream video feed to the Video object
tester.attachVideo(ns);

// Set the buffer time to a huge value so the movie will not start playing
ns.setBufferTime(1000); //time is seconds

// Begin playing the FLV file
ns.play("myfile.flv");

//Tell the movie to pause so it doesn't start playing until we want it to.
ns.pause(true);


//These keep track of the download speed.
//They will cause an erroneously slow speed to be reported for a while
//since they are averaged with the current speed. This is a safety measure
//to be sure we don't start plaback too early.
var oldBytes = 0;
var oldSpeed = 0;
var oldSpeed2 = 0;
var oldSpeed3 = 0;
var oldSpeed4 = 0;
var oldSpeed5 = 0;
var speed = 0;
var count = 0;


//This is the function called from the timeout. It checks the progress
//and starts the playback when ready.
checkProgress = function (ns:NetStream) {

  //bytesTotal is -1 if the file has not started downloading.
  if(ns.bytesTotal == -1)
    return;

 oldSpeed5 = oldSpeed4;
 oldSpeed4 = oldSpeed3;
 oldSpeed3 = oldSpeed2;
 oldSpeed2 = oldSpeed;
 oldSpeed = speed;

 //I make local copies of these under the (untested) assumption that the
 //indirection of the properties of ns is slower... need to test
 var bl = ns.bytesLoaded;
 var bt = ns.bytesTotal;

 //Simple average... This should probably have some kind of quadric decay
 speed = Math.floor(((bl - oldBytes)+oldSpeed+oldSpeed2+oldSpeed3+oldSpeed4
+oldSpeed5)/6);
 oldBytes = bl;



 var remaining = bt - bl;
 count++;

 //Here we calculate how big the buffer should be in seconds.
 //The 1.3 is the extra 30% (vary this number to taste) to be sure that
 //we really do have enough bandwidth to finish loading the movie before
 //start playing.
 var bufTime = Math.floor(1+1.3*(remaining/speed));

  //hack to avoid doing this after just one call.
  if(count>1)
    ns.setBufferTime(bufTime);

  if(ns.bufferLength >= ns.bufferTime || bl >= bt)
  {
   count = -9999999; //avoid calling setBufferTime again
    if(bl >= bt)
    {
        clearInterval(poll);

    }

           trace("loaded");

           //ready is the frame where the shape used to hide the movie is
           //now turned off and the controls are revealed.
           gotoAndPlay("ready");
  }

  //prog is a progress bar symbol. This sets its scale to have it move
  prog._xscale = (bl/bt)*100;
  trace("%" + percentLoaded + " loaded.");
};

// Load streaming FLV file and start calling checkProgress()

var poll = setInterval(checkProgress, 1000, ns);



//We want the play head to stay on the start frame, which should have
//a graphic that covers up the playback controls and hides the movie
//while it is loading.
//This can show a still image or something...

stop();





The frame labeled "ready" needs a frame script like this:

stop();
ns.pause(false);

This will stop the play head, as well as cause the movie to start playing.


I hope this helps.

Note that if the movie is big or has a heavy data rate it can sometimes
stutter while it is still downlaoding. I have only seen this on Macs,
which seem to still be slower at playing Flash than PCs. The gap has
gotten better thanks to MM finally putting some effort into the Mac
player.

--
Joe Laffey                |        Visual Effects for Film and Video
LAFFEY Computer Imaging   |        -- ---- ---- ---- ---- ---- -----
St. Louis, MO             |        Show Reel at http://LAFFEY.tv/?s
USA                       |        -- ---- ---- ---- ---- ---- -----
                          |         -*- Digital Fusion Plugins -*-
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Mail here will be rejected --> "Real Trap" <r_trap@(protected)>

-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
send message to the list:               mailto:flashpro@(protected)
[FlashPro] list info, subscribe, archive:   http://flash-list.com/
There's also a WebPro mailing list:     http://webdesign-list.com/
cutting-edge sounds for flash:            http://flash-sounds.com/

Earn $52 per hosting referral at Lunarpages.