frontend record more types of playback
This commit is contained in:
@@ -22,6 +22,24 @@ function AudioPlayer(props) {
|
|||||||
const [timerCount, setTimerCount] = useState(0);
|
const [timerCount, setTimerCount] = useState(0);
|
||||||
const [timerID, setTimerID] = useState(null);
|
const [timerID, setTimerID] = useState(null);
|
||||||
const [beginPlayTime, setBeginPlayTime] = useState(null);
|
const [beginPlayTime, setBeginPlayTime] = useState(null);
|
||||||
|
const [lastID, setLastID] = useState(null);
|
||||||
|
|
||||||
|
const recordPlaybackHistory = async (file_id, method, duration) => {
|
||||||
|
await fetch('/api/v1/record_playback', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
playback: {
|
||||||
|
file_id,
|
||||||
|
method,
|
||||||
|
duration,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// init mediaSession API
|
// init mediaSession API
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -42,6 +60,13 @@ function AudioPlayer(props) {
|
|||||||
setPlayingURL("");
|
setPlayingURL("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// crrently playing file, record interupt
|
||||||
|
if (playingURL) {
|
||||||
|
const endPlayTime = new Date()
|
||||||
|
const duration = parseInt((endPlayTime - beginPlayTime) / 1000)
|
||||||
|
recordPlaybackHistory(lastID, 2, duration)
|
||||||
|
}
|
||||||
|
setLastID(props.playingFile.id)
|
||||||
// have playingFile, record begin time
|
// have playingFile, record begin time
|
||||||
setBeginPlayTime(new Date())
|
setBeginPlayTime(new Date())
|
||||||
if (raw) {
|
if (raw) {
|
||||||
@@ -120,6 +145,10 @@ function AudioPlayer(props) {
|
|||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
props.setPlayingFile({});
|
props.setPlayingFile({});
|
||||||
|
const endPlayTime = new Date()
|
||||||
|
const duration = parseInt((endPlayTime - beginPlayTime) / 1000)
|
||||||
|
setBeginPlayTime(endPlayTime)
|
||||||
|
recordPlaybackHistory(props.playingFile.id, 3, duration)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{Tr("Stop")}
|
{Tr("Stop")}
|
||||||
@@ -204,19 +233,7 @@ function AudioPlayer(props) {
|
|||||||
const endPlayTime = new Date()
|
const endPlayTime = new Date()
|
||||||
const duration = parseInt((endPlayTime - beginPlayTime) / 1000)
|
const duration = parseInt((endPlayTime - beginPlayTime) / 1000)
|
||||||
setBeginPlayTime(endPlayTime)
|
setBeginPlayTime(endPlayTime)
|
||||||
await fetch('/api/v1/record_playback', {
|
recordPlaybackHistory(props.playingFile.id, 1, duration)
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
playback: {
|
|
||||||
file_id: props.playingFile.id,
|
|
||||||
method: 1,
|
|
||||||
duration: parseInt(duration),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
></audio>
|
></audio>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user