Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Syncing videos?

KittenKatja

Well-Known Coder
I'd like to sync two videos.
One is behind the other video and has the blur filter.
Currently, ontimeupdate="if(this.currentTime == 0){let a = document.getElementById('background_blur');a.currentTime = 0;a.play()}" only works, if the video has sound, and is not muted.
Would canvas safe some ram by taking the foreground video's frame input and output onto the canvas?

I'd like to download a file from an external source with a left click on an element. As far as I know, the download tag only allows same-origin sources to be downloaded, there's also a way to download using blob, but I don't know anything about that.
 
I'd like to sync two videos.
One is behind the other video and has the blur filter.
Currently, ontimeupdate="if(this.currentTime == 0){let a = document.getElementById('background_blur');a.currentTime = 0;a.play()}" only works, if the video has sound, and is not muted.
Would canvas safe some ram by taking the foreground video's frame input and output onto the canvas?

I'd like to download a file from an external source with a left click on an element. As far as I know, the download tag only allows same-origin sources to be downloaded, there's also a way to download using blob, but I don't know anything about that.
Personally, I've never had the need to do this, but this does sound like an interesting topic to learn from :). Did a bit of digging, and found this article on video syncing.


Hope it helps
 
I don't want to sync 2 videos as often as the browser allows me, once every start of the video is enough for me, because that seems to be the only time when the two videos go async. But I also want to sync 2 mute videos.

Your example only makes it open the link, not give me a download prompt or have a file name suggestion already in it.
Blob is at the bottom, can't you explain how that works instead?
 
I don't want to sync 2 videos as often as the browser allows me, once every start of the video is enough for me, because that seems to be the only time when the two videos go async. But I also want to sync 2 mute videos.

Your example only makes it open the link, not give me a download prompt or have a file name suggestion already in it.
Blob is at the bottom, can't you explain how that works instead?
To answer your bonus: If you want to give a suggested file name to the file, all you have to do is set the download attribute to whatever filename you wish to suggest:
HTML:
<a href="https://pathToFile" download="always-checkout-references-given.exe">Download ME</a>

Right from that stackoverflow article I referenced ;)
1667771042801.png
 
IF you wish to have a popup with an "actual" prompt, then some js magic is involved. At this point, you have a couple of options.
1) have a button "download me" open up a modal that asks the user to download, and hook up the download event to the "OK" button inside of the modal

OR...hear me out :)

2) have an alert box that does the same thing
 
I think you're not digging enough.
The same-origin policy disallows websites to prompt a download from another website, that means I can only download files that are already on my computer, because the local file has its origin on my computer.
Instead of opening the download file prompt, it will instead open the hyperlink, and since only the download tag is specified and not the target, it will open in that tab.
Blob goes around same-origin by downloading the file into cache first, but I don't know how to use blob. (I thought a security analyst would know about that policy)
 
I think you're not digging enough.
The same-origin policy disallows websites to prompt a download from another website, that means I can only download files that are already on my computer, because the local file has its origin on my computer.
Instead of opening the download file prompt, it will instead open the hyperlink, and since only the download tag is specified and not the target, it will open in that tab.
Blob goes around same-origin by downloading the file into cache first, but I don't know how to use blob. (I thought a security analyst would know about that policy)
Fully aware of CORS. When it comes to that, a bit of js magic should help. In your GET call, add the attribute to handle CORS.
 
Is video in MP4 or youtube???

Here try this code
HTML:
<video height="180" width="300" id="a" controls>
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.mp4"></source>
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.ogv"></source>
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.webm"></source>
</video>
<video height="180" width="300" id="b">
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.mp4"></source>
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.ogv"></source>
<source src="https://videos.mozilla.org/serv/webmademovies/popcorntest.webm"></source>
</video>

<input type="range" value="0" id="scrub" />


JavaScript:
//USE jQuery edge

var videos = {
    a: Popcorn("#a"),
    b: Popcorn("#b"),
  },
  scrub = $("#scrub"),
  loadCount = 0,
  events = "play pause timeupdate seeking".split(/\s+/g);

// iterate both media sources
Popcorn.forEach(videos, function(media, type) {

  // when each is ready...
  media.on("canplayall", function() {

    // trigger a custom "sync" event
    this.emit("sync");

    // set the max value of the "scrubber"
    scrub.attr("max", this.duration());

    // Listen for the custom sync event...   
  }).on("sync", function() {

    // Once both items are loaded, sync events
    if (++loadCount == 2) {

      // Iterate all events and trigger them on the video B
      // whenever they occur on the video A
      events.forEach(function(event) {

        videos.a.on(event, function() {

          // Avoid overkill events, trigger timeupdate manually
          if (event === "timeupdate") {

            if (!this.media.paused) {
              return;
            }
            videos.b.emit("timeupdate");

            // update scrubber
            scrub.val(this.currentTime());

            return;
          }

          if (event === "seeking") {
            videos.b.currentTime(this.currentTime());
          }

          if (event === "play" || event === "pause") {
            videos.b[event]();
          }
        });
      });
    }
  });
});

scrub.bind("change", function() {
  var val = this.value;
  videos.a.currentTime(val);
  videos.b.currentTime(val);
});

// With requestAnimationFrame, we can ensure that as
// frequently as the browser would allow,
// the video is resync'ed.
function sync() {
  if (videos.b.media.readyState === 4) {
    videos.b.currentTime(
      videos.a.currentTime()
    );
  }
  requestAnimationFrame(sync);
}
 
Back
Top Bottom