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

feat: Add Airplay support when overriding native HLS in Safari/iOS #1543

Merged
merged 3 commits into from
Oct 9, 2024

Conversation

alex-barstow
Copy link
Contributor

@alex-barstow alex-barstow commented Oct 8, 2024

Description

Note: This depends on videojs/video.js#8886. Before we merge this, we will need a new Video.js release and then have to bump the peer dependency version in this package.

This PR adds Airplay support when overriding native HLS in Safari and/or iOS by using two source elements, one for the MediaSource URL object and one for the Airplay-compatible manifest URL.

From the Webkit guide on Airplay and MSE:

When Safari detects that an alternative source is available in addition to the MediaSource URL object, it will display the familiar AirPlay icon to the video player control. Should the user select AirPlay, it will switch over from MSE to the AirPlay-compatible URL.

Specific Changes proposed

If we are playing HLS with MSE in Safari or iOS, set the source by adding two <source> elements-- one for the Media Source blob and one for the HLS manifest that will be used for Airplay. Preserve the existing behavior in all other cases.

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
  • Reviewed by Two Core Contributors

// If we are playing HLS with MSE in Safari, add source elements for both the blob and manifest URLs.
// The latter will enable Airplay playback on receiver devices.
if ((videojs.browser.IS_ANY_SAFARI || videojs.browser.IS_IOS) && this.options_.overrideNative && this.options_.sourceType === 'hls') {
this.tech_.addSourceElement(this.mediaSourceUrl_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that addSourceElement will not exist on some techs? Do we want to check for it's existence first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MSE is an extension of HTML5 so we should be able to safely assume that all tech references are for the HTML5 tech.

Copy link
Member

Choose a reason for hiding this comment

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

Though unlikely, doing a check here adds safety in case someone is using a later version of vhs with the current version of videojs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a check

Copy link
Contributor

Choose a reason for hiding this comment

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

Though unlikely, doing a check here adds safety in case someone is using a later version of vhs with the current version of videojs.

I guess if someone tries to use it this way, npm should warn that peer dependency is incompatible

src/videojs-http-streaming.js Show resolved Hide resolved
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.40%. Comparing base (f6a4f79) to head (482c2c4).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1543      +/-   ##
==========================================
+ Coverage   86.36%   86.40%   +0.04%     
==========================================
  Files          43       43              
  Lines       11148    11155       +7     
  Branches     2545     2550       +5     
==========================================
+ Hits         9628     9639      +11     
+ Misses       1520     1516       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@wseymour15 wseymour15 left a comment

Choose a reason for hiding this comment

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

+1 once the changes from video.js are pulled in

@alex-barstow alex-barstow merged commit bfc17b4 into main Oct 9, 2024
15 checks passed
@alex-barstow alex-barstow deleted the feat/airplay-support branch October 9, 2024 16:59
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.

4 participants