JavaScript Serving mp3 files in NodeJS for use in audio tag serving static files nodejs,nodejs serving files,serve static files

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.

Answer:1

I have a HTML form and I am converting that form inputs to a object using the below code: var inputs = $("form :input"); var obj = $.map(inputs, function (x, y) { return { Key: x.name, ...

I have a HTML form and I am converting that form inputs to a object using the below code: var inputs = $("form :input"); var obj = $.map(inputs, function (x, y) { return { Key: x.name, ...

  1. remove key value from object javascript
  2. remove key value from dictionary python
  3. remove key value pair from dictionary python
  4. remove key value from dict python
  5. remove key value from hash ruby
  6. remove key value pair from hash ruby
  7. remove key value from dictionary
  8. remove key value pair from dictionary javascript
  9. remove key value from array php
  10. remove key value pair from dictionary c#
  11. remove key value pair from map c++
  12. remove key value from dict
  13. remove key value from map java
  14. remove key value from dictionary javascript
  15. remove key value pair from map java
  16. remove key value from json object javascript
  17. remove key value from json python
  18. remove key value from map golang
  19. remove key value pair from array javascript
  20. remove key value from json

How can I change the content of the span class"push-me" which is "+" to a "-" on alternative clicks of the "container-heading" class. $('#btn1').click(function() { $('#nrOne').toggleClass('...

How can I change the content of the span class"push-me" which is "+" to a "-" on alternative clicks of the "container-heading" class. $('#btn1').click(function() { $('#nrOne').toggleClass('...

  1. change content span jquery
  2. change content span css
  3. change content span javascript
  4. change content span
  5. change span content js
  6. change span content using javascript
  7. change span content html
  8. jquery change span content by id
  9. change span text content javascript
  10. react change span content
  11. how to change span content using jquery
  12. javascript change content of span element
  13. javascript change content inside span

I came across a weird code which I didn't understood. It would be great if I get explanation. function forEach(array, action) { for (var i = 0; i < array.length; i++) { action(array[i]); }...

I came across a weird code which I didn't understood. It would be great if I get explanation. function forEach(array, action) { for (var i = 0; i < array.length; i++) { action(array[i]); }...

I am using Google Geocharts and following Google's documentation (https://developers.google.com/chart/interactive/docs/gallery/geochart?hl=en) to setup a chart like this: google.charts.load('current',...

I am using Google Geocharts and following Google's documentation (https://developers.google.com/chart/interactive/docs/gallery/geochart?hl=en) to setup a chart like this: google.charts.load('current',...

  1. google.visualization undefined
  2. google.visualization.datatable undefined
  3. google.visualization.arraytodatatable undefined
  4. typeerror google.visualization is undefined
  5. new google.visualization.datatable() undefined
  6. google.maps.visualization is undefined
  7. google charts google.visualization is undefined
  8. error google.visualization is undefined