-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { Component } from 'react' | ||
|
||
import { callPlayer, getSDK, queryString } from '../utils' | ||
import createSinglePlayer from '../singlePlayer' | ||
|
||
const SDK_URL = '//widget.mixcloud.com/media/js/widgetApi.js' | ||
const SDK_GLOBAL = 'Mixcloud' | ||
const MATCH_URL = /mixcloud\.com\/([^/]+\/[^/]+)/ | ||
|
||
export class Mixcloud extends Component { | ||
static displayName = 'Mixcloud' | ||
static canPlay = url => MATCH_URL.test(url) | ||
|
||
callPlayer = callPlayer | ||
duration = null | ||
currentTime = null | ||
secondsLoaded = null | ||
load (url) { | ||
getSDK(SDK_URL, SDK_GLOBAL).then(Mixcloud => { | ||
this.player = Mixcloud.PlayerWidget(this.iframe) | ||
this.player.ready.then(() => { | ||
this.player.events.play.on(this.props.onPlay) | ||
this.player.events.pause.on(this.props.onPause) | ||
this.player.events.ended.on(this.props.onEnded) | ||
this.player.events.error.on(this.props.error) | ||
this.player.events.progress.on((seconds, duration) => { | ||
this.currentTime = seconds | ||
this.duration = duration | ||
}) | ||
this.props.onReady() | ||
}) | ||
}, this.props.onError) | ||
} | ||
play () { | ||
this.callPlayer('play') | ||
} | ||
pause () { | ||
this.callPlayer('pause') | ||
} | ||
stop () { | ||
// Nothing to do | ||
} | ||
seekTo (seconds) { | ||
this.callPlayer('seek', seconds) | ||
} | ||
setVolume (fraction) { | ||
// No volume support | ||
} | ||
getDuration () { | ||
return this.duration | ||
} | ||
getCurrentTime () { | ||
return this.currentTime | ||
} | ||
getSecondsLoaded () { | ||
return null | ||
} | ||
ref = iframe => { | ||
this.iframe = iframe | ||
} | ||
render () { | ||
const { url, config } = this.props | ||
const id = url.match(MATCH_URL)[1] | ||
const style = { | ||
width: '100%', | ||
height: '100%' | ||
} | ||
const query = queryString({ | ||
...config.mixcloud.options, | ||
feed: `/${id}/` | ||
}) | ||
// We have to give the iframe a key here to prevent a | ||
// weird dialog appearing when loading a new track | ||
return ( | ||
<iframe | ||
key={id} | ||
ref={this.ref} | ||
style={style} | ||
src={`https://www.mixcloud.com/widget/iframe/?${query}`} | ||
frameBorder='0' | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default createSinglePlayer(Mixcloud) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters