Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cuechange events in HLS playback #2476

Merged
merged 6 commits into from
Apr 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,27 @@ goog.require('shaka.util.Timer');
*/


/**
* @event shaka.Player.MetadataEvent
* @description Triggers after metadata associated with the stream is found.
* Usually they are metadata of type ID3.
* @property {string} type
* 'metadata'
* @property {number} startTime
* The time that describes the beginning of the range of the metadata to
* which the cue applies.
* @property {number} endTime
* The time that describes the end of the range of the metadata to which
* the cue applies.
* @property {string} type
* Type of metadata. Eg: org.id3 or org.mp4ra
* @property {Object} payload
* ID3 metadata, it's essentially a Map of <Any, Any>
* https://id3.org/id3v2.3.0#Declared_ID3v2_frames
* @exportDoc
*/


/**
* @event shaka.Player.StreamingEvent
* @description Fired after the manifest has been parsed and track information
Expand Down Expand Up @@ -2110,8 +2131,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}

/**
* We're looking for metadata tracks to process id3 tags for ad info on LIVE
* streams
* We're looking for metadata tracks to process id3 tags. One of the uses is
* for ad info on LIVE streams
*
* @param {!Event} event
* @private
Expand All @@ -2125,6 +2146,14 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
track.mode = 'hidden';
this.eventManager_.listen(track, 'cuechange', () => {
for (const cue of track.activeCues) {
const eventName = shaka.Player.EventName.Metadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, is this whole method only applicable to Safari or is it gonna work for all the browsers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now only Safari, but it will work in all browsers, mux.js exposes the ID3 metadata but it is still not handled in the app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Is it related to this PR or is that separate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR is the base, but you still have to process the data and expose it to the SS and launch the metadata event. I had planned to work on this soon, but I have two more urgent PR for this week according to our needs.

const data = {
startTime: cue.startTime,
endTime: cue.endTime,
type: cue.type,
payload: cue.value,
};
this.dispatchEvent(this.makeEvent_(eventName, data));
if (this.adManager_) {
this.adManager_.onCueMetadataChange(cue.value);
}
Expand Down Expand Up @@ -5016,6 +5045,7 @@ shaka.Player.EventName = {
Loaded: 'loaded',
Loading: 'loading',
ManifestParsed: 'manifestparsed',
Metadata: 'metadata',
OnStateChange: 'onstatechange',
OnStateIdle: 'onstateidle',
RateChange: 'ratechange',
Expand Down