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

onReady for resolveURL #59

Merged
merged 3 commits into from
Nov 3, 2016
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,44 @@ _(String)_ - this could be regular link from SoundCloud web app which points to
"https://soundcloud.com/stepan-i-meduza-official/sets/dolgo-obyasnyat-ep"
```

##### `onReady`

_(function)_ - if using `resolveUrl`, pass a function to be called when the track or playlist is resolved and ready to be played. Will not be called if you use `streamUrl`. The function is called without any arguments:

```javascript
import React from 'react';
import { SoundPlayerContainer } from 'react-soundplayer/addons';

const clientId = 'YOUR CLIENT ID';
const resolveUrl = 'https://soundcloud.com/thrilljockey/future-islands-balance';

class AppPlayer extends React.Component {
constructor(){
super();
this.trackReady = this.trackReady.bind(this);
}

trackReady(){
console.log('Track can be played!')
// Enable the play button, or start playing programmatically, etc
}

render() {
<div>
<SoundPlayerContainer
clientId={clientId}
resolveUrl={resolveUrl}
onReady={this.trackReady}
>
{/* your custom player components */}
</SoundPlayerContainer>
</div>
}
}

React.render(<AppPlayer />, document.body);
```

##### `streamUrl`

_(String)_ - pass here pure stream url as it's returned by [SoundCloud API](https://developers.soundcloud.com/docs/api/reference#tracks), it has higher priority than `resolveUrl`, example:
Expand Down
3 changes: 2 additions & 1 deletion src/addons/SoundPlayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ SoundPlayerContainer.propTypes = {
onStartTrack: PropTypes.func,
onStopTrack: PropTypes.func,
onPauseTrack: PropTypes.func,
onVolumeChange: PropTypes.func
onVolumeChange: PropTypes.func,
onReady: PropTypes.func
};

export default withSoundCloudAudio(SoundPlayerContainer);
4 changes: 2 additions & 2 deletions src/addons/withSoundCloudAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function withSoundCloudAudio (WrappedComponent) {

requestAudio() {
const { soundCloudAudio } = this;
const { resolveUrl, streamUrl } = this.props;
const { resolveUrl, streamUrl, onReady } = this.props;

if (streamUrl) {
soundCloudAudio.preload(streamUrl);
Expand All @@ -64,7 +64,7 @@ export default function withSoundCloudAudio (WrappedComponent) {
}
this.setState({
[data.tracks ? 'playlist' : 'track']: data
});
}, () => onReady && onReady());
});
}
}
Expand Down