Skip to content

Commit 4b3ebe5

Browse files
author
Maciej Makowski
committed
docs: added overridden onEnded callback to AudioBufferQueueSourceNode docs
1 parent e36f796 commit 4b3ebe5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

packages/audiodocs/docs/sources/audio-buffer-queue-source-node.mdx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sidebar_position: 5
33
---
44

5-
import { Optional, Experimental } from '@site/src/components/Badges';
5+
import { Optional, Experimental, Overridden } from '@site/src/components/Badges';
66

77
# AudioBufferQueueSourceNode
88

@@ -44,12 +44,29 @@ function App() {
4444

4545
### `enqueueBuffer`
4646

47-
The above method lets you add another buffer to queue.
47+
The above method lets you add another buffer to queue. Returns `bufferId` that can be used to identify the buffer in `onEnded` event.
4848

4949
| Parameters | Type | Description |
5050
| :---: | :---: | :---- |
5151
| `buffer` | [`AudioBuffer`](/sources/audio-buffer) | Buffer with next data. |
52-
| `isLastBuffer` | `boolean` | Boolean indicating if it is a last buffer. Default value is `false`. Queue will stop after buffer marked as `last` will end. |
5352

54-
#### Returns `undefined`.
53+
#### Returns `string`.
5554

55+
## Events
56+
57+
### `onEnded` <Overridden />
58+
59+
Allows to set (or remove) callback that will be fired when queue source node has stopped playing with payload `event.bufferId = undefined`
60+
or when a specific buffer has ended with payload `event.bufferId = <bufferId>`.
61+
62+
You can remove callback by passing `null`.
63+
64+
```ts
65+
audioBufferSourceNode.onEnded = (event) => { //setting callback
66+
if (event.bufferId === undefined) {
67+
console.log('queue source node has been stopped');
68+
} else {
69+
console.log(`buffer with id {event.bufferId} ended`);
70+
}
71+
};
72+
```

packages/audiodocs/docs/sources/audio-scheduled-source-node.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ If you invoke this method multiple times on the same node before the designated
5353

5454
## Events
5555

56+
### `onEnded`
57+
5658
Allows to set (or remove) callback that will be fired when source node has stopped playing,
5759
either because it's reached a predetermined stop time, the full duration of the audio has been performed, or because the entire buffer has been played.
5860
You can remove callback by passing `null`.

0 commit comments

Comments
 (0)