refactor: Update loadedTime getter in Artplayer

The code changes update the loadedTime getter in Artplayer to handle different scenarios. The getter now checks for the presence of the loadedTime property in the video element and returns it if available, otherwise it falls back to the previous logic of retrieving the buffered end time. This update improves the reliability and compatibility of Artplayer's loadedTime functionality.
This commit is contained in:
Harvey Zack committed 2024-08-21 22:28:00 +08:00
1 parent 0a7d3ca5aa
commit 796f25cea2
4 files changed
+32 -19

No files matched your search

+16 -7
View File
@@ -164,14 +164,14 @@ function artplayerProxyWebAV() {
videoWidth: 0,
videoHeight: 0,
currentTime: 0,
loadedTime: 0,
volume: 1,
autoplay: false,
playbackRate: 1,
paused: true,
ended: false,
readyState: 0,
muted: false
muted: false,
buffered: 0
};
function reset() {
Object.assign(state, {
@@ -180,14 +180,14 @@ function artplayerProxyWebAV() {
videoWidth: 0,
videoHeight: 0,
currentTime: 0,
loadedTime: 0,
volume: 1,
autoplay: false,
playbackRate: 1,
paused: true,
ended: false,
readyState: 0,
muted: false
muted: false,
buffered: 0
});
}
function stop() {
@@ -218,9 +218,14 @@ function artplayerProxyWebAV() {
const { state: clipState, video, audio } = await clip.tick(Math.round(curTime));
curTime += 1000 / 30 * 1000 * state.playbackRate;
state.currentTime = curTime / 1e6;
// 更新缓冲状态
state.buffered = Math.max(state.buffered, state.currentTime);
art.emit("video:timeupdate", {
type: "timeupdate"
});
art.emit("video:progress", {
type: "progress"
});
if (clipState === "done") {
stop();
state.ended = true;
@@ -318,9 +323,6 @@ function artplayerProxyWebAV() {
{}
]
});
def(canvas, "loadedTime", {
get: ()=>state.loadedTime
});
def(canvas, "duration", {
get: ()=>state.duration
});
@@ -403,6 +405,13 @@ function artplayerProxyWebAV() {
});
}
});
def(canvas, "buffered", {
get: ()=>({
start: ()=>0,
end: ()=>state.buffered,
length: 1
})
});
// Define methods
def(canvas, "play", {
value: async ()=>{