PDA

View Full Version : Preloading with a video


PeaTearGriffin
11-08-2007, 05:52 PM
Hi,

I am trying to preload a video so that when the preloading is done you can jump to any part of the clip. I have a bar that loads as the percentage increases. It works fine and all, but the way I am doing it right now is by preloading a swf file that has an imported video on it which streams the video. So that would mean it is only preloading the swf file and not the video right?

I currently have this code:
var requestObj:URLRequest = new URLRequest("swf/demo.swf");
var loaderObj:Loader = new Loader();
addChild(loaderObj);
loaderObj.load(requestObj);

loaderObj.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preloadProgress);

function preloadProgress(event:ProgressEvent):void {
var loadedPercent:int = event.bytesLoaded / event.bytesTotal * 100;
preloader_mc.loadingBar_mc.loaderText_txt.text = loadedPercent + "%";
preloader_mc.loadingBar_mc.loaderMask_mc.scaleY = loadedPercent / 100;
}

loaderObj.contentLoaderInfo.addEventListener(Event.COMPLETE, preloadComplete);
function preloadComplete(event:Event):void {
preloader_mc.visible = false;
}

What must I do to make the preloader actually preload a video?

I tried embedding a video onto the timeline, but the preloader won't download it. The preloader will show 0% and just jump to the clip which needs to be streamed.

gnomeontherun
11-09-2007, 02:27 AM
Ok so you are loading a swf file that loads a video file? Is this a standalone file or is this part of a larger flash file? What happens is you would need to have the preloading occur for the video file itself, and its best to save video files as .flv instead of loading them into the timeline.

I would suggest using www.gotoandlearn.com to read the video tutorials. This gives some great examples on how you can have video loaded into the file and make your own video player. Best of all, you can get through the tutorials in a couple hours and have a working video player.

PeaTearGriffin
11-09-2007, 04:10 PM
Hmm, I wanted to try and use the same code. And see why mine wouldn't work. I have a swf file (but I don't have the fla file for it) and if I run the swf file it will preload the swf file that has the movie on it. I'm not sure what they did to put the movie on there, but it wasn't streaming for sure since I don't have any other file and it would work. I thought they embedded it to the timeline, but when I try that it won't work.

My video is already a .flv file and if I try to put a .flv file as the source, flash gives me an error saying they don't recognize that.

gnomeontherun
11-10-2007, 08:08 AM
I'm not knowledgeable about AS3 yet, but does the swf file have a feature to preload the video? This script appears to only manage the swf, and once that is loaded the swf has to handle loading the video. It is my belief that unless you are able to edit the swf and have it preload the video, I don't think it can be done.

PeaTearGriffin
11-11-2007, 05:34 AM
I'm not knowledgeable about AS3 yet, but does the swf file have a feature to preload the video? This script appears to only manage the swf, and once that is loaded the swf has to handle loading the video. It is my belief that unless you are able to edit the swf and have it preload the video, I don't think it can be done.

Well I got the swf file from a CD tutorial and there was no FLA file for it. I have my own swf file with a video on it, but the preloader won't preload the video, only the swf file.

Basically they have a simple preloader swf that calls a video that is a swf. I am just wondering what they do to be able to preload the actual video. They are not streaming it because I can run it on my computer without any other files. When I try to embed a video into the timeline, it doesn't work either. The other options for flash are streaming from a flash server, but that also isn't applicable.

So did I just embed it wrong or something? (Most say that embedded video should be no longer than 10 seconds, and have no sound, but the swf file I have is longer than that and is no problem) It wouldn't seem to be anything else.

gnomeontherun
11-11-2007, 07:28 AM
Could I see these files (upload it to your site or something?) One of the biggest problems with Flash for me is that its hard to diagnose issues without seeing the actual files and framework.

PeaTearGriffin
11-13-2007, 07:43 PM
There is only 2 layers in the fla file. One is the actions layer, which I posted the code above. The 2nd layer is only the preloader, with a mask that shows the animation for the loading bar. The preloader works... but the problem is getting it to preload the video, instead of the actual swf file.

The swf movie file when you run it is just a video that autoplays and has no controls. I don't have the fla file for that, so I don't know how they did it. But the file is about 1.2mb I think. So did they embed the video file? But when I try to embed a video, it won't work. The preloader shows 0% and then just skips to show the video which I then have to stream instead of preloading it.

gnomeontherun
11-13-2007, 09:25 PM
Are you testing this over an internet connection or from your local computer? The issue is that your swf does not preload the video (from what you've said) and I don't know how you are getting the SWF to know which FLV file it should pick up. Do you know anything about how the swf works, or at least how do you pass the filename of your video to it? My only idea is that you may be able to preload the video file separately in the main swf file, and pass the file as a variable to the video player swf, but again I have no idea how your player works which is the whole reason I can't help much.

I still think you could try going over the www.gotoandlearn.com tutorials on video players, because it seems easier to setup the player in the main swf instead of importing a secondary swf, its cutting out the middleman. If you want to just directly load a video into the file without this video player swf, this is the place to learn quickly.