Skip to content

Commit

Permalink
Stop using deprecated methods in tests and tutorials.
Browse files Browse the repository at this point in the history
Closes #73.

Change-Id: I1b32add49137a20f89654d5bbef37ea7a05d3524
  • Loading branch information
joeyparrish authored and Gerrit Code Review committed May 22, 2015
1 parent 562bee2 commit e4a0dc3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 62 deletions.
73 changes: 23 additions & 50 deletions spec/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ describe('Player', function() {
// This covers basic player re-use.
it('can be used multiple times without EME', function(done) {
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
return player.load(newSource(plainManifest));
}).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
expect(video.currentTime).toBeGreaterThan(0.0);
Expand All @@ -118,12 +118,12 @@ describe('Player', function() {
// to be unset on the second use of a video tag.
it('can be used multiple times with EME', function(done) {
player.load(newSource(encryptedManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
return player.load(newSource(encryptedManifest));
}).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
expect(video.currentTime).toBeGreaterThan(0.0);
Expand All @@ -140,7 +140,7 @@ describe('Player', function() {
player.load(newSource(plainManifest)).then(function() {
var track = getVideoTrackByHeight(720);
player.selectVideoTrack(track.id);
player.play();
video.play();
// adapts by the time it crosses a segment boundary.
return waitForTargetTime(6.0, 10.0);
}).then(function() {
Expand All @@ -156,7 +156,7 @@ describe('Player', function() {
player.load(newSource(plainManifest)).then(function() {
var track = getVideoTrackByHeight(720);
player.selectVideoTrack(track.id);
player.play();
video.play();
// adapts by the time it crosses a segment boundary.
return waitForTargetTime(6.0, 10.0);
}).then(function() {
Expand All @@ -176,46 +176,19 @@ describe('Player', function() {
});
});

describe('pause', function() {
it('pauses playback', function(done) {
var timestamp;
player.load(newSource(plainManifest)).then(function() {
player.play();
return waitForMovement();
}).then(function() {
expect(video.paused).toBe(false);
player.pause();
timestamp = video.currentTime;
return delay(1.0);
}).then(function() {
expect(video.paused).toBe(true);
expect(video.currentTime).toEqual(timestamp);
player.play();
return waitForMovement();
}).then(function() {
expect(video.paused).toBe(false);
expect(video.currentTime).toBeGreaterThan(timestamp);
done();
}).catch(function(error) {
fail(error);
done();
});
});
});

describe('seek', function() {
// This covers bug #18597152. Completely clearing the buffers after a seek
// can cause the media pipeline in Chrome to get stuck. This seemed to
// happen when certain seek intervals were used.
it('does not lock up on segment boundaries', function(done) {
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForMovement(); // gets the player out of INIT state
}).then(function() {
player.seek(40.0); // <0.1s before end of segment N (5).
video.currentTime = 40.0; // <0.1s before end of segment N (5).
return delay(2.0);
}).then(function() {
player.seek(30.0); // <0.1s before end of segment N-2 (3).
video.currentTime = 30.0; // <0.1s before end of segment N-2 (3).
return delay(5.0);
}).then(function() {
// Typically this bug manifests with seeking == true.
Expand Down Expand Up @@ -244,15 +217,15 @@ describe('Player', function() {
// not done, playback gets "stuck" when the playhead enters such a gap.
it('does not create unclosable gaps in the buffer', function(done) {
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
player.seek(33.0);
video.currentTime = 33.0;
return waitForMovement();
}).then(function() {
return delay(1.0);
}).then(function() {
player.seek(28.0);
video.currentTime = 28.0;
// We don't expect 38.0 because of the uncertainty of network and other
// delays. This is a safe number which will not cause false failures.
// When this bug manifests, the playhead typically gets stuck around
Expand Down Expand Up @@ -304,7 +277,7 @@ describe('Player', function() {
}).then(function() {
// The content is now buffered.
expect(audioStreamBuffer.buffered.length).toBe(1);
player.play();
video.play();
return waitForMovement();
}).then(function() {
// Power through and consume the audio data quickly.
Expand All @@ -315,7 +288,7 @@ describe('Player', function() {
// Otherwise, this test hasn't reproduced the circumstances correctly.
expect(audioStreamBuffer.buffered.start(0)).toBeGreaterThan(0);
// Seek to the beginning, which is data we will have to re-download.
player.seek(0);
video.currentTime = 0;
// Expect to play some.
return waitForTargetTime(0.5, 2.0);
}).then(function() {
Expand All @@ -333,7 +306,7 @@ describe('Player', function() {
var source = newSource(plainManifest);

player.load(source).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
// Move quickly past the first two segments.
Expand All @@ -351,7 +324,7 @@ describe('Player', function() {
// later than where we adapted.
return waitForTargetTime(22.0, 6.0);
}).then(function() {
player.seek(0);
video.currentTime = 0;
return waitForMovement();
}).then(function() {
return waitForTargetTime(21.0, 12.0);
Expand All @@ -367,7 +340,7 @@ describe('Player', function() {
var source = newSource(plainManifest);

player.load(source).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
var Stream = shaka.media.Stream;
Expand All @@ -379,7 +352,7 @@ describe('Player', function() {
expect(ok).toBe(true);
expect(videoStream.state_).toBe(Stream.State_.SWITCHING);

player.seek(30.0);
video.currentTime = 30.0;
return waitForTargetTime(33.0, 5.0);
}).then(function() {
done();
Expand All @@ -395,7 +368,7 @@ describe('Player', function() {
var onSeeking = jasmine.createSpy('onSeeking');

player.load(source).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
video.addEventListener('seeking', onSeeking);
Expand Down Expand Up @@ -502,7 +475,7 @@ describe('Player', function() {
it('plays faster for rates above 1', function(done) {
var timestamp;
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
expect(video.currentTime).toBeGreaterThan(0.0);
Expand All @@ -522,7 +495,7 @@ describe('Player', function() {
it('plays in reverse for negative rates', function(done) {
var timestamp;
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForTargetTime(3.0, 5.0);
}).then(function() {
timestamp = video.currentTime;
Expand All @@ -544,7 +517,7 @@ describe('Player', function() {
it('updates playTime', function(done) {
var oldPlayTime;
player.load(newSource(plainManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
oldPlayTime = player.getStats().playTime;
Expand Down Expand Up @@ -757,7 +730,7 @@ describe('Player', function() {

it('plays VP9 WebM', function(done) {
player.load(newSource(webmManifest)).then(function() {
player.play();
video.play();
return waitForMovement();
}).then(function() {
expect(video.currentTime).toBeGreaterThan(0.0);
Expand Down
16 changes: 11 additions & 5 deletions tutorials/offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ <h3 class="tutorial-heading">
&lt;/video&gt;
&lt;/body&gt;
&lt;script&gt;
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down Expand Up @@ -183,12 +185,14 @@ <h3 class="tutorial-heading">
&lt;/video&gt;
&lt;/body&gt;
&lt;script&gt;
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down Expand Up @@ -269,7 +273,7 @@ <h3 class="tutorial-heading">
<span class="newCode"> new shaka.player.OfflineVideoSource(window.groupId, null);</span>
<span class="newCode"> return window.player.load(offlineSource).then(</span>
<span class="newCode"> function() {</span>
<span class="newCode"> window.player.play();</span>
<span class="newCode"> video.play();</span>
<span class="newCode"> console.log('Offline content with group ID ' + window.groupId +</span>
<span class="newCode"> ' ready for playback.');</span>
<span class="newCode"> });</span>
Expand Down Expand Up @@ -314,12 +318,14 @@ <h3 class="tutorial-heading">
&lt;/video&gt;
&lt;/body&gt;
&lt;script&gt;
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down Expand Up @@ -400,7 +406,7 @@ <h3 class="tutorial-heading">
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
video.play();
console.log('Offline content with group ID ' + window.groupId +
' ready for playback.');
});
Expand Down
2 changes: 1 addition & 1 deletion tutorials/player.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ <h3 class="tutorial-heading">
<span class="newCode"> }</span>
<span class="newCode"></span>
<span class="newCode"> // Begin playback, since autoplay is not enabled on the video tag.</span>
<span class="newCode"> player.play();</span>
<span class="newCode"> video.play();</span>
<span class="newCode"> });</span>
}
document.addEventListener('DOMContentLoaded', initPlayer);
Expand Down
2 changes: 1 addition & 1 deletion tutorials/sample3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}

// Begin playback, since autoplay is not enabled on the video tag.
player.play();
video.play();
});
}
document.addEventListener('DOMContentLoaded', initPlayer);
Expand Down
4 changes: 3 additions & 1 deletion tutorials/sample7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
</video>
</body>
<script>
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down
6 changes: 4 additions & 2 deletions tutorials/sample8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
</video>
</body>
<script>
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down Expand Up @@ -101,7 +103,7 @@
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
video.play();
console.log('Offline content with group ID ' + window.groupId +
' ready for playback.');
});
Expand Down
6 changes: 4 additions & 2 deletions tutorials/sample9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
</video>
</body>
<script>
var video;

function initPlayer() {
// Install polyfills.
shaka.polyfill.installAll();

// Find the video element.
var video = document.getElementById('video');
video = document.getElementById('video');

// Attach the player to the window so that it can be easily debugged.
window.player = new shaka.player.Player(video);
Expand Down Expand Up @@ -101,7 +103,7 @@
new shaka.player.OfflineVideoSource(window.groupId, null);
return window.player.load(offlineSource).then(
function() {
window.player.play();
video.play();
console.log('Offline content with group ID ' + window.groupId +
' ready for playback.');
});
Expand Down

0 comments on commit e4a0dc3

Please sign in to comment.