How to send binary data, for example, mp3/mp4 back to the external interface?
I know that there are two ways to do this: use the sandbox file system provided by NACL and get the URL in the frontend; Passing data through PostMessage() using a VarArrayBuffer . It would be great if someone could give me a simple example of how to pass binary data through PostMessage() . There is a Pong example for the NACl FileSystem API, but I'm a little confused how to get the file location as a URL so that the JS interface can receive it via a message.
Here is what I have done so far using the second method of passing data through PostMessage() and VarArrayBuffer :
I successfully extracted the data from the mp4 online file and saved it in the vector vector<char> outputBuffer .
Flushes data to a new character buffer and creates a VarArrayBuffer to store data and pass it to the JS side
char* binaryBuffer = new char[outputBuffer.size()]; int increment = 0; for (vector<char>::iterator it = outputBuffer.begin(); it != outputBuffer.end(); it++) { binaryBuffer[increment] = *it; } pp::VarArrayBuffer outBuffer(binaryBuffer); instance_->PostMessage(outBuffer);
So, how should the JS side intercept the array buffer? Is it through message.data or something else?
c ++ javascript arrays bytearray google-nativeclient
Jjin
source share