HTML5/JavaScript - How to add a timestamp attribute to video source? - javascript

Having never used HTML or JavaScript before I'm really struggling to find an answer to this! I'm running a website for a local club which uses an online site builder so I haven't had to do any coding so far.
I want to show a timelapse video on one of the pages that updates every 30 mins via FTP (overwriting itself every time it updates). I've got the video uploading and playing fine but browsers are caching the video and not re-loading it when the page refreshes as the file name stays the same. I've done plenty of research and found that adding a random attribute, such as a timestamp, to the video src path would likely fix the issue (as per the below link) but I can't figure out how to do this.
Force browser to update cached HTML5 video object
As it's an online website builder, the only way to add code is to insert a 'HTML/Script' element and paste the code in there, so currently I have:
<video width="476" height="266" controls="" autoplay="">
<source src="http://mydomain.co.uk/Weather/today.mp4"
new="" type="video/mp4"/>
Sorry, your browser does not support our time lapse video.
</video>
I'm under the impression that I need some JavaScript in there to add the attribute, but as a newbie to HTML/Java I could do with some help! Thanks, Jonathan.

This will go into the video object that you have created and append a unique string to the end of the source of the video.
I did add an ID to the source in the video object to allow easier access of the source object with javascript.
var video = document.getElementById("vid");
var source = document.getElementById("vidsource");
var rndString = "?t=" + Date.now();
source.src = source.src + rndString;
video.load();
<video id="vid" width="476" height="266" controls="" autoplay="">
<source id="vidsource" src="http://mydomain.co.uk/Weather/today.mp4" new="" type="video/mp4" />Sorry, your browser does not support our time lapse video.
</video>

Related

Change video source with Javascript in html without refreshing the page just the video

My team and I are making a custom html video player and I'm working on a setting panel
And the first option we are mainly worried about so I'm adding first is the video quality option.
<video id="video" class="nm" poster="the poster url">
<source src="video source url of the video at 480p" type="video/mp4" size="480">
<source src="video source url of the video at 720p" type="video/mp4" size="720">
<source src="video source url of the video at 1080p" type="video/mp4" size="1080">
</video>
And now what we want to do is when the user toggles on an option it will change the video source to the source that has the quality specified by the size attribute
Image reference here
PS: We are making a video player from scratch as It is on its own built with no APIs (e.g. Video.js, JWPlayer, Plyr) We are making all the things needed from scratch with pure javascript and html... and as we're making a website for streaming, and my team and I want to make a video player made by us for the website, and "maybe" later for distribution but for now we want to make a brand new video player and were just been putting this part off as we aren't sure of the best way to do this!
Edit
Also, we want the video to pause and change the quality and pick up off where it was paused
Note that for the native video the browser will decide which <source> to show and choose the first element it supports/understands (e.g. the first supported video file format): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#Usage_notes
To circumvent that and force the browser to show a certain video source url, put in only one <source> element and manipulate the source property with javascript.
To pause and play the video in the native HTML5 video player you may use the API of the HTMLMediaElement: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
It has the play and pause functions you're looking for.

Custom scrub bar in video HTML5, set currentTime not working

I'm making a custom scrub bar in HTML video player. I'm creating a HTML5 video player and take a currentTime from video and it is working good, but seting currentTime after moving a scrub bar dose not working.
Firstly, I want write I've tried several possiblity to resolve this problem. I disable autoplay in video and other things, what can be.
But, one thing puzzles me. I can not have a directly URL to the video, I have a URL to JSP code on the server, and this code return to me this file. What can be a problem with it? Because, if I downloaded this movie file and set URL to directly to this movie file - with extension .mp4 - all starts working good.
Maybe it's problem with it I can not have a directly url to movie file?
I don't have any ideas to resolve this porblem. I'm counting on your help
if the video stored as an .mp4 or .ogg or .webm video file format, It would play. Here is how your html may look like.
<video controls preload="metadata">
<source src="http://www.example.com/waterfall-video.mp4" type="video/mp4"/>
<source src="http://www.example.com/waterfall-video.ogg" type="video/ogg">
Video not supported.
</video>

JS - displaying annotations on html5 video element

<video id="video" preload=auto autoplay controls>
<source src = "http://www.w3schools.com/html/mov_bbb.mp4">
</video>
Youtube uses notes once a user defines one in his videos.
they are called annotations. Something like this:
http://www.incomediary.com/wp-content/uploads/2013/08/types-of-youtube-annotations.jpg
Is there an easy way to display it on a specific X, Y on my video,
full screen or not? for certain reasons,
I don't want the notes to be displayed on a canvas,
just on a video. How does youtube do it? I suspect that
they don't use canvas, since when right clicking on their videos show it's a video element.
EDIT: I forgot to mention, the annotations should be able to display dynamically - for example it can be displayed all of the sudden at minute 5:33, because maybe JS received something from Node server stating so.

Play video in client side

I'm developing a website using MVC5-html5(actually it will only has a limited number of user,may be 5-10 ). Now, I play video through video tag in html5.
<video width="400" controls>
<source src="myVideo.webm" type="video/webm">
Your browser does not support HTML5 video.
</video>
But in order to load the video, It takes time to get the video file from my server to clients and sometime it gets lagging. I wonder is it possible for me to let my client save these videos in their PCs and for the next time, we read direct video from there(let's say from C:\temp folder). Don't need to download from the server again.
Thank you for any though/ suggestion.

Which is better ifram or <video> to play video (both youtube as well non youtube) in terms of browser compatibility?

I tried with both
iframe - no solution to stop autoplay or control video for non-youtube videos
video - Does not support youtube video
Using iframe
<iframe id="vt" width="420" autoplay="false" height="345" src="http://cache4.asset-cache.net/xd/468140002.mp4?v=1&c=IWSAsset&k=2&d=72990B68305E4FDFEE95B69A879131BCD6D7111452E48A17C03F8342D660D5A451EBC1DEC2A827C9&b=RTdG" frameborder="0" allowfullscreen></iframe>
jQuery(document).ready(function () {
// var url = $('#vt').attr('src');
// $('#vt').attr('src', '');
// $('#vt').attr('src', url);
var vid = document.getElementById("vt");
vid.pause()
//vid.onpause = function() {
//alert("The video has been paused");
};
});
with video tag
<video width="320" height="240" src="https://www.youtube.com/watch?v=dwH34mR6ZG8" controls="controls"> </video>
First of all, iframes were never meant for displaying embedded media. That's something the object tag was intended to handle instead. From the MDN docs:
The HTML Inline Frame Element (<iframe>) represents a nested browsing
context, effectively embedding another HTML page into the current
page.
The HTML Embedded Object Element (<object>) represents an external
resource, which can be treated as an image, a nested browsing context,
or a resource to be handled by a plugin.
Both of which predate the video element, which is what you should always be using to embed video content in a webpage.
Secondly, YouTube videos aren't meant to be linked directly from a <video> element... the embed code they provide you with is an iframe that opens up to an HTML5 video player anyway (or a Flash fallback for antique devices).
Verdict: If the video you're trying to display isn't or can't be hosted on YouTube, use the video tag on a webpage to embed it, making sure to convert the video in as many supported formats as possible. There's plenty of write-ups online on HTML5 video, so I won't detail the process here.

Categories

Resources