From 4da4e2275ed8d2e41b5a5fa0c559275cc9b1f509 Mon Sep 17 00:00:00 2001 From: Sam Bauch Date: Wed, 2 Nov 2016 13:07:07 -0400 Subject: [PATCH 1/3] Adds callback function prop for onReady when a track or playlist URL needs to be resolved --- src/addons/SoundPlayerContainer.js | 3 ++- src/addons/withSoundCloudAudio.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/addons/SoundPlayerContainer.js b/src/addons/SoundPlayerContainer.js index 2225def..81d0c52 100644 --- a/src/addons/SoundPlayerContainer.js +++ b/src/addons/SoundPlayerContainer.js @@ -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); diff --git a/src/addons/withSoundCloudAudio.js b/src/addons/withSoundCloudAudio.js index a91049d..a4c20b1 100644 --- a/src/addons/withSoundCloudAudio.js +++ b/src/addons/withSoundCloudAudio.js @@ -31,6 +31,7 @@ export default function withSoundCloudAudio (WrappedComponent) { } this.state = { + ready: !!props.streamUrl, duration: 0, currentTime: 0, seeking: false, @@ -53,7 +54,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); @@ -64,7 +65,7 @@ export default function withSoundCloudAudio (WrappedComponent) { } this.setState({ [data.tracks ? 'playlist' : 'track']: data - }); + }, () => onReady && onReady()); }); } } From 82d6d6b42499394a6ef14c7ccba8b88e66519c51 Mon Sep 17 00:00:00 2001 From: Sam Bauch Date: Wed, 2 Nov 2016 13:54:48 -0400 Subject: [PATCH 2/3] remove ready from state --- src/addons/withSoundCloudAudio.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/addons/withSoundCloudAudio.js b/src/addons/withSoundCloudAudio.js index a4c20b1..5312a0e 100644 --- a/src/addons/withSoundCloudAudio.js +++ b/src/addons/withSoundCloudAudio.js @@ -31,7 +31,6 @@ export default function withSoundCloudAudio (WrappedComponent) { } this.state = { - ready: !!props.streamUrl, duration: 0, currentTime: 0, seeking: false, From 6fe6f60e13b1597ab0971c4850f188c33d9ad524 Mon Sep 17 00:00:00 2001 From: Sam Bauch Date: Thu, 3 Nov 2016 10:05:27 -0400 Subject: [PATCH 3/3] adds documentation for onReady --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 72a8ead..77b2e7e 100644 --- a/README.md +++ b/README.md @@ -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() { +
+ + {/* your custom player components */} + +
+ } +} + +React.render(, 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: