Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #53 from theonion/stop-preroll-autoplay
Browse files Browse the repository at this point in the history
Stop preroll autoplay
  • Loading branch information
csinchok committed Oct 31, 2014
2 parents 714a951 + 8260a37 commit 1a27c81
Show file tree
Hide file tree
Showing 3 changed files with 338 additions and 351 deletions.
70 changes: 53 additions & 17 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
<link href="videojs.vast.css" rel="stylesheet" type="text/css">

<style type="text/css">
#vid1 {
width: 75%;
.description {
background-color:#eee;
border: 1px solid #777;
padding: 10px;
font-size: .8em;
line-height: 1.5em;
font-family: Verdana, sans-serif;
}
.example-video-container {
display: inline-block;
}
</style>
<!--[if lt IE 9]><script src="lib/es5.js"></script><![endif]-->
Expand All @@ -21,26 +29,54 @@
<script src="videojs.vast.js"></script>
</head>
<body>
<p style="background-color:#eee; border: 1px solid #777; padding: 10px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;">This page shows you how to create, register and initialize a Video.js plugin.</p>

<video id="vid1" class="video-js vjs-default-skin" autoplay controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='640'
height='400'
>
<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'>
<p>Video Playback Not Supported</p>
</video>
<p class="description">Video.js VAST plugin examples.</p>

<div class="example-video-container">
<p class="description">No autoplay.</p>

<video id="vid1" class="video-js vjs-default-skin" controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='640'
height='400'
>
<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'>
<p>Video Playback Not Supported</p>
</video>
</div>

<div class="example-video-container">
<p class="description">With autoplay.</p>

<video id="vid2" class="video-js vjs-default-skin" autoplay controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='640'
height='400'
>
<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'>
<p>Video Playback Not Supported</p>
</video>
</div>

<script>
var vid1 = videojs('vid1');
var vid1 = videojs('vid1'),
vid2 = videojs('vid2');

vid1.muted(true);
vid1.ads();
vid1.vast({
url: 'http://ad3.liverail.com/?LR_PUBLISHER_ID=1331&LR_CAMPAIGN_ID=229&LR_SCHEMA=vast2'
url: 'http://videoads.theonion.com/vast/270.xml'
});

vid2.muted(true);
vid2.ads();
vid2.vast({
url: 'http://videoads.theonion.com/vast/270.xml'
});
</script>

Expand Down
131 changes: 17 additions & 114 deletions spec/VastPluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,19 @@ describe('videojs.vast plugin', function() {
});

it("should bail out if player.ads isn't defined", function() {
spyOn(console, "log");
spyOn(this.p.vast, "createSourceObjects");
spyOn(console, "error");
this.p.ads = undefined;
this.p.vast({url:"i wanna go VAST!"});
expect(console.log).toHaveBeenCalledWith(jasmine.any(String));
expect(this.p.vast.createSourceObjects).not.toHaveBeenCalled();
var result = this.p.vast({url:"i wanna go VAST!"});
expect(result).toBe(null);
expect(console.error).toHaveBeenCalledWith(jasmine.any(String));
});

it("should bail out if no url is provided", function() {
spyOn(this.p.vast, "createSourceObjects");
spyOn(this.p, "trigger");
this.p.ads();
this.p.vast({});
var result = this.p.vast({});
expect(result).toBe(null);
expect(this.p.trigger).toHaveBeenCalledWith("adtimeout");
expect(this.p.vast.createSourceObjects).not.toHaveBeenCalled();
});

