improve for stream audio mode

This commit is contained in:
SrGooglo 2023-03-30 22:49:56 +00:00
parent 62a54a0d2d
commit 530c55ac91
2 changed files with 66 additions and 9 deletions

View File

@ -2,7 +2,6 @@ import React from "react"
import * as antd from "antd" import * as antd from "antd"
import Slider from "@mui/material/Slider" import Slider from "@mui/material/Slider"
import classnames from "classnames" import classnames from "classnames"
import Ticker from "react-ticker"
import { Icons, createIconRender } from "components/Icons" import { Icons, createIconRender } from "components/Icons"
@ -38,6 +37,7 @@ class SeekBar extends React.Component {
durationText: "00:00", durationText: "00:00",
sliderTime: 0, sliderTime: 0,
sliderLock: false, sliderLock: false,
streamMode: false,
} }
handleSeek = (value) => { handleSeek = (value) => {
@ -58,6 +58,19 @@ class SeekBar extends React.Component {
// get current audio duration // get current audio duration
const audioDuration = app.cores.player.duration() const audioDuration = app.cores.player.duration()
// if duration is infinity, set stream mode
if (audioDuration === Infinity) {
this.setState({
streamMode: true,
})
return
}
if (isNaN(audioDuration)) {
return
}
console.log(`Audio duration: ${audioDuration}`) console.log(`Audio duration: ${audioDuration}`)
// convert duration to minutes and seconds // convert duration to minutes and seconds
@ -150,6 +163,7 @@ class SeekBar extends React.Component {
this.setState({ this.setState({
timeText: "00:00", timeText: "00:00",
sliderTime: 0, sliderTime: 0,
streamMode: false,
}) })
this.calculateDuration() this.calculateDuration()
@ -168,12 +182,14 @@ class SeekBar extends React.Component {
} }
tick = () => { tick = () => {
if (this.props.playing) { if (this.props.playing || this.state.streamMode) {
this.interval = setInterval(() => { this.interval = setInterval(() => {
this.updateAll() this.updateAll()
}, 1000) }, 1000)
} else { } else {
clearInterval(this.interval) if (this.interval) {
clearInterval(this.interval)
}
} }
} }
@ -199,12 +215,26 @@ class SeekBar extends React.Component {
} }
render() { render() {
return <div className="status"> return <div
<div className="progress"> className={classnames(
"status",
{
["hidden"]: !this.props.initialLoad,
}
)}
>
<div
className={classnames(
"progress",
{
["hidden"]: this.state.streamMode,
}
)}
>
<Slider <Slider
size="small" size="small"
value={this.state.sliderTime} value={this.state.sliderTime}
disabled={this.props.stopped} disabled={this.props.stopped || this.state.streamMode}
min={0} min={0}
max={100} max={100}
step={0.1} step={0.1}
@ -232,7 +262,9 @@ class SeekBar extends React.Component {
<span>{this.state.timeText}</span> <span>{this.state.timeText}</span>
</div> </div>
<div> <div>
<span>{this.state.durationText}</span> {
this.state.streamMode ? <antd.Tag>Live</antd.Tag> : <span>{this.state.durationText}</span>
}
</div> </div>
</div> </div>
</div> </div>
@ -275,6 +307,7 @@ export default class AudioPlayer extends React.Component {
bpm: app.cores.player.getState("trackBPM") ?? 0, bpm: app.cores.player.getState("trackBPM") ?? 0,
showControls: false, showControls: false,
minimized: false, minimized: false,
initialLoad: false,
} }
events = { events = {
@ -283,6 +316,12 @@ export default class AudioPlayer extends React.Component {
}, },
"player.loading.update": (data) => { "player.loading.update": (data) => {
this.setState({ loading: data }) this.setState({ loading: data })
if (!data && !this.state.initialLoad) {
this.setState({
initialLoad: true
})
}
}, },
"player.status.update": (data) => { "player.status.update": (data) => {
this.setState({ playbackStatus: data }) this.setState({ playbackStatus: data })
@ -456,6 +495,7 @@ export default class AudioPlayer extends React.Component {
<SeekBar <SeekBar
stopped={playbackStatus === "stopped"} stopped={playbackStatus === "stopped"}
playing={playbackStatus === "playing"} playing={playbackStatus === "playing"}
initialLoad={this.state.initialLoad}
/> />
</div> </div>
</div> </div>

View File

@ -260,15 +260,31 @@
align-self: center; align-self: center;
width: 90%; width: 90%;
height: 100%;
height: fit-content;
margin: 20px 0 10px 0; margin: 20px 0 10px 0;
border-radius: 8px; border-radius: 8px;
transition: all 150ms ease-in-out;
&.hidden {
height: 0px;
opacity: 0;
pointer-events: none;
}
.progress { .progress {
width: 100%; width: 100%;
height: 100%;
transition: all 150ms ease-in-out;
&.hidden {
opacity: 0;
height: 0;
pointer-events: none;
}
} }
.timers { .timers {
@ -279,6 +295,7 @@
height: fit-content; height: fit-content;
justify-content: space-between; justify-content: space-between;
align-items: center;
} }
h1, h1,