Skip to content

Commit

Permalink
fix: 修复长时间暂停歌曲无法播放问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Jan 24, 2022
1 parent 0b5c5af commit fbde379
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/background/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
shuffleArr,
race,
randChinaIp,
sleep,
} from "../utils";

// 播放器
Expand All @@ -36,8 +35,8 @@ let audioState = { ...EMPTY_AUDIO_STATE, volumeMute: null };
let persistData = null;
// 上次刷新时间
let refreshAt = 0;
// 上次暂停时间
let pausedAt = null;
// 加载歌曲时间
let songAt = 0;

const store = proxy({ ...COMMON_PROPS, playing: false, dir: 1, chinaIp: null });

Expand Down Expand Up @@ -75,19 +74,17 @@ export async function togglePlaying() {
return { audioPlaying: false };
}
if (audioPlaying) {
pausedAt = Date.now();
audio.pause();
playing = false;
} else {
if (pausedAt && Date.now() - pausedAt > 10 * 60 * 1000) {
if (Date.now() - songAt > 10 * 60 * 1000) {
const currentTime = audioState.currentTime;
await loadAndPlaySong(
store.selectedPlaylist,
store.selectedSong.id,
false
);
updateAudioTime(currentTime);
pausedAt = null;
}
audio.play();
playing = true;
Expand Down Expand Up @@ -721,6 +718,7 @@ function setupAudio() {
}
async function updateAudioSrc(src, playing) {
audio.src = src;
songAt = Date.now();
if (playing) {
audio.autoplay = true;
} else {
Expand Down

0 comments on commit fbde379

Please sign in to comment.