Hello there,
I will try to be more specific about my question, I'm using angular 9 and latest electron version 8.1.1.
My goal is to read large media files like videos(>4go), songs(flac) or other large files located on my file system but using the stream api in nodeJS in the main process and sending the result (chunk,buffer) to the renderer process.
How can I handle the stream buffer in the renderer process, I would like to use video and audio api already built in html5, thus using ipc between the main and renderer process, I will send the chunks and would like to be able to display,play,read those chunk using html5 api's (e.g with the video tag and attribute src or audio tag and attribute src) what should I give as a src for these elements so that it works like a basic web stream with an url ?
Here is my main process code (where I use fs with nodejs):
ipcMain.on('getFileStream', (event, arg) => {
try {
if(fs.existsSync(arg.path) && fs.lstatSync(arg.path).isFile()) {
const s = fs.createReadStream(arg.path)
s.on('data', (chunk: Buffer) => {
console.log(chunk)
event.sender.send('getFileStreamResponse', chunk)
}).on('end', () => {
console.log("end stream")
event.sender.send('getFileStreamResponse', false)
s.close()
});
}
} catch(e) {
console.log('getFileStream', e)
}
})
I don't want to wait all chunks to begin to play the media, I want to be able to play the media when enough data is loaded. I have read about Mediasources in html5 but wanted to know if it's the right way or do you know a better way to read large files and rebuilt the chunks in the renderer process ?
Thanks a lot for your time