The ended event of the MediaStreamTrack interface is fired when playback or streaming has stopped because the end of the media was reached or because no further data is available.
| Bubbles | No |
| Cancelable | No |
| Interface | Event
|
| Event handler property | MediaStreamTrack.onended
|
Usage notes
ended events fire when the media stream track's source permanently stops sending data on the stream. There are various ways this can happen, including:
- There is no more data left to send.
- The user revoked the permissions needed for the data to be sent.
- The hardware generating the source data has been removed or ejected.
- A remote peer has permanently stopped sending data; pausing media does not generate an
endedevent.
Examples
This example sets up an event handler for the ended event, which changes an on-screen icon to indicate that the track is no longer active.
track.addEventListener('ended', () => {
let statusElem = document.getElementById("status-icon");
statusElem.src = "/images/stopped-icon.png";
})
You can also set up the event handler using the MediaStreamTrack.onended property:
track.onended = function() {
let statusElem = document.getElementById("status-icon");
statusElem.src = "/images/stopped-icon.png";
}
Specifications
| Specification | Status | Comment |
|---|---|---|
| Media Capture and StreamsThe definition of 'ended' in that specification. | Candidate Recommendation | Initial specification. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ended event
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support 50 |
IE
No support No |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support 50 |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
See Also
HTMLMediaElement: playing eventHTMLMediaElement: waiting eventHTMLMediaElement: seeking event<audio><video>HTMLMediaElement: ended eventAudioScheduledSourceNode: ended event
MediaStreamTrack: ended event by Mozilla Contributors is licensed under CC-BY-SA 2.5.