it("should request an ad if a source is already loaded", function() {
Expand All @@ -96,6 +94,7 @@ describe('videojs.vast plugin', function() {
describe("createSourceObjects", function() {

it("should return objects with 'src', 'type', 'width', and 'height' properties", function() {
player.vast({ url: 'balhbahblhab' });
var media_files = [
{
fileURL: "TRL",
Expand All @@ -118,82 +117,13 @@ describe('videojs.vast plugin', function() {
expect(sources[s].height).toBeDefined();
}
});

//phantomjs does not support video
xit("should not accept all video formats", function() {
var media_files = [
{
fileURL: "TRL",
mimeType: "video/flv",
width: 640,
height: 360
},
{
fileURL: "So Trill",
mimeType: "video/x-flv",
width: 512,
height: 288
},
{
fileURL: "Skrill, WHERES MY SKRILL",
mimeType: "video/mpeg",
width: 0,
height: 0
},
{
fileURL: "Jack and Jill",
mimeType: "video/ogg",
width: 1280,
height: 720
},
{
fileURL: "-- Code Raps -- ",
mimeType: "hls/playlist.m3u8",
width: 640,
height: 480
},
{
fileURL: "I'm tapped",
mimeType: "video/avi",
width: 512,
height: 384
},
{
fileURL: "BuddhaForRill",
mimeType: "video/mp4",
width: 1920,
height: 1080
}
];
var sources = player.vast.createSourceObjects(media_files);
expect(sources.length).toBe(1);
});

//phantomjs does not support video
xit("can return sources with duplicate formats", function() {
var media_files = [
{
fileURL: "TRL",
mimeType: "video/mp4",
width: 640,
height: 360
},
{
fileURL: "BuddhaForRill",
mimeType: "video/mp4",
width: 853,
height: 480
}
];
var sources = player.vast.createSourceObjects(media_files);
expect(sources.length).toBe(2);
});

});

describe("tearDown", function() {

it("should end the linear ad", function() {
player.vast({ url: 'balhbahblhab' });

spyOn(player.ads, "endLinearAdMode");
spyOn(player, "off");

Expand All @@ -207,11 +137,13 @@ describe('videojs.vast plugin', function() {
expect(player.off).toHaveBeenCalledWith("ended", jasmine.any(Function));
expect(player.ads.endLinearAdMode).toHaveBeenCalled();
});

});

describe("preroll", function() {

beforeEach(function() {
player.vast({ url: 'balhbahblhab' });
player.vastTracker = {
clickThroughURLTemplate: "a whole new page",
clickTrackingURLTemplate: "a new fantastic advertisement",
Expand All @@ -224,6 +156,7 @@ describe('videojs.vast plugin', function() {
it("should start the ad", function() {
spyOn(player.ads, "startLinearAdMode");
spyOn(player, "src");
player.vast.sources = [];
player.vast.preroll();
expect(player.ads.startLinearAdMode).toHaveBeenCalled();
expect(player.src).toHaveBeenCalledWith(jasmine.any(Array));
Expand All @@ -239,6 +172,7 @@ describe('videojs.vast plugin', function() {

describe("getContent", function() {
it("should bail out if there aren't playable media files", function() {
player.vast({ url: 'balhbahblhab' });
spyOn(DMVAST.client, "get").and.callFake(function(url, callback){
var fake_response = {
ads: [{
Expand All @@ -250,15 +184,15 @@ describe('videojs.vast plugin', function() {
};
callback(fake_response);
});

spyOn(player, "trigger");
player.vast.getContent("some url");
expect(player.trigger).toHaveBeenCalledWith("adtimeout");
});

describe("linear ads", function() {
beforeEach(function() {
spyOn(vast.client, "get")
spyOn(DMVAST.client, "get")
.and.callFake(function(url, callback){
var fake_response = {
ads: [{
Expand All @@ -271,38 +205,6 @@ describe('videojs.vast plugin', function() {
callback(fake_response);
});
});

//phantomjs does not support video
xit("should create a vast tracker", function() {
spyOn(vast, "tracker");
player.vast.getContent("some url");
expect(vast.tracker).toHaveBeenCalled();
expect(player.vastTracker).toBeDefined();
});

//phantomjs does not support video
xit("should guarantee that assetDuration is defined", function() {
spyOn(vast, "tracker").and.returnValue({
setProgress: function(){}
});
spyOn(player, "duration").and.returnValue(11);
spyOn(player, "currentTime").and.returnValue(11);
player.vast.getContent("some url");

/*
Forcing some implementation here, but the
duration fail-safe is a hack anyway.
*/
player.trigger("timeupdate");
expect(player.vastTracker.assetDuration).toBe(11);
});

//phantomjs does not support video
xit("should trigger the 'adsready' event", function() {
spyOn(player, "trigger");
player.vast.getContent("some url");
expect(player.trigger).toHaveBeenCalledWith("adsready");
});
});

describe("non-linear ads", function() {
Expand All @@ -322,6 +224,7 @@ describe('videojs.vast plugin', function() {
});
});
it("should do nothing with non-linear ads, and report the error", function() {
player.vast({ url: 'balhbahblhab' });
spyOn(DMVAST.util, "track");
spyOn(player, "trigger");
player.vast.getContent("some url");
Expand Down
Loading

0 comments on commit 1a27c81

Please sign in to comment.