fix seekbar initial states

This commit is contained in:
SrGooglo 2023-08-03 07:20:57 +00:00
parent 0511a508bc
commit e21a02a5da

View File

@ -8,7 +8,7 @@ import "./index.less"
export default class SeekBar extends React.Component { export default class SeekBar extends React.Component {
state = { state = {
playing: false, playing: app.cores.player.state["playback_status"] === "playing",
timeText: "00:00", timeText: "00:00",
durationText: "00:00", durationText: "00:00",
sliderTime: 0, sliderTime: 0,
@ -31,7 +31,7 @@ export default class SeekBar extends React.Component {
calculateDuration = (preCalculatedDuration) => { calculateDuration = (preCalculatedDuration) => {
// get current audio duration // get current audio duration
const audioDuration = preCalculatedDuration || app.cores.player.duration() const audioDuration = preCalculatedDuration ?? app.cores.player.duration()
if (isNaN(audioDuration)) { if (isNaN(audioDuration)) {
return return
@ -102,6 +102,10 @@ export default class SeekBar extends React.Component {
}, },
// handle when player changes track // handle when player changes track
"player.state.update:track_manifest": (manifest) => { "player.state.update:track_manifest": (manifest) => {
if (!manifest) {
return false
}
this.updateAll() this.updateAll()
this.setState({ this.setState({
@ -131,6 +135,7 @@ export default class SeekBar extends React.Component {
componentDidMount = () => { componentDidMount = () => {
this.calculateDuration() this.calculateDuration()
this.updateAll()
this.tick() this.tick()
for (const [event, callback] of Object.entries(this.events)) { for (const [event, callback] of Object.entries(this.events)) {