Remove onCurrentTrackDidChange

This commit is contained in:
Jordan Eldredge 2025-06-19 13:52:31 -07:00
parent 62c5af1dfb
commit 8b218e8e67
3 changed files with 0 additions and 61 deletions

View file

@ -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.

View file

@ -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`

View file

@ -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.
*/