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

video.js 706B

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