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 forceDisableHls option for FilePlayer #1625

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Key | Options
`mixcloud` | `options`: Override the [default player options](https://www.mixcloud.com/developers/widget/#methods)
`dailymotion` | `params`: Override the [default player vars](https://developer.dailymotion.com/player#player-parameters)
`twitch` | `options`: Override the [default player options](https://dev.twitch.tv/docs/embed)<br />`playerId`: Override player ID for consistent server-side rendering (use with [`react-uid`](https://github.com/thearnica/react-uid))
`file` | `attributes`: Apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)<br />`forceVideo`: Always render a `<video>` element<br />`forceAudio`: Always render an `<audio>` element<br />`forceHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams<br />`forceSafariHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams, [even on Safari](https://github.com/cookpete/react-player/pull/1560)<br />`forceDASH`: Always use [dash.js](https://github.com/Dash-Industry-Forum/dash.js) for DASH streams<br />`forceFLV`: Always use [flv.js](https://github.com/Bilibili/flv.js)<br />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning)<br />`hlsVersion`: Override the [`hls.js`](https://github.com/video-dev/hls.js) version loaded from [`jsdelivr`](https://www.jsdelivr.com/package/npm/hls.js), default: `0.13.1`<br />`dashVersion`: Override the [`dash.js`](https://github.com/Dash-Industry-Forum/dash.js) version loaded from [`cdnjs`](https://cdnjs.com/libraries/dashjs), default: `2.9.2`<br />`flvVersion`: Override the [`flv.js`](https://github.com/Bilibili/flv.js) version loaded from [`jsdelivr`](https://www.jsdelivr.com/package/npm/flv.js), default: `1.5.0`
`file` | `attributes`: Apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)<br />`forceVideo`: Always render a `<video>` element<br />`forceAudio`: Always render an `<audio>` element<br />`forceHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams<br />`forceSafariHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams, [even on Safari](https://github.com/cookpete/react-player/pull/1560)<br />`forceDisableHLS`: Disable usage [hls.js](https://github.com/video-dev/hls.js) for HLS streams<br />`forceDASH`: Always use [dash.js](https://github.com/Dash-Industry-Forum/dash.js) for DASH streams<br />`forceFLV`: Always use [flv.js](https://github.com/Bilibili/flv.js)<br />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning)<br />`hlsVersion`: Override the [`hls.js`](https://github.com/video-dev/hls.js) version loaded from [`jsdelivr`](https://www.jsdelivr.com/package/npm/hls.js), default: `0.13.1`<br />`dashVersion`: Override the [`dash.js`](https://github.com/Dash-Industry-Forum/dash.js) version loaded from [`cdnjs`](https://cdnjs.com/libraries/dashjs), default: `2.9.2`<br />`flvVersion`: Override the [`flv.js`](https://github.com/Bilibili/flv.js) version loaded from [`jsdelivr`](https://www.jsdelivr.com/package/npm/flv.js), default: `1.5.0`

### Methods

Expand Down
9 changes: 3 additions & 6 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class FilePlayer extends Component {
this.props.onMount && this.props.onMount(this)
this.addListeners(this.player)
this.player.src = this.getSource(this.props.url) // Ensure src is set in strict mode
if (IS_IOS) {
if (IS_IOS || this.props.config.forceDisableHls) {
this.player.load()
}
}
Expand Down Expand Up @@ -138,13 +138,10 @@ export default class FilePlayer extends Component {
}

shouldUseHLS (url) {
if (this.props.config.forceHLS) {
if ((IS_SAFARI && this.props.config.forceSafariHLS) || this.props.config.forceHLS) {
return true
}
if (IS_SAFARI && this.props.config.forceSafariHLS) {
return true
}
if (IS_IOS) {
if (IS_IOS || this.props.config.forceDisableHls) {
return false
}
return HLS_EXTENSIONS.test(url) || MATCH_CLOUDFLARE_STREAM.test(url)
Expand Down
4 changes: 3 additions & 1 deletion src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const propTypes = {
forceAudio: bool,
forceHLS: bool,
forceSafariHLS: bool,
forceDisableHls: bool,
forceDASH: bool,
forceFLV: bool,
hlsOptions: object,
Expand Down Expand Up @@ -172,7 +173,8 @@ export const defaultProps = {
hlsOptions: {},
hlsVersion: '1.1.4',
dashVersion: '3.1.3',
flvVersion: '1.5.0'
flvVersion: '1.5.0',
forceDisableHls: false
},
wistia: {
options: {},
Expand Down
1 change: 1 addition & 0 deletions types/file.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface FileConfig {
forceAudio?: boolean
forceHLS?: boolean
forceSafariHLS?: boolean
forceDisableHls?: boolean
forceDASH?: boolean
forceFLV?: boolean
hlsOptions?: Record<string, any>
Expand Down