我有五个视频文件,如video-1.flv,video-2.flv,video-3.flv,video-4.flv,video-5.flv。 我首先阅读video-1.flv并使用以下代码将其存储在byteArray中:
private var byteArray = new byteArray();
byteArray = readFile(VIDEO-FILE-PATH);
private function readFile(fileName:String):ByteArray
{
var data:ByteArray = new ByteArray();
var inFile:File = File.applicationDirectory; // source folder is application
inFile = inFile.resolvePath(fileName); // name of file to read
var inStream:FileStream = new FileStream();
inStream.open(inFile, FileMode.READ);
inStream.readBytes(data, 0, data.length);
inStream.close();
return data;
}
现在我想在同一个byteArray中阅读并将视频-2.flv中的下一个视频存储到video-5.flv。
我该怎么做?任何代码示例或Web链接都将受到赞赏。
答案 0 :(得分:1)
您可以对所有文件使用相同的byteArray,数据将自动附加,只需将缓冲区传递给readFile
方法并删除data.length
(在第一次读取时为0,所以您阅读全部可用数据和下一个读数,这将在inStream.readBytes(data, 0, data.length);
行中读取所有prevuse缓冲区长度的新文件。例如:
var buffer:ByteArray = new ByteArray();
for(var i:int = 1; i < 6; i++)
{
readFile("video-"+i+".flv", buffer);
}
private function readFile(fileName:String, buffer:ByteArray):ByteArray
{
var inFile:File = File.applicationDirectory; // source folder is application
inFile = inFile.resolvePath(fileName); // name of file to read
var inStream:FileStream = new FileStream();
inStream.open(inFile, FileMode.READ);
inStream.readBytes(buffer);
inStream.close();
return buffer;
}