0

I have five video file like video-1.flv, video-2.flv, video-3.flv, video-4.flv, video-5.flv. I read first video-1.flv and store it in a byteArray using the code below:

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;
}

Now I want to read and store the next videos from video-2.flv to video-5.flv in the same byteArray.

How can I do this. Any code sample or web link would be appreciated.

1 Answer 1

1

You can use the same byteArray for all files, data will be appended automatically, just pass the buffer to the readFile method and remove the data.length (in first reading it's 0, so you read all available data and in next readings this will course reading new file with the length of all previuse buffer) in inStream.readBytes(data, 0, data.length); line. Example:

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.