|
| 1 | +--- |
| 2 | +title: "SourceBuffer: updateend event" |
| 3 | +short-title: updateend |
| 4 | +slug: Web/API/SourceBuffer/updateend_event |
| 5 | +page-type: web-api-event |
| 6 | +browser-compat: api.SourceBuffer.updateend_event |
| 7 | +--- |
| 8 | + |
| 9 | +{{APIRef("Media Source Extensions")}}{{AvailableInWorkers("window_and_dedicated")}} |
| 10 | + |
| 11 | +The **`updateend`** event of the {{domxref("SourceBuffer")}} interface signals the (not necessarily successful) completion of an {{domxref("SourceBuffer.appendBuffer", "appendBuffer()")}} or {{domxref("SourceBuffer.remove", "remove()")}} operation. The {{domxref("SourceBuffer.updating", "updating")}} attribute transitions from `true` to `false`. This event is fired after the {{domxref("SourceBuffer.update_event", "update")}}, {{domxref("SourceBuffer.error_event", "error")}}, or {{domxref("SourceBuffer.abort_event", "abort")}} events. |
| 12 | + |
| 13 | +## Syntax |
| 14 | + |
| 15 | +Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property. |
| 16 | + |
| 17 | +```js-nolint |
| 18 | +addEventListener("updateend", (event) => { }) |
| 19 | +
|
| 20 | +onupdateend = (event) => { } |
| 21 | +``` |
| 22 | + |
| 23 | +## Event type |
| 24 | + |
| 25 | +A generic {{domxref("Event")}}. |
| 26 | + |
| 27 | +## Examples |
| 28 | + |
| 29 | +### Handling the updateend event after appending data |
| 30 | + |
| 31 | +This example demonstrates how to handle the `updateend` event. Note that we handle each completion event separately, and only use `updateend` for finalizing the stream. |
| 32 | + |
| 33 | +```js |
| 34 | +const sourceBuffer = source.addSourceBuffer(mimeCodec); |
| 35 | +sourceBuffer.addEventListener("abort", () => { |
| 36 | + downloadStatus.textContent = "Canceled"; |
| 37 | +}); |
| 38 | +sourceBuffer.addEventListener("error", () => { |
| 39 | + downloadStatus.textContent = "Error occurred during decoding"; |
| 40 | +}); |
| 41 | +sourceBuffer.addEventListener("update", () => { |
| 42 | + downloadStatus.textContent = "Done"; |
| 43 | +}); |
| 44 | +sourceBuffer.addEventListener("updateend", () => { |
| 45 | + source.endOfStream(); |
| 46 | +}); |
| 47 | +downloadStatus.textContent = "Downloading..."; |
| 48 | +fetch(assetURL) |
| 49 | + .then((response) => response.arrayBuffer()) |
| 50 | + .then((data) => { |
| 51 | + downloadStatus.textContent = "Decoding..."; |
| 52 | + sourceBuffer.appendBuffer(data); |
| 53 | + }); |
| 54 | +``` |
| 55 | + |
| 56 | +## Specifications |
| 57 | + |
| 58 | +{{Specifications}} |
| 59 | + |
| 60 | +## Browser compatibility |
| 61 | + |
| 62 | +{{Compat}} |
| 63 | + |
| 64 | +## See also |
| 65 | + |
| 66 | +- {{domxref("SourceBuffer.appendBuffer()")}} |
| 67 | +- {{domxref("SourceBuffer.remove()")}} |
0 commit comments