preloading video for speed?

They have: 46 posts

Joined: May 2002

Hi, I recently read something about using JavaScript to preload images for speed. For example, if you want a onmouseover effect the new image would already be downloaded and the effect would be instantaneous.

Code looks like this:

<script LANGUAGE="JavaScript">
hoverfx = new Image;
hoverfx.src = "new_image.jpg";
</script>



QUESTION: Can video files be pre-downloaded as well? (specifically a .wmv file for play in Windows Media Player) If so, can you provide any example code? Any other ideas?

Jimmy Changa's picture

They have: 220 posts

Joined: Mar 2003

From what I know...any file type can be preloaded. But I may be wrong.

The code you put in your post is for rolover, but not for preload...

Here's one version of a preload script...

<!-- Preload Images Script-->
&lt;script language="JavaScript" type="text/javascript"&gt;
var myimages=new Array()
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}

preloadimages("yadayadayada.gif, etc.jpg, somethingelse.png")

&lt;/script&gt;
<!-- End Preload Images Script -->
'

They have: 46 posts

Joined: May 2002

Thank you. But does New Image() apply to .wmv files?

Anybody do this with invisible frames? e.g. have a video file pre-loading in an invisible frame so it's fully downloaded by the time it's required in the main frame?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

PLEASE don't do this. PLEASE. If people want to view the video, they will wait for it to load. Otherwise you will suck up time and resources for people who don't want to view it, waste your bandwidth (considerable for movies) and throw away goodwill.

They have: 46 posts

Joined: May 2002

This particular site requires everyone to view this video. While they are registering in one frame... why can't the video they *have* to watch be downloading in another (invisible) frame???

Also, the video will be hosted on another server specifically designed for that purpose. So the downloading of the video will not effect other people's ability to register on the main site.

Based on this new information, PLEASE reconsider and help me out if you can.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

And if they choose not to register?

They have: 46 posts

Joined: May 2002

It's just an example. Let's pretend people are getting paid $10 to watch a 30-second TV commercial concept and provide feedback on it. They've agreed to do this. No one goes to this particular web site except to do this. They have to answer a few screens of questions before they see the video.

Can I preload the video while they are answering the few screens of preliminary questions? Does JavaScript's new Image() function apply to .wmv files or is there another way to do this that I'm not thinking of?

Thanks in advance...

They have: 447 posts

Joined: Oct 1999

hmm, good question. i suppose you could always try it....

Jimmy Changa's picture

They have: 220 posts

Joined: Mar 2003

There is that little issue of "security".

*shrugs*

They have: 46 posts

Joined: May 2002

What do you mean about security? I'm not sure where you're going with that...

Also, I found documentation on Microsoft's web site on how to use JavaScript to set the filename to be displayed in an embedded media player. Now I'm just trying to get one embedded media player in the main frame to display (without delay) the same .wmv file that was already downloaded to an embedded media file in a hidden frame. It *should* work - hopefully I'll get it to work over this weekend...

Jimmy Changa's picture

They have: 220 posts

Joined: Mar 2003

The security comment is not necessarily with your situation...just the preloading of files in general. Pardon my useless comments..I make many.

Hope your project works out for ya. Smiling

They have: 46 posts

Joined: May 2002

Mission accomplished!

mpeg video files can be preloaded. .wmv files cannot (they start to stream).

You just embed a Windows Media Player onto a web page (or in a hidden frame), specify the URL of the .mpg file, but set AutoStart or AutoPlay = false. The .mpg will start downloading immediately, but the video won't play until someone presses the play button.

Or use JavaScript to set the filename for a Windows Media Player in the main frame equal to the filename of the Windows Media Player in your hidden frame (which already caused the .mpg file to download to your computer's cache).

Works like a gem, but my god this was a pain in the arse to figure out...

Jimmy Changa's picture

They have: 220 posts

Joined: Mar 2003

Thanks for sharing your successful results with us.

Smiling

They have: 2 posts

Joined: Mar 2007

Thanks for this thread. I'm having kind of the same problem wherein my wmv files can't be preloaded and take forever and a day to load when someone clicks to play. Maybe I should convert the files to mpegs? That wasn't a random thought but actually a question ;>)

Thanks for any opinions!

Yvonne

He has: 1,758 posts

Joined: Jul 2002

Whoaaa... old thread Wink

In all honesty, in this day and age, Flash video is probably the best way to go. It can be preloaded easily and works on all systems that have flash (which is probably the most popular plugin out there). From what I know flash has something like a 98% install base, where as quicktime, realmedia, windows media are significantly lower.

Andy

They have: 2 posts

Joined: Mar 2007

Thanks Andy. If anyone can resurrect a thread from the dead, it would be me Laughing out loud

I've read that Flash would be my best option but am such a noob in this area . . . just one more thing to fit into my day. Sigh.

Thanks again!

Yvonne

They have: 1 posts

Joined: Mar 2007

can this preloading be done with MP3s as well... ?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.