Skip to content

Commit a743396

Browse files
committed
Add forceVideo option for FilePlayer
1 parent 7c16ed4 commit a743396

5 files changed

Lines changed: 38 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Key | Options
134134
`mixcloud` | `options`: Override the [default player options](https://www.mixcloud.com/developers/widget/#methods)
135135
`dailymotion` | `params`: Override the [default player vars](https://developer.dailymotion.com/player#player-parameters)<br />`preload`: Used for [preloading](#preloading)
136136
`twitch` | `options`: Override the [default player options](https://dev.twitch.tv/docs/embed)
137-
`file` | `attributes`: Apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)<br />`forceAudio`: Always render an `<audio>` element<br />`forceHLS`: Use [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 />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/doc/API.md#fine-tuning)
137+
`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 />`forceDASH`: Always use [dash.js](https://github.com/Dash-Industry-Forum/dash.js) for DASH streams<br />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/doc/API.md#fine-tuning)
138138

139139
##### Preloading
140140

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface MixcloudConfig {
4646
export interface FileConfig {
4747
attributes?: Object;
4848
tracks?: TrackProps[];
49+
forceVideo?: boolean;
4950
forceAudio?: boolean;
5051
forceHLS?: boolean;
5152
forceDASH?: boolean;

src/players/FilePlayer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ export class FilePlayer extends Component {
8282
this.props.onSeek(e.target.currentTime)
8383
}
8484
shouldUseAudio (props) {
85-
if (this.props.config.file.attributes.poster) {
85+
if (props.config.file.forceVideo) {
86+
return false
87+
}
88+
if (props.config.file.attributes.poster) {
8689
return false // Use <video> so that poster is shown
8790
}
8891
return AUDIO_EXTENSIONS.test(props.url) || props.config.file.forceAudio

src/props.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const propTypes = {
3838
file: shape({
3939
attributes: object,
4040
tracks: array,
41+
forceVideo: bool,
4142
forceAudio: bool,
4243
forceHLS: bool,
4344
forceDASH: bool,
@@ -124,6 +125,7 @@ export const defaultProps = {
124125
file: {
125126
attributes: {},
126127
tracks: [],
128+
forceVideo: false,
127129
forceAudio: false,
128130
forceHLS: false,
129131
forceDASH: false,

test/specs/ReactPlayer.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,36 @@ describe('ReactPlayer', () => {
370370
})
371371
})
372372

373+
describe.only('FilePlayer forceVideo', () => {
374+
beforeEach(done => {
375+
renderPlayer({
376+
url: 'http://example.com/file.mp3',
377+
config: { file: { forceVideo: true } }
378+
}, () => done())
379+
})
380+
381+
it('forces video element', () => {
382+
const video = player.getInternalPlayer()
383+
expect(video).to.be.a('HTMLVideoElement')
384+
expect(video.src).to.equal('http://example.com/file.mp3')
385+
})
386+
})
387+
388+
describe.only('FilePlayer forceAudio', () => {
389+
beforeEach(done => {
390+
renderPlayer({
391+
url: 'http://example.com/random/path',
392+
config: { file: { forceAudio: true } }
393+
}, () => done())
394+
})
395+
396+
it('forces audio element', () => {
397+
const video = player.getInternalPlayer()
398+
expect(video).to.be.a('HTMLAudioElement')
399+
expect(video.src).to.equal('http://example.com/random/path')
400+
})
401+
})
402+
373403
// onPause being called was a bug that has been fixed
374404
// so skip this test for now
375405
it.skip('Twitch switches from video to channel', done => {

0 commit comments

Comments
 (0)