YouTip LogoYouTip

Av Event Canplay

## HTML Audio/Video DOM: `canplay` Event The `canplay` event is fired when the user agent (browser) can resume playback of the media data, but estimates that there is not enough data loaded to play the media up to its end without having to stop for further buffering. In simpler terms, it indicates that the browser has loaded enough of the audio or video to start playing, even if it might still need to pause and buffer later. --- ## Media Loading Event Sequence When an audio or video file is loading, the browser triggers a specific sequence of events. The `canplay` event occurs late in this lifecycle: 1. `loadstart` – The browser begins looking for the media data. 2. `durationchange` – The duration of the media changes (becomes known). 3. `loadedmetadata` – Metadata (like dimensions, duration, and tracks) has been loaded. 4. `loadeddata` – The browser has loaded the current playback frame. 5. `progress` – The browser is downloading the media data. 6. **`canplay`** – The browser can start playing the media. 7. `canplaythrough` – The browser estimates it can play the media all the way through without pausing to buffer. --- ## Syntax You can listen for the `canplay` event in three different ways: ### 1. In HTML ```html ``` ### 2. In JavaScript (using the event handler property) ```javascript const mediaElement = document.getElementById("myMedia"); mediaElement.oncanplay = function() { console.log("The media is ready to start playing."); }; ``` ### 3. In JavaScript (using `addEventListener`) ```javascript const mediaElement = document.getElementById("myMedia"); mediaElement.addEventListener("canplay", function() { console.log("The media is ready to start playing."); }); ``` --- ## Technical Details | Feature | Support / Details | | :--- | :--- | | **Supported HTML Tags** | `
← Att Ios Ui SlidersAv Prop Volume β†’