使用 FileReferenceList 类加载多个 flv 视频

发布于 2024-10-11 10:27:40 字数 4436 浏览 3 评论 0原文

以下是我使用 FileReference 类加载一个视频的代码,它工作正常,

[Event(name="complete",type="flash.events.Event")]  
[Event(name="status",type="flash.events.StatusEvent")]  
public class LocalFileLoader extends EventDispatcher  
{  
    public function LocalFileLoader()  
    {}      
    private var file:FileReference;// = FileReference(event.target);  
    private var list:FileReferenceList; 
    public var p2pSharedObject:P2PSharedObject = new P2PSharedObject();  
    public function browseFileSystem():void {  
        file = new FileReference();  
        list = new FileReferenceList();  
        list.addEventListener(Event.SELECT, selectHandler);  
        list.browse();  
    }  
    protected function selectHandler(event:Event):void {  
        for each ( file in list.fileList ){  
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);    
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
            file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);         
            file.addEventListener(Event.COMPLETE, completeHandler);  
            writeText(file.name+" | "+file.size);  
            file.load();      
        }   
    }   
    protected function securityErrorHandler(event:SecurityErrorEvent):void {  
        writeText("securityError: " + event);  
    }  
    protected function completeHandler(event:Event):void {  
        writeText("completeHandler");  
        p2pSharedObject = new P2PSharedObject();  
        p2pSharedObject.size = file.size;  
        p2pSharedObject.packetLength = Math.floor(file.size/32000)+1;  
        p2pSharedObject.data = file.data;  
        p2pSharedObject.chunks = new Object();  
        var desc:Object = new Object();  
        desc.totalChunks = p2pSharedObject.packetLength+1;  
        desc.name = file.name;  
        p2pSharedObject.chunks[0] = desc;  
        for(var i:int = 1;i<p2pSharedObject.packetLength;i++){  
            p2pSharedObject.chunks[i] = new ByteArray();  
            p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,32000);  
        }  
        // +1 last packet  
        p2pSharedObject.chunks[p2pSharedObject.packetLength] = new ByteArray();  
        p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,p2pSharedObject.data.bytesAvailable);  
        p2pSharedObject.packetLength+=1;  
        writeText("----- p2pSharedObject -----");  
        writeText("packetLenght: "+(p2pSharedObject.packetLength));  
        dispatchEvent(new Event(Event.COMPLETE));  
    }  
    protected function writeText(str:String):void{  
        var e:StatusEvent = new StatusEvent(StatusEvent.STATUS,false,false,"status",str);  
        dispatchEvent(e);  
    }  
}  

sender.mxml 代码在舞台上播放视频

private function init() : void {  
    fileLoader = new LocalFileLoader();  
    fileLoader.addEventListener(Event.COMPLETE, fileLoaded);  
    fileShare = new P2PFileShare();  
    fileShare.addEventListener(StatusEvent.STATUS,
            function(event:StatusEvent):void {  
                writeText(event.level);  
            });    
    fileShare.connect();  
}    

private function fileLoaded ( event:Event ) : void {  
    writeText("fileLoaded");  
    if (fileShare.connected) {  
        fileShare.p2pSharedObject = fileLoader.p2pSharedObject;  
        fileShare.p2pSharedObject.lastIndexBegin = 0;  
        fileShare.p2pSharedObject.lastIndexEnd = fileShare.p2pSharedObject.packetLength-1;  
        fileShare.updateHaveObjects();  
    }  
    setupVideo();  
    // PLAY  
    ns.play(null);  

    ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);               
    ns.appendBytes(fileLoader.p2pSharedObject.data);  
    video.attachNetStream(ns);  
}  

private function setupVideo():void{  
    var nc:NetConnection = new NetConnection();  
    nc.connect(null);  
    ns = new NetStream(nc);  
    ns.client = this;  
    ns.addEventListener(NetStatusEvent.NET_STATUS, 
            function(event:NetStatusEvent):void{  
                writeText("stream: "+event.info.code);  
            });  
    video = new Video();  
    videoComp = new UIComponent();  
    videoComp.addChild(video);  
    this.addElement(videoComp);  
}  

,然后,file.name 和 file.size 转到 mxml 页面并显示视频在舞台上显示名称和文件大小 但我想对 FileReferenceList 类做同样的事情,我在过去两周解决了这个问题,但不能,,,请指导我,,,我谷歌很多次,但没有具体答案 问候
阿马德·汗

following is my code for loading one video using FileReference class and it works fine

[Event(name="complete",type="flash.events.Event")]  
[Event(name="status",type="flash.events.StatusEvent")]  
public class LocalFileLoader extends EventDispatcher  
{  
    public function LocalFileLoader()  
    {}      
    private var file:FileReference;// = FileReference(event.target);  
    private var list:FileReferenceList; 
    public var p2pSharedObject:P2PSharedObject = new P2PSharedObject();  
    public function browseFileSystem():void {  
        file = new FileReference();  
        list = new FileReferenceList();  
        list.addEventListener(Event.SELECT, selectHandler);  
        list.browse();  
    }  
    protected function selectHandler(event:Event):void {  
        for each ( file in list.fileList ){  
            file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);    
            file.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
            file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);         
            file.addEventListener(Event.COMPLETE, completeHandler);  
            writeText(file.name+" | "+file.size);  
            file.load();      
        }   
    }   
    protected function securityErrorHandler(event:SecurityErrorEvent):void {  
        writeText("securityError: " + event);  
    }  
    protected function completeHandler(event:Event):void {  
        writeText("completeHandler");  
        p2pSharedObject = new P2PSharedObject();  
        p2pSharedObject.size = file.size;  
        p2pSharedObject.packetLength = Math.floor(file.size/32000)+1;  
        p2pSharedObject.data = file.data;  
        p2pSharedObject.chunks = new Object();  
        var desc:Object = new Object();  
        desc.totalChunks = p2pSharedObject.packetLength+1;  
        desc.name = file.name;  
        p2pSharedObject.chunks[0] = desc;  
        for(var i:int = 1;i<p2pSharedObject.packetLength;i++){  
            p2pSharedObject.chunks[i] = new ByteArray();  
            p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,32000);  
        }  
        // +1 last packet  
        p2pSharedObject.chunks[p2pSharedObject.packetLength] = new ByteArray();  
        p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,p2pSharedObject.data.bytesAvailable);  
        p2pSharedObject.packetLength+=1;  
        writeText("----- p2pSharedObject -----");  
        writeText("packetLenght: "+(p2pSharedObject.packetLength));  
        dispatchEvent(new Event(Event.COMPLETE));  
    }  
    protected function writeText(str:String):void{  
        var e:StatusEvent = new StatusEvent(StatusEvent.STATUS,false,false,"status",str);  
        dispatchEvent(e);  
    }  
}  

the sender.mxml code is following which plays the video on the stage

private function init() : void {  
    fileLoader = new LocalFileLoader();  
    fileLoader.addEventListener(Event.COMPLETE, fileLoaded);  
    fileShare = new P2PFileShare();  
    fileShare.addEventListener(StatusEvent.STATUS,
            function(event:StatusEvent):void {  
                writeText(event.level);  
            });    
    fileShare.connect();  
}    

private function fileLoaded ( event:Event ) : void {  
    writeText("fileLoaded");  
    if (fileShare.connected) {  
        fileShare.p2pSharedObject = fileLoader.p2pSharedObject;  
        fileShare.p2pSharedObject.lastIndexBegin = 0;  
        fileShare.p2pSharedObject.lastIndexEnd = fileShare.p2pSharedObject.packetLength-1;  
        fileShare.updateHaveObjects();  
    }  
    setupVideo();  
    // PLAY  
    ns.play(null);  

    ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);               
    ns.appendBytes(fileLoader.p2pSharedObject.data);  
    video.attachNetStream(ns);  
}  

private function setupVideo():void{  
    var nc:NetConnection = new NetConnection();  
    nc.connect(null);  
    ns = new NetStream(nc);  
    ns.client = this;  
    ns.addEventListener(NetStatusEvent.NET_STATUS, 
            function(event:NetStatusEvent):void{  
                writeText("stream: "+event.info.code);  
            });  
    video = new Video();  
    videoComp = new UIComponent();  
    videoComp.addChild(video);  
    this.addElement(videoComp);  
}  

then after this, the file.name and file.size goes to mxml page and the video is displayed on stage with name and file size
but the samething i want to do with FileReferenceList class, i am solving this problem from last 2 weeks but cant ,,, plz guide me ,,, i google so many times but no specific answer
Regards
Ammad Khan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛泛之交 2024-10-18 10:27:40

您可以使用 fileList 属性 FileReferenceList 类来访问所选的文件。然后分别 load() 列表中的每个 FileReference:

private var list:FileReferenceList;

public function browseFileSystem():void {

    list = new FileReferenceList();  
    list.addEventListener(Event.SELECT, selectHandler);  
    list.browse();  
} 

protected function selectHandler(event:Event):void {  

    for each ( var file:FileReference in list.fileList) {
        file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);  
        file.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
        file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);  
        file.addEventListener(Event.COMPLETE, completeHandler);  
        writeText(file.name+" | "+file.size);           
        file.load(); 
    } 
} 

You can use the fileList property of the FileReferenceList class to access the files that where selected. Then load() each FileReference in the list separately:

private var list:FileReferenceList;

public function browseFileSystem():void {

    list = new FileReferenceList();  
    list.addEventListener(Event.SELECT, selectHandler);  
    list.browse();  
} 

protected function selectHandler(event:Event):void {  

    for each ( var file:FileReference in list.fileList) {
        file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);  
        file.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
        file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);  
        file.addEventListener(Event.COMPLETE, completeHandler);  
        writeText(file.name+" | "+file.size);           
        file.load(); 
    } 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文