diff --git a/packages/webamp-docs/docs/06_API/03_instance-methods.md b/packages/webamp-docs/docs/06_API/03_instance-methods.md index 0a046155..2ec6ce2e 100644 --- a/packages/webamp-docs/docs/06_API/03_instance-methods.md +++ b/packages/webamp-docs/docs/06_API/03_instance-methods.md @@ -215,8 +215,6 @@ Returns an "unsubscribe" function. **Note:** If the user drags in a track, the URL may be an [ObjectURL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL) -**Note:** This is different from the `onCurrentTrackDidChange` callback which is called every time a track changes. This callback is only called when a new track starts loading. - ```ts const unsubscribe = webamp.onTrackDidChange((track => { console.log("New track playing:", track.url); @@ -226,31 +224,6 @@ const unsubscribe = webamp.onTrackDidChange((track => { unsubscribe(); ``` -### `onCurrentTrackDidChange(cb: (currentTrack: PlaylistTrack | null, trackIndex: number) => void): () => void` - -A callback which will be called whenever a the current track changes. - -The callback is passed the current track and the zero-based index of the current track's position within the playlist. - -Returns an "unsubscribe" function. - -**Note:** This is different from the `onTrackDidChange` callback which is only called when a new track first starts loading. - -**Since** 2.1.0 - -```ts -const unsubscribe = webamp.onCurrentTrackDidChange( - (currentTrack, trackIndex) => { - if (currentTrack) { - console.log(`Now playing track ${trackIndex + 1}: ${currentTrack.title}`); - } - } -); - -// If at some point in the future you want to stop listening to these events: -unsubscribe(); -``` - ### `onWillClose(cb: (cancel: () => void) => void): () => void` A callback which will be called when Webamp is _about to_ close. Returns an "unsubscribe" function. The callback will be passed a `cancel` function which you can use to conditionally prevent Webamp from being closed. diff --git a/packages/webamp/CHANGELOG.md b/packages/webamp/CHANGELOG.md index c436db0f..caac6758 100644 --- a/packages/webamp/CHANGELOG.md +++ b/packages/webamp/CHANGELOG.md @@ -9,7 +9,6 @@ - Improve skin parsing performance and avoid Chrome console warning by adding `willReadFrequently` to canvas contexts. - Define an explicit `IMedia` interface for custom media implementations, which allows for better type checking and documentation. - Added new `Webamp` instance methods: - - `webamp.onCurrentTrackDidChange` - `webamp.isShuffleEnabled` - `webamp.isRepeatEnabled` - `webamp.setCurrentTrack` diff --git a/packages/webamp/js/webampLazy.tsx b/packages/webamp/js/webampLazy.tsx index 42935868..0d85dfa5 100644 --- a/packages/webamp/js/webampLazy.tsx +++ b/packages/webamp/js/webampLazy.tsx @@ -354,35 +354,6 @@ class Webamp { this.store.dispatch(Actions.open()); } - /** - * A callback which will be called whenever a the current track changes. - * - * The callback is passed the current track and the zero-based index of the - * current track's position within the playlist. - * - * Note: This is different from the `onTrackDidChange` callback which is only - * called when a new track first starts loading. - * - * @returns An "unsubscribe" function. Useful if at some point in the future - * you want to stop listening to these events. - */ - onCurrentTrackDidChange( - cb: (currentTrack: PlaylistTrack | null, trackIndex: number) => void - ): () => void { - let previousTrackId: number | null = null; - return this.store.subscribe(() => { - const state = this.store.getState(); - const currentTrack = Selectors.getCurrentTrack(state); - const currentTrackId = currentTrack?.id || null; - if (currentTrackId === previousTrackId) { - return; - } - previousTrackId = currentTrackId; - const trackIndex = Selectors.getCurrentTrackIndex(state); - cb(currentTrack, trackIndex); - }); - } - /** * A callback which will be called when a new track starts loading. * @@ -393,10 +364,6 @@ class Webamp { * * Note: If the user drags in a track, the URL may be an ObjectURL. * - * Note: This is different from the `onCurrentTrackDidChange` callback which - * is called every time a track changes. This callback is only called when a - * new track starts loading. - * * @returns An "unsubscribe" function. Useful if at some point in the future * you want to stop listening to these events. */