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

Fix: Retain quality setting when setting/switching audio tracks #720

Merged
merged 6 commits into from
Mar 29, 2018
Merged

Fix: Retain quality setting when setting/switching audio tracks #720

merged 6 commits into from
Mar 29, 2018

Conversation

jeremypress
Copy link
Contributor

This fixes a few bugs around track selection by shaka player. We will now retain the current quality when changing audio tracks.

Tests on the way

@boxcla
Copy link

boxcla commented Mar 15, 2018

Verified that @jeremypress has signed the CLA. Thanks for the pull request!

this.player.addEventListener('error', this.shakaErrorHandler);
this.player.configure({
abr: {
enabled: true
enabled: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting this to false by default, it will get overridden if 'auto' is saved in our cache as the current quality setting.

* @param {Object} shakaError - Error to handle
* @return {void}
*/
shakaManifestHandler() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only moved things that are dependent on the manifest here. This should give a slight performance gain as we will zero in on our target quality faster than if we waited for loadeddata.

Copy link
Contributor

Choose a reason for hiding this comment

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

💯 I should look into adding startAt here as well. I think there was a bug which I had to work around before but pretty sure they fixed it

Copy link
Contributor

@DanDeMicco DanDeMicco left a comment

Choose a reason for hiding this comment

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

Looks good, just some small polish and tests needed

const track = this.audioTracks[audioIdx];
this.player.selectAudioLanguage(track.language, track.role);
this.enableAudioId(track.role);
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be newAudioTrack, delete previous line

* @param {Object} shakaError - Error to handle
* @return {void}
*/
shakaManifestHandler() {
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 I should look into adding startAt here as well. I think there was a bug which I had to work around before but pretty sure they fixed it

enableAudioId(role) {
const tracks = this.player.getVariantTracks();
const activeTrack = this.getActiveTrack();
const newTrack = tracks.find((track) => track.roles[0] === role && track.videoId === activeTrack.videoId);
Copy link
Contributor

Choose a reason for hiding this comment

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

a comment here would be good

@@ -387,6 +408,25 @@ class DashViewer extends VideoBaseViewer {
}
}

/**
* Handles streaming event which is the first time the manifest is available. See https://shaka-player-demo.appspot.com/docs/api/shaka.util.Error.html
Copy link
Contributor

Choose a reason for hiding this comment

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

Update these docs. Looks like you're no longer handling/accepting a shakaError param

Copy link
Contributor

@DanDeMicco DanDeMicco left a comment

Choose a reason for hiding this comment

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

revert the startAt stuff here (my fault, sorry). Other than that, looks good

dash.startTimeInSeconds = START_TIME_IN_SECONDS;
sandbox.stub(shaka, 'Player').returns(dash.player);
stubs.mockPlayer.expects('load').withArgs('url', START_TIME_IN_SECONDS).returns(Promise.resolve());
// it('should load the player with the start time', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean to comment this out?

sandbox.stub(shaka, 'Player').returns(dash.player);
stubs.mockPlayer.expects('load').withArgs('url', START_TIME_IN_SECONDS).returns(Promise.resolve());
// it('should load the player with the start time', () => {
// const START_TIME_IN_SECONDS = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

same with this

this.loadUI();

this.player.configure({
playRangeStart: this.startTimeInSeconds
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

@@ -171,7 +173,7 @@ class DashViewer extends VideoBaseViewer {
this.player.getNetworkingEngine().registerRequestFilter(this.requestFilter);

this.startLoadTimer();
this.player.load(this.mediaUrl, this.startTimeInSeconds).catch(this.shakaErrorHandler);
this.player.load(this.mediaUrl).catch(this.shakaErrorHandler);
Copy link
Contributor

Choose a reason for hiding this comment

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

add the startAt back here

this.player.selectAudioLanguage(track.language, track.role);
const newAudioTrack = this.audioTracks[audioIdx];
if (newAudioTrack !== undefined) {
this.enableAudioId(newAudioTrack.role);
Copy link
Contributor

Choose a reason for hiding this comment

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

This'll throw an error if newAudioTrack is anything but an Object, due to accessing role, and only checking if it's not undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is how we build the audio tracks

   this.audioTracks = uniqueAudioVariants.map((track) => ({
            language: track.language,
            role: track.roles[0]
        }));

We make this assumption that tracks coming back from the manifest are objects all over the code. Should I trust this as a fact or add the check everywhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Dang, I gotcha. So if there can only ever be undefined OR an object like this, that sounds fine by me as is

@jeremypress jeremypress merged commit adc84e1 into box:master Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants