Skip to content

Commit

Permalink
Fix file player load sequence on iOS
Browse files Browse the repository at this point in the history
Calling `load()` manually fires onReady before `onPlay`, instead of after
Fixes cookpete/react-player#340
  • Loading branch information
happydev829 committed Mar 22, 2018
1 parent 2af1110 commit bd08c19
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/players/FilePlayer.js
Expand Up @@ -3,6 +3,7 @@ import React, { Component } from 'react'
import { getSDK } from '../utils'
import createSinglePlayer from '../singlePlayer'

const IOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
const AUDIO_EXTENSIONS = /\.(m4a|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i
const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)($|\?)/i
const HLS_EXTENSIONS = /\.(m3u8)($|\?)/i
Expand Down Expand Up @@ -38,6 +39,9 @@ export class FilePlayer extends Component {

componentDidMount () {
this.addListeners()
if (IOS) {
this.player.load()
}
}
componentWillReceiveProps (nextProps) {
if (this.shouldUseAudio(this.props) !== this.shouldUseAudio(nextProps)) {
Expand Down Expand Up @@ -81,11 +85,7 @@ export class FilePlayer extends Component {
return AUDIO_EXTENSIONS.test(props.url) || props.config.file.forceAudio
}
shouldUseHLS (url) {
const iOS =
typeof navigator !== 'undefined' &&
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
!window.MSStream
return (HLS_EXTENSIONS.test(url) && !iOS) || this.props.config.file.forceHLS
return (HLS_EXTENSIONS.test(url) && !IOS) || this.props.config.file.forceHLS
}
shouldUseDASH (url) {
return DASH_EXTENSIONS.test(url) || this.props.config.file.forceDASH
Expand Down

0 comments on commit bd08c19

Please sign in to comment.