Skip to content

Commit

Permalink
Extend Player track methods to cover native HLS
Browse files Browse the repository at this point in the history
Track methods are now implemented for native HLS and other src=
playbacks.  This will allow the UI to select text and audio languages.

This change adds best-effort methods to get track information for src=
playbacks, including native HLS on Safari.  In many cases, it relies
on the audioTracks and videoTracks members of HTMLVideoElement which
are only implemented on Safari.  They are in the spec, though, so
there's no harm in using them when they exist.

This is fully parallel to the manifest-based paradigm for MSE-based
playbacks.  Each of these top-level methods in Player has an "if" to
decide which way to supply the requested info, except for the language
methods, which now delegate to the track methods.

With this, Safari's native HLS can supply audio and text language
information to the UI/app, and the UI/app can have some control over
those things through the tracks API.  I believe this is important to
the success of our new iOS support.

Issue #997
Issue #382

Change-Id: Icc44a932927fafedda1b62a9d4c6e2ed3dc7db30
  • Loading branch information
joeyparrish committed Apr 30, 2019
1 parent 56a48ec commit 8391fe1
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 196 deletions.
67 changes: 67 additions & 0 deletions externs/audiotrack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Externs for AudioTrack which are missing from the Closure
* compiler.
*
* @externs
*/

/** @constructor */
function AudioTrack() {}

/** @type {boolean} */
AudioTrack.prototype.enabled;

/** @type {string} */
AudioTrack.prototype.id;

/** @type {string} */
AudioTrack.prototype.kind;

/** @type {string} */
AudioTrack.prototype.label;

/** @type {string} */
AudioTrack.prototype.language;

/** @type {SourceBuffer} */
AudioTrack.prototype.sourceBuffer;


/**
* @extends {IArrayLike.<AudioTrack>}
* @extends {EventTarget}
* @interface
*/
function AudioTrackList() {}

/** @override */
AudioTrackList.prototype.addEventListener =
function(type, listener, useCapture) {};

/** @override */
AudioTrackList.prototype.removeEventListener =
function(type, listener, useCapture) {};

/** @override */
AudioTrackList.prototype.dispatchEvent = function(event) {};


/** @type {AudioTrackList} */
HTMLMediaElement.prototype.audioTracks;
4 changes: 4 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ shaka.extern.BufferedInfo;
* videoCodec: ?string,
* primary: boolean,
* roles: !Array.<string>,
* audioRoles: Array.<string>,
* videoId: ?number,
* audioId: ?number,
* channelsCount: ?number,
Expand Down Expand Up @@ -248,6 +249,9 @@ shaka.extern.BufferedInfo;
* cannot be satisfied.
* @property {!Array.<string>} roles
* The roles of the track, e.g. 'main', 'caption', or 'commentary'.
* @property {Array.<string>} audioRoles
* The roles of the audio in the track, e.g. 'main' or 'commentary'.
* Will be null for text tracks or variant tracks without audio.
* @property {?number} videoId
* (only for variant tracks) The video stream id.
* @property {?number} audioId
Expand Down
11 changes: 6 additions & 5 deletions externs/texttrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

/**
* @fileoverview Externs for TextTrack and TextTrackCue which are
* missing from the closure compiler.
* missing from the Closure compiler.
*
* @externs
*/

/** @type {string} */
TextTrack.prototype.id;

/** @type {string} */
TextTrack.prototype.kind;

/** @type {string} */
TextTrack.prototype.label;
Expand All @@ -30,18 +35,14 @@ TextTrack.prototype.label;
/** @type {string} */
TextTrackCue.prototype.positionAlign;


/** @type {string} */
TextTrackCue.prototype.lineAlign;


/** @type {number|null|string} */
TextTrackCue.prototype.line;


/** @type {string} */
TextTrackCue.prototype.vertical;


/** @type {boolean} */
TextTrackCue.prototype.snapToLines;
67 changes: 67 additions & 0 deletions externs/videotrack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Externs for VideoTrack which are missing from the Closure
* compiler.
*
* @externs
*/

/** @constructor */
function VideoTrack() {}

/** @type {boolean} */
VideoTrack.prototype.selected;

/** @type {string} */
VideoTrack.prototype.id;

/** @type {string} */
VideoTrack.prototype.kind;

/** @type {string} */
VideoTrack.prototype.label;

/** @type {string} */
VideoTrack.prototype.language;

/** @type {SourceBuffer} */
VideoTrack.prototype.sourceBuffer;


/**
* @extends {IArrayLike.<VideoTrack>}
* @extends {EventTarget}
* @interface
*/
function VideoTrackList() {}

/** @override */
VideoTrackList.prototype.addEventListener =
function(type, listener, useCapture) {};

/** @override */
VideoTrackList.prototype.removeEventListener =
function(type, listener, useCapture) {};

/** @override */
VideoTrackList.prototype.dispatchEvent = function(event) {};


/** @type {VideoTrackList} */
HTMLMediaElement.prototype.videoTracks;
Loading

0 comments on commit 8391fe1

Please sign in to comment.