Skip to content

Commit

Permalink
chore: sync videojs-contrib-hls updates (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
forbesjo authored Apr 4, 2018
1 parent 27ed914 commit 9223588
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ videojs(video, {html5: {
// or

var options = {hls: {
withCredentials: true;
withCredentials: true
}};

videojs(video, {html5: options});
Expand Down Expand Up @@ -581,6 +581,10 @@ will have this structure

```javascript
cue.value = {
byteLength, // The size of the segment in bytes
bandwidth, // The peak bitrate reported by the segment's playlist
resolution, // The resolution reported by the segment's playlist
codecs, // The codecs reported by the segment's playlist
uri, // The Segment uri
timeline, // Timeline of the segment for detecting discontinuities
playlist, // The Playlist uri
Expand Down
8 changes: 7 additions & 1 deletion src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,13 @@ export class MasterPlaylistController extends videojs.EventTarget {
// code in video.js but is required because play() must be invoked
// *after* the media source has opened.
if (this.tech_.autoplay()) {
this.tech_.play();
const playPromise = this.tech_.play();

// Catch/silence error when a pause interrupts a play request
// on browsers which return a promise
if (typeof playPromise !== 'undefined' && typeof playPromise.then === 'function') {
playPromise.then(null, (e) => {});
}
}

this.trigger('sourceopen');
Expand Down
4 changes: 4 additions & 0 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@ export default class SegmentLoader extends videojs.EventTarget {

const Cue = window.WebKitDataCue || window.VTTCue;
const value = {
bandwidth: segmentInfo.playlist.attributes.BANDWIDTH,
resolution: segmentInfo.playlist.attributes.RESOLUTION,
codecs: segmentInfo.playlist.attributes.CODECS,
byteLength: segmentInfo.byteLength,
uri: segmentInfo.uri,
timeline: segmentInfo.timeline,
playlist: segmentInfo.playlist.uri,
Expand Down
15 changes: 15 additions & 0 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2501,3 +2501,18 @@ QUnit.test('properly configures loader mime types', function(assert) {
'correct mime type for audio segment loader');
assert.notOk(audioMimeTypeCalls[0][1], 'no source buffer emitter');
});

QUnit.test('Exception in play promise should be caught', function(assert) {
const mpc = this.masterPlaylistController;

mpc.setupSourceBuffers = () => true;
mpc.tech_ = {
autoplay: () => true,
play: () => new Promise(function(resolve, reject) {
reject(new DOMException());
})
};
mpc.handleSourceOpen_();

assert.ok(true, 'rejects dom exception');
});
31 changes: 26 additions & 5 deletions test/segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,12 @@ QUnit.module('SegmentLoader', function(hooks) {
'as they are buffered',
function(assert) {
const track = loader.segmentMetadataTrack_;
let playlist = playlistWithDuration(50);
const attributes = {
BANDWIDTH: 3500000,
RESOLUTION: '1920x1080',
CODECS: 'mp4a.40.5,avc1.42001e'
};
let playlist = playlistWithDuration(50, {attributes});
let probeResponse;
let expectedCue;

Expand Down Expand Up @@ -441,7 +446,11 @@ QUnit.module('SegmentLoader', function(hooks) {
timeline: 0,
playlist: 'playlist.m3u8',
start: 0,
end: 9.5
end: 9.5,
bandwidth: 3500000,
resolution: '1920x1080',
codecs: 'mp4a.40.5,avc1.42001e',
byteLength: 10
};

assert.equal(track.cues.length, 1, 'one cue added for segment');
Expand All @@ -458,7 +467,11 @@ QUnit.module('SegmentLoader', function(hooks) {
timeline: 0,
playlist: 'playlist.m3u8',
start: 9.56,
end: 19.2
end: 19.2,
bandwidth: 3500000,
resolution: '1920x1080',
codecs: 'mp4a.40.5,avc1.42001e',
byteLength: 10
};

assert.equal(track.cues.length, 2, 'one cue added for segment');
Expand All @@ -475,7 +488,11 @@ QUnit.module('SegmentLoader', function(hooks) {
timeline: 0,
playlist: 'playlist.m3u8',
start: 19.24,
end: 28.99
end: 28.99,
bandwidth: 3500000,
resolution: '1920x1080',
codecs: 'mp4a.40.5,avc1.42001e',
byteLength: 10
};

assert.equal(track.cues.length, 3, 'one cue added for segment');
Expand All @@ -494,7 +511,11 @@ QUnit.module('SegmentLoader', function(hooks) {
timeline: 0,
playlist: 'playlist.m3u8',
start: 19.21,
end: 28.98
end: 28.98,
bandwidth: 3500000,
resolution: '1920x1080',
codecs: 'mp4a.40.5,avc1.42001e',
byteLength: 10
};

assert.equal(track.cues.length, 3, 'overlapped cue removed, new one added');
Expand Down
2 changes: 1 addition & 1 deletion test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export const playlistWithDuration = function(time, conf) {
uri: conf && typeof conf.uri !== 'undefined' ? conf.uri : 'playlist.m3u8',
discontinuitySequence:
conf && conf.discontinuitySequence ? conf.discontinuitySequence : 0,
attributes: {}
attributes: conf && typeof conf.attributes !== 'undefined' ? conf.attributes : {}
};
let count = Math.floor(time / 10);
let remainder = time % 10;
Expand Down

0 comments on commit 9223588

Please sign in to comment.