VideoJS the play function - video.js

I have a problem with the player the point is that when I try to call player.play(); nothing happens. Chrome 72
var player = videojs('content_video');
player.src({
src: "https://vdn.terrafox.com/sf/bb-baycam/playlist.m3u8",
type: "application/x-mpegURL"
})
player.ready(() => {
player.play()
})
<link href="http://vjs.zencdn.net/5.19/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/5.19/video.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.8.0/videojs-contrib-hls.min.js" ></script>
<video id="content_video" class="video-js vjs-default-skin" controls preload="auto" autoplay playsinline width="640" height="360">
</video>

The link you are using (i.e https://vdn.terrafox.com/sf/bb-baycam/playlist.m3u8) is not exist. so play function is not working. If you use proper url for ex. https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8, it will work.
var player = videojs('content_video');
player.src({
src: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8",
type: "application/x-mpegURL"
})
player.ready(() => {
player.play()
})
<link href="http://vjs.zencdn.net/5.19/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/5.19/video.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-hls/5.8.0/videojs-contrib-hls.min.js" ></script>
<video id="content_video" class="video-js vjs-default-skin" controls preload="auto" autoplay playsinline width="640" height="360">
</video>

Related

Change HTML5 video src does not work in Safari mobile browser

I have a scenario, i have to play two video in HTML5 player in mobile browsers. The videos are playing fine in desktop browsers.
one thing i know ,
We not autoplay videos in mobile browsers, user has to tap on the video player to play video.
What i am doing, on video ended event of first video i am changing the src of the . but sometimes it is shaky or it does not plays the second video. user has to tap on play button to play 2nd video. I just need to exclude the 2nd tap. YouTube is doing this somehow. The ad video plays fine, the player minimize and then the 2nd video starts playing.
It takes much time to play the video on start.
Following is my sample implementation. try this url in iPhone or Android
http://abuzer.github.io/videojs-liverail-vpaid/sample.html
<script>
videojs.options.flash.swf = "video-js.swf";
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
video1 = 'https://d3hh3bpy3h68fd.cloudfront.net/processed_videos/47fad7e0-7477-0132-8e95-123139254ded/_preview_640x480_2932_edit.mp4';
video2 = 'https://drgta5lwz3cck.cloudfront.net/uploads-public-videos/fd6eefe0-73cc-0132-a03a-12313b07582a/640x480.mp4';
video1Played = false;
video2Played = false;
$(function() {
$('#playAd').on('click', function() {
$('#playAd').hide();
$('#videoElement').attr('src', video1);
$('#videoSource').attr('src', video1);
$('#videoElement')[0].play();
video1Played = true;
});
$('#videoElement').bind('ended', function() {
if (video1Played && !video2Played) {
$('#videoElement').attr('src', video2);
$('#videoSource').attr('src', video2);
$('#videoElement')[0].load();
$('#videoElement')[0].play();
video2Played = true;
}
});
$('.videoElement').bind('progress', function(e) {
$('#state').hide();
});
$('.videoElement').bind('waiting', function(e) {
$('#state').show();
});
});
</script>
<html>
<head>
<meta charset="utf-8">
<title></title>
<!-- Chang URLs to wherever Video.js files will be hosted -->
<link href="video-js.css" rel="stylesheet" type="text/css">
<!-- video.js must be in the <head> for older IEs to work. -->
<script src="video.js"></script>
<!-- Unless using the CDN hosted version, update the URL to the Flash SWF -->
</head>
<body>
<button type="button" id="playAd">Click to Play</button>
<div id="videoWrapper" style="">
<div id="state" style="display:none; text-align: center">
<img style="-webkit-user-select: none" src="http://www.loadinfo.net/images/preview/14_cyrle_four_24.gif?1384388177">
</div>
<video x-webkit-airplay="allow" id="videoElement" class="video-js videoElement vjs-default-skin" height="50%" width="100%" controls src="" poster="">
<source id="videoSource" src="" type="video/mp4">
</video>
<!-- <video data-setup="{}" x-webkit-airplay="allow" id="videoElement1" class="video-js videoElement1 vjs-default-skin" height="50%" width="100%" controls src="" poster="">
<source id="videoSource" src="https://d3hh3bpy3h68fd.cloudfront.net/processed_videos/47fad7e0-7477-0132-8e95-123139254ded/_preview_640x480_2932_edit.mp4" type="video/mp4">
</video>
-->
</div>
</body>
</html>

XDK - html5 tag video, autoplay and loop ignored by Android

I am developing a simple application in XDK IBM to run a video in a android device.
The problem is, after built, the video dont autoplay and dont do the loop.
The code:
<!DOCTYPE html>
<html>
<head>
<title>Blank Hybrid App Project Template</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<style>
#-ms-viewport { width: 100vw ; zoom: 100% ; } #viewport { width: 100vw ; zoom: 100% ; }
#-ms-viewport { user-zoom: fixed ; } #viewport { user-zoom: fixed ; }
</style>
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<video width="100%" height="100%" autoplay="true" loop="true">
<source src="assets/1234.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' id="src" autostart="true">
</video>
<script src="intelxdk.js"></script>
<script src="cordova.js"></script>
<script src="xhr.js"></script>
<script src="js/app.js"></script>
<script src="js/init-app.js"></script>
<script src="js/init-dev.js"></script>
</body>
</html>
I afraid this problem seem to be a XDK issue. In the debug it works as expected. I tested the APk in 2 smartphones and in the MK808.
Regards,
This was the solution:
<video width="100%" height="100%" id="video">
<source src="assets/12345.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' id="src" autostart="true">
</video>
<script type="text/javascript">
var video = document.getElementById("video");
video.loop = false;
video.addEventListener('ended', function() { video.currentTime=0.1; video.play(); }, false);
video.play();
</script>

Video-JS + Colorbox, loading dynamic videos

Having an issue that has been frustrating me the last few days.
I have some videos on a site that are loaded dynamically from sitecore, and display on a page with thumbnail images. When you click those images you are taken to a lightbox with the video.
The problem is, the video plays in Chrome, Firefox and IE8 -, but not IE9 +. I thought it may be an encoding issue, but I have converted this video so many times to every format available to the web to no avail.
I am setting the plugin to load the video as flash first, then if flash isn't available, load as html5. This will clear all worries in terms of browser support of HTML5 video.
I was thinking that it may be the lightbox and videoJS plugin fighting with each other, or the fact that i am hiding videos and showing them, which i know can sometimes cause issues. I have decided to use a different lightbox, and people seem to have said that colorbox is a decent one to use with videoJS, especially since it has some built in callbacks onLoad.
On to the problem and the code:
The problem:
This lightbox is working, but videoJS seems to throw a few errors when i try and reset the player, which is breaking the videos in IE since its such a dumb browser.
As you can see in the demo link at the bottom, the videos play in IE just fine when they are just set on the page, but when you open the lightbox by pressing "vid1" or "vid2" you are riddled with console errors and the videos no longer play.
The code:
HTML + jScript:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"> </script>
<link href="http://vjs.zencdn.net/4.3/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/4.3/video.js"></script>
<link type="text/css" rel="stylesheet" href="colorbox.css" />
<script type="text/javascript" src="js/jquery.colorbox.js"></script>
<style type="text/css">
.hide {
display: none;
}
</style>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$(".inline", this).colorbox({
inline: true,
rel: 'videohook',
width: '650px',
onLoad: function() {
//grab the video ID and store it
var vidID = $(this).attr("data-vidID");
//Reset the video players
videojs.players = {};
//set the videoJS player for this video.
videojs(vidID);
}
});
});
</script>
<a rel="videohook" data-vidID="my_video_1" class="inline" href="#video_1">vid 1</a>
<a rel="videohook" data-vidID="my_video_2" class="inline" href="#video_2">vid 2</a>
<div id="video_1" class="video">
<video id="my_video_1" class="video-js vjs-default-skin" controls
preload="none" width="640" height="264" poster=""
data-setup='{"techOrder": ["flash", "html5"]}'>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/mp4'>
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type='video/ogv'>
</video>
</div>
<div id="video_2" class="video">
<video id="my_video_2" class="video-js vjs-default-skin" controls
preload="none" width="640" height="264" poster=""
data-setup='{"techOrder": ["flash", "html5"]}'>
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type='video/mp4'>
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type='video/ogv'>
</video>
</div>
</body>
</html>
Console errors im getting:
Uncaught TypeError: Object #<HTMLObjectElement> has no method 'vjs_getProperty'
LIVE DEMO:
Go here to see the errors for yourself: http://kodistro.com
In this case, my solution is to inject the video tag HTML into the lightbox content (when opening) and then call videojs().
So, in pseudo-code:
<script type="text/javascript">
$(document).ready(function() {
$(".inline", this).colorbox({
inline: true,
rel: 'videohook',
width: '650px',
height: '274', //the size most be fixed
onLoad: function() {
var appendVideo1 = '<video id="my_video_1"......> </video>'; //insert the <video> tag. Note.Remove attribute data-setup='{"techOrder": ["flash", "html5"]}'
$("video_1").append(appendVideo1);
},
onComplete: function() {
videojs(my_video_1); //initialize video-js
},
onClosed: function() {
videojs(my_video_1).dispose(); //destroy video-js
}
});
});
</script>
<a rel="videohook" data-vidID="my_video_1" class="inline" href="#video_1">vid 1</a>
<div id="video_1" class="video">
</div>

Videojs TypeError: this.addEvent is not a function

Really don't know what's wrong with my code! I'm tryng to attach the end event to my player by i get this error in my firefox console:
"TypeError: this.addEvent is not a function"
I tried in so many way, but coudnt solve this problem!
<!DOCTYPE html>
<html>
<head>
<link href="video-js.css" rel="stylesheet" type="text/css">
<script src="video.js"></script>
<script>_V_.options.flash.swf = "video-js.swf";</script>
</head>
<body>
<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="400" height="500" data-setup='{}'
poster="http://video-js.zencoder.com/oceans-clip.png">
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
<track kind="captions" src="demo.captions.vtt" srclang="en" label="English" />
</video>
<script>
var myPlayer = videojs("example_video_1");
videojs("example_video_1").ready(function(){
var myPlayer = this;
var videoEnd = function(){
console.log('ended')
};
myPlayer.addEvent("ended", videoEnd);
});
</script>
</body>
</html>
Can u help me please?
thanks a lot
video.js has recently been updated to version 4 and some things in the API have changed. You'll need to use myPlayer.on("ended", videoEnd);
API docs: https://github.com/videojs/video.js/blob/master/docs/api/vjs.Player.md

HTML Overlay in full screen using Video.js

Has anyone been able to create a full-screen overlay using Video.js player? We are looking for a way to display a div over the video, and have it available even when in full-screen mode.
This is what I've done on a recent project using JQuery UI dialogs, but the solution applies to whatever element you want to display over the video.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#overlay').dialog({
width: $(window).width() * .8,
height: 100,
position: { my: "center", at: "bottom", of: window },
autoOpen: false,
zIndex: 2147483647
});
});
int = setInterval(function(){checkNews()},checkNewsInterval);
function checkNews() {
var url = 'news.php';
$('#overlay').load(url, function() {
$('#overlay').dialog('open');
return false;
}
</script>
<body>
<div id="video-container">
<video id="myvideo" class="video-js vjs-default-skin" controls
preload="auto" poster="" data-setup="{}">
<source src="<you_video_source>" type='video/mp4'></source>
<param name="allowfullscreen" value="true" />
</video>
</div>
<div id="overlay"></div>
</body
</html>
The trick being the property:
zIndex: 2147483647
either set in the dialog setup or as a CSS in:
#overlay {
z-index: 2147483647;
}