From 95be6b4bdabc8a5d6f9e99a826df940b5892089d Mon Sep 17 00:00:00 2001 From: wanxiankai Date: Tue, 3 Nov 2026 02:27:04 +0800 Subject: [PATCH] fix: initialize preloaded media duration and buffered state --- docs/useAudio.md | 4 ++ docs/useVideo.md | 6 +- src/factory/createHTMLMediaHook.ts | 2 + tests/createHTMLMediaHook.test.tsx | 102 +++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/createHTMLMediaHook.test.tsx diff --git a/docs/useAudio.md b/docs/useAudio.md index 8939060400..e17896c57c 100644 --- a/docs/useAudio.md +++ b/docs/useAudio.md @@ -71,6 +71,10 @@ render tree, for example: `playing`: The audio is being played and is affected by the network. If it starts to buffer audio, it will be false +`duration` and `buffered` are read from the rendered audio element on mount and when +`src` changes, including metadata loaded before React attaches its event handlers. +`duration` remains `0` until metadata is available. + `controls` is a list collection of methods that allow you to control the playback of the audio, it has the following interface: diff --git a/docs/useVideo.md b/docs/useVideo.md index 7d0dfb9257..561c41dcfd 100644 --- a/docs/useVideo.md +++ b/docs/useVideo.md @@ -67,6 +67,10 @@ render tree, for example: } ``` +`duration` and `buffered` are read from the rendered video element on mount and when +`src` changes, including metadata loaded before React attaches its event handlers. +`duration` remains `0` until metadata is available. + `controls` is a list collection of methods that allow you to control the playback of the video, it has the following interface: @@ -84,4 +88,4 @@ interface AudioControls { `ref` is a React reference to HTML `