Skip to content

Commit

Permalink
Add Youku player
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Jul 17, 2022
1 parent 9775bb7 commit 81aec4f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ class App extends Component {
{this.renderLoadButton('https://cdnapisec.kaltura.com/p/2507381/sp/250738100/embedIframeJs/uiconf_id/44372392/partner_id/2507381?iframeembed=true&playerId=kaltura_player_1605622336&entry_id=1_i1jmzcn3', 'Test B')}
</td>
</tr>
<tr>
<th>Youku</th>
<td>
{this.renderLoadButton('https://v.youku.com/v_show/id_XNTg4NjExNzY3Ng==.html', 'Test A')}
{this.renderLoadButton('https://v.youku.com/v_show/id_XNDQ4MDEzMzE3Ng==.html', 'Test B')}
</td>
</tr>
<tr>
<th>Files</th>
<td>
Expand Down
2 changes: 2 additions & 0 deletions src/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const MATCH_URL_DAILYMOTION = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:
export const MATCH_URL_MIXCLOUD = /mixcloud\.com\/([^/]+\/[^/]+)/
export const MATCH_URL_VIDYARD = /vidyard.com\/(?:watch\/)?([a-zA-Z0-9-_]+)/
export const MATCH_URL_KALTURA = /^https?:\/\/[a-zA-Z]+\.kaltura.(com|org)\/p\/([0-9]+)\/sp\/([0-9]+)00\/embedIframeJs\/uiconf_id\/([0-9]+)\/partner_id\/([0-9]+)(.*)entry_id.([a-zA-Z0-9-_].*)$/
export const MATCH_URL_YOUKU = /youku\.com\/v_show\/id_([a-zA-Z0-9]+)==\.html/
export const AUDIO_EXTENSIONS = /\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i
export const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i
export const HLS_EXTENSIONS = /\.(m3u8)($|\?)/i
Expand Down Expand Up @@ -60,5 +61,6 @@ export const canPlay = {
mixcloud: url => MATCH_URL_MIXCLOUD.test(url),
vidyard: url => MATCH_URL_VIDYARD.test(url),
kaltura: url => MATCH_URL_KALTURA.test(url),
youku: url => MATCH_URL_YOUKU.test(url),
file: canPlayFile
}
88 changes: 88 additions & 0 deletions src/players/Youku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React, { Component } from 'react'

import { callPlayer, getSDK, randomString } from '../utils'
import { canPlay, MATCH_URL_YOUKU } from '../patterns'

const SDK_URL = 'https://player.youku.com/jsapi'
const SDK_GLOBAL = 'YKU'
const PLAYER_ID_PREFIX = 'youku-player-'

export default class Youku extends Component {
static displayName = 'Youku'
static canPlay = canPlay.youku
callPlayer = callPlayer
playerID = this.props.config.playerId || `${PLAYER_ID_PREFIX}${randomString()}`

componentDidMount () {
this.props.onMount && this.props.onMount(this)
}

load (url, isReady) {
const { playing, config: { clientId, options }, onError } = this.props
const id = url.match(MATCH_URL_YOUKU)[1]
getSDK(SDK_URL, SDK_GLOBAL).then(YKU => {
this.player = new YKU.Player(this.playerId, {
client_id: clientId,
vid: id,
newPlayer: true,
autoplay: playing,
events: {
onPlayerReady: () => this.props.onReady(),
onPlayStart: () => this.props.onPlay(),
onPlayEnd: () => this.props.onEnded()
},
...options
})
}, onError)
}

play () {
this.callPlayer('playVideo')
}

pause () {
this.callPlayer('pauseVideo')
}

stop () {
// Nothing to do
}

seekTo (amount) {
this.callPlayer('seekTo', amount)
}

setVolume () {
// No volume support
}

mute = () => {
// No volume support
}

unmute = () => {
// No volume support
}

getDuration () {
return null
}

getCurrentTime () {
return this.callPlayer('currentTime')
}

getSecondsLoaded () {
return null
}

render () {
const style = {
width: '100%',
height: '100%'
}
return (
<div id={this.playerId} style={style} />
)
}
}
6 changes: 6 additions & 0 deletions src/players/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export default [
canPlay: canPlay.kaltura,
lazyPlayer: lazy(() => import(/* webpackChunkName: 'reactPlayerKaltura' */'./Kaltura'))
},
{
key: 'youku',
name: 'Youku',
canPlay: canPlay.youku,
lazyPlayer: lazy(() => import(/* webpackChunkName: 'reactPlayerYouku' */'./Youku'))
},
{
key: 'file',
name: 'FilePlayer',
Expand Down

0 comments on commit 81aec4f

Please sign in to comment.