Skip to content

Commit

Permalink
feat: Utilize option to override native on tech (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
OshinKaramian authored and forbesjo committed Jun 6, 2018
1 parent d6f5005 commit 5c7ab4c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,24 @@ is true, if the platform supports Media Source Extensions
videojs-http-streaming will take over HLS playback to provide a more
consistent experience.

__NOTE__: If you use this option, you must also set
`html5.nativeAudioTracks` and `html5.nativeVideoTracks` to
`false`. videojs-http-streaming relies on audio and video tracks to play
streams with alternate audio and requires additional capabilities only
supported by non-native tracks in video.js.

```javascript
// via the constructor
var player = videojs('playerId', {
html5: {
nativeAudioTracks: false,
nativeVideoTracks: false,
hls: {
overrideNative: true
}
}
});

// via the source
var player = videojs('playerId');

player.src({
src: 'https://example.com/index.m3u8',
type: 'application/x-mpegURL',
overrideNative: true
});
```

##### blacklistDuration
Expand Down
2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
(function(window, videojs) {
var player = window.player = videojs('videojs-http-streaming-player', {
html5: {
nativeAudioTracks: !!videojs.browser.IS_SAFARI,
nativeVideoTracks: !!videojs.browser.IS_SAFARI,
hls: {
overrideNative: !videojs.browser.IS_SAFARI
}
Expand Down
11 changes: 8 additions & 3 deletions src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,15 @@ class HlsHandler extends Component {
this.ignoreNextSeekingEvent_ = false;
this.setOptions_();

// overriding native HLS only works if audio tracks have been emulated
// error early if we're misconfigured:
if (this.options_.overrideNative &&
(tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
tech.overrideNativeAudioTracks &&
tech.overrideNativeVideoTracks) {
tech.overrideNativeAudioTracks(true);
tech.overrideNativeVideoTracks(true);
} else if (this.options_.overrideNative &&
(tech.featuresNativeVideoTracks || tech.featuresNativeAudioTracks)) {
// overriding native HLS only works if audio tracks have been emulated
// error early if we're misconfigured
throw new Error('Overriding native HLS requires emulated tracks. ' +
'See https://git.io/vMpjB');
}
Expand Down
27 changes: 13 additions & 14 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1988,13 +1988,13 @@ QUnit.test('loads if native HLS is available and override is set locally', funct
player = createPlayer({html5: {hls: {overrideNative: true}}});
this.clock.tick(1);
player.tech_.featuresNativeVideoTracks = true;
assert.throws(function() {
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/x-mpegURL'
});
this.clock.tick(1);
}, 'errors if native tracks are enabled');
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/x-mpegURL'
});
this.clock.tick(1);

assert.ok(player.tech_.hls, 'did load hls tech');
player.dispose();

player = createPlayer({html5: {hls: {overrideNative: true}}});
Expand All @@ -2018,13 +2018,12 @@ QUnit.test('loads if native HLS is available and override is set globally', func
Hls.supportsNativeHls = true;
player = createPlayer();
player.tech_.featuresNativeVideoTracks = true;
assert.throws(function() {
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/x-mpegURL'
});
this.clock.tick(1);
}, 'errors if native tracks are enabled');
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/x-mpegURL'
});
this.clock.tick(1);
assert.ok(player.tech_.hls, 'did load hls tech');
player.dispose();

player = createPlayer();
Expand Down
4 changes: 0 additions & 4 deletions utils/stats/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ <h3>Timed Metadata</h3>
}

videojs.options.hls.overrideNative = overrideNative === 'on';
if (videojs.options.hls.overrideNative) {
videojs.options.html5.nativeAudioTracks = false;
videojs.options.html5.nativeVideoTracks = false;
}

var type = document.getElementById('url-content-type').value;
// use the form data to add a src to the player
Expand Down

0 comments on commit 5c7ab4c

Please sign in to comment.