开发者

how do I make sure Flash caches flv files?

I have an SWF开发者_开发知识库 that pulls several fairly heavy .flv files into the media player over its life cycle.

I'm using the player.source property. I don't see how I can control whether or not the player caches the flvs. I see a settings tab on the Flash Player itself (you can right click to bring up the settings) and I've set the slider to "unlimited" but after running the movie, the amount of cached information is still at 0.

Curious if anyone has dealt with this before.


I'm pretty sure if you just use the built-in flvPlayBack component and stream the .flv using httpStreaming, your file will not be cached.

In the past, I've used NetStream to download .flvs and save them to cache.

something like:

import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.URLRequest;
import flash.events.Event;

public var loader:NetStream;
public var dummy:Sprite;

public function loadFLV():void{
    var request:URLRequest = new URLRequest ('file_to_load.flv');
    var connection : NetConnection = new NetConnection();
    connection.connect(null);
    loader = new NetStream(connection);
    var dummy:Sprite = new Sprite();
    loader.play(request.url, true);
    loader.pause();//pause the playback so it doesn't play the video, it just buffers it.
    dummy.addEventListener(Event.ENTER_FRAME, onNetStreamEnterFrame, false, 0, true);
}

protected function onNetStreamEnterFrame(event : Event) : void {
    if(loader.bytesTotal == loader.bytesLoaded && loader.bytesTotal > 8) {
        //finished loading
        dummy.removeEventListener(Event.ENTER_FRAME, onNetStreamEnterFrame, false);
        loader.seek(0);
    }else{
        // still loading - you could do some progress stuff here if you wanted to.
    }
}

This is just off the top of my head. I'm also pretty sure some 3rd party loaders like BulkLoader do this for you.


Settings tab controls how many info Flash app can save through SharedObject. It's browser who caches any downloads, including those Flash Player makes; afaik, it can't be controlled from Flash.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