I'm having problems serving mp3 files in NodeJS.
var filestream = fs.createReadStream('file.mp3');
filestream.on('open', function() {
var stats = fs.statSync('file.mp3');
var fileSizeInBytes = stats["size"];
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': fileSizeInBytes});
filestream.pipe(response);
});
I am setting the content type of the files before they are served, and the content length.
When I have the file on the page, I can play the audio and get the content's duration and it's current time.
But I cannot set it's current time like I can when I am not using NodeJS to serve the mp3 file.
<audio id='player' src='file.mp3'></audio>
<script>
var duration = player.duration; // 88 seconds
var time = player.currentTime; // 0 seconds
player.currentTime = 10;
var time = player.currentTime; // 0 seconds
</script>
Just to reitterate - when opening this page from the directory (not using nodejs as a server) I can set the currentTime of the audio element.
Why is this?
Thanks for your help.