Skip to content

Instantly share code, notes, and snippets.

@netwons
Created April 7, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netwons/20626fc2d2e684c32e7822573691dd8f to your computer and use it in GitHub Desktop.
Save netwons/20626fc2d2e684c32e7822573691dd8f to your computer and use it in GitHub Desktop.
InvalidHLS
<html>
<head>
<!-- Load dependent stylesheets. -->
<link href="//aws-cdn.terrafox.com/videojs/latest/video-js.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.6.1/videojs-contrib-ads.css" />
<link rel="stylesheet" href="//googleads.github.io/videojs-ima/dist/videojs.ima.css" />
</head>
<body>
<video id="content_video" class="video-js vjs-default-skin"
preload="metadata" muted width="640" height="360">
</video>
<button onclick="onChange()">Change source</button>
<!-- Load dependent scripts -->
<script src="//aws-cdn.terrafox.com/videojs/latest/video.min.js"></script>
<script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-contrib-ads/6.6.1/videojs-contrib-ads.js"></script>
<script src="//googleads.github.io/videojs-ima/dist/videojs.ima.js"></script>
</body>
</html>
var player = videojs('content_video', { autoplay: true, controls: true });
const sources = [{
type: 'application/x-mpegURL',
src: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
}, {
type: 'application/x-mpegURL',
src: 'https://d.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
}]
const tagUrl = 'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ct%3Dskippablelinear&correlator='
var options = {
id: 'content_video',
adsRenderingSettings: {
enablePreloading: true,
},
contribAdsSettings: {
liveCuePoints: false,
contentIsLive: true,
debug: true,
}
};
player.ima(options);
player.ima.initializeAdDisplayContainer();
player.ima.setContentWithAdTag(sources[0], tagUrl, false);
player.ima.requestAds();
function onChange() {
player.autoplay(true)
if (player.ads.inAdBreak()) {
player.ads.disableNextSnapshotRestore = true // eslint-disable-line no-param-reassign
player.ads.endLinearAdMode()
player.trigger('contentresumed')
}
const id = Math.round(Math.random())
player.ima.setContentWithAdTag(sources[id], tagUrl, false);
player.ima.requestAds();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment