Turn audio into a shareable video. forked from nypublicradio/audiogram

video.js 660B

12345678910111213141516171819202122232425262728293031323334353637
  1. var d3 = require("d3");
  2. var video = document.querySelector("video");
  3. function kill() {
  4. // Pause the video if it's playing
  5. if (!video.paused && !video.ended && 0 < video.currentTime) {
  6. video.pause();
  7. }
  8. d3.select("body").classed("rendered", false);
  9. }
  10. function update(url, name) {
  11. var timestamp = d3.timeFormat("%m%d%y_AG_")(new Date).toLowerCase(),
  12. filename = timestamp + (name || "Audiogram") + ".mp4";
  13. d3.select("#download")
  14. .attr("download", filename)
  15. .attr("href", url);
  16. d3.select(video).select("source")
  17. .attr("src", url);
  18. video.load();
  19. video.play();
  20. }
  21. module.exports = {
  22. kill: kill,
  23. update: update
  24. }