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

Add mediaCannotPlay and onTrackPlaybackFailure #356

Merged
merged 6 commits into from
Feb 10, 2019

Conversation

danielr18
Copy link
Contributor

Solves #352.

I documented mediaCannotPlay, but not onTrackPlaybackFailure, since the markdown file for playerContextProvider is empty and the Readme options look outdated.

@danielr18
Copy link
Contributor Author

Don't know if we should pass the activeTrackIndex or something to onTrackPlaybackFailure.

Copy link
Owner

@benwiley4000 benwiley4000 left a comment

Choose a reason for hiding this comment

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

Awesome thank you! Looks great!

I've got a handful of comments - left me know if you have any questions.

@@ -166,6 +153,10 @@ export class PlayerContextProvider extends Component {
this.videoHostOccupiedCallbacks = new Map();
this.videoHostVacatedCallbacks = new Map();

// bind internal methods
this.setMediaElementSources = this.setMediaElementSources.bind(this);
Copy link
Owner

Choose a reason for hiding this comment

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

I think setMediaElementSources doesn't need to be bound, unless I missed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

setMediaElementSources method uses this, wouldn't that require it to be bound?

Copy link
Owner

Choose a reason for hiding this comment

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

It's not passed anywhere as a callback so it's bound at call time when we call this.setMediaElementSources(...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, yes! Just removed it.

if (source.type) {
sourceElement.type = source.type;
}
sourceElement.addEventListener('error', this.onTrackPlaybackFailure);
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should remove the event listeners on the source elements on component unmount, in case someone is holding onto a reference to the media element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't it be garbage collected as you said in the issue?

https://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory

Except in old browsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However, doesn't hurt to remove them, check out the last commit.

Copy link
Owner

Choose a reason for hiding this comment

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

Normally yes, but if someone retained an outside ref to the media element then I want to make sure we don't have callbacks belonging to an unmounted component getting called.

mediaCannotPlay: true
});
if (this.props.onTrackPlaybackFailure) {
this.props.onTrackPlaybackFailure(event);
Copy link
Owner

Choose a reason for hiding this comment

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

I think this should be:

this.props.onTrackPlaybackFailure(
  this.props.playlist[this.state.activeTrackIndex],
  this.state.activeTrackIndex,
  event
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good, done.

packages/core/src/PlayerContextProvider.js Show resolved Hide resolved
Copy link
Owner

@benwiley4000 benwiley4000 left a comment

Choose a reason for hiding this comment

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

Perfect thanks!

@benwiley4000 benwiley4000 merged commit 6bf372b into benwiley4000:next Feb 10, 2019
@benwiley4000
Copy link
Owner

Released in v2.0.0-alpha.23.

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.

2 participants