Commit 6ce3776
authored
[video_player_web] Fix blank first frame on iOS. (flutter#9025)
Fixes [First Frame of Video Once VideoPlayer Controller doesn't show in iOS Safari/Chrome](flutter#139107)
This PR fixes the blank first frame issue by adding a `_videoElement.load()` call at the end of the `initialize` function. This call forces the browser to load media in preparation for playback (https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/load).
Additionally, this PR removes `loadedmetadata` event listener, as the `canplay` event is now reliably emitted across all platforms. Keeping `loadedmetadata` listener could result in marking the video controller as initialized before the first frame is actually rendered. This causes the loader to disappear too early, leaving a blank space where the video should be until the browser displays the first frame. Relying on `canplay` ensures the first frame is ready before we proceed.
> [!NOTE]
> It turns out that this issue is iOS-specific and was reported not only in Flutter, but in some other packages and tools:
> 1) [video-react/First frame not shown as the poster on iOS Safari](video-react/video-react#328)
> 2) [WordPress/gutenberg/Video Block: First frame not shown as the poster on iOS Safari — Fix: Use Fragment URL](WordPress/gutenberg#51995)
> [!TIP]
> As a temporary workaround until this PR is merged, users can append the `#t=0.001` fragment to the asset or URL `src` to force the browser to load the first frame (e.g., `assets/butterfly.mp4#t=0.001`, `https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4#t=0.001`).
The following repository was used for issue reproduction and testing: https://github.com/ksokolovskyi/video_player_blank_frame_bug
| Before | After |
| :---: | :---: |
| https://video-player-blank-frame-bug.web.app | https://video-player-blank-frame-fix.web.app |
| <video src="https://github.com/user-attachments/assets/4077fcc4-10cf-4dbd-8c59-2fd824b4e4c4" /> | <video src="https://github.com/user-attachments/assets/2951af36-1569-4a5c-90dd-1d52a5d1e7f2" /> |
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.1 parent 909f062 commit 6ce3776
File tree
4 files changed
+45
-7
lines changed- packages/video_player/video_player_web
- example/integration_test
- lib/src
4 files changed
+45
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
Lines changed: 36 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
| |||
130 | 144 | | |
131 | 145 | | |
132 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
133 | 152 | | |
134 | 153 | | |
135 | 154 | | |
| |||
222 | 241 | | |
223 | 242 | | |
224 | 243 | | |
225 | | - | |
226 | | - | |
| 244 | + | |
227 | 245 | | |
228 | 246 | | |
229 | 247 | | |
| |||
235 | 253 | | |
236 | 254 | | |
237 | 255 | | |
238 | | - | |
239 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
240 | 272 | | |
241 | 273 | | |
242 | 274 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
| |||
131 | 129 | | |
132 | 130 | | |
133 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments