frontend support record playback history
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { useEffect, useState } from "react";
|
import {useEffect, useState} from "react";
|
||||||
import { useNavigate } from "react-router";
|
import {useNavigate} from "react-router";
|
||||||
import { CalcReadableFilesizeDetail } from "./Common";
|
import {CalcReadableFilesizeDetail} from "./Common";
|
||||||
import FfmpegConfig from "./FfmpegConfig";
|
import FfmpegConfig from "./FfmpegConfig";
|
||||||
import FileDialog from "./FileDialog";
|
import FileDialog from "./FileDialog";
|
||||||
import { Tr } from "../translate";
|
import {Tr} from "../translate";
|
||||||
|
|
||||||
function AudioPlayer(props) {
|
function AudioPlayer(props) {
|
||||||
// props.playingFile
|
// props.playingFile
|
||||||
@@ -21,6 +21,7 @@ function AudioPlayer(props) {
|
|||||||
const [isPreparing, setIsPreparing] = useState(false);
|
const [isPreparing, setIsPreparing] = useState(false);
|
||||||
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);
|
||||||
|
|
||||||
// init mediaSession API
|
// init mediaSession API
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -34,13 +35,15 @@ function AudioPlayer(props) {
|
|||||||
navigator.mediaSession.metadata = new window.MediaMetadata({
|
navigator.mediaSession.metadata = new window.MediaMetadata({
|
||||||
title: props.playingFile.filename,
|
title: props.playingFile.filename,
|
||||||
album: props.playingFile.foldername,
|
album: props.playingFile.foldername,
|
||||||
artwork: [{ src: "/favicon.png", type: "image/png" }],
|
artwork: [{src: "/favicon.png", type: "image/png"}],
|
||||||
});
|
});
|
||||||
// no playing file
|
// no playing file
|
||||||
if (props.playingFile.id === undefined) {
|
if (props.playingFile.id === undefined) {
|
||||||
setPlayingURL("");
|
setPlayingURL("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// have playingFile, record begin time
|
||||||
|
setBeginPlayTime(new Date())
|
||||||
if (raw) {
|
if (raw) {
|
||||||
console.log("Play raw file");
|
console.log("Play raw file");
|
||||||
setPlayingURL("/api/v1/get_file_direct?id=" + props.playingFile.id);
|
setPlayingURL("/api/v1/get_file_direct?id=" + props.playingFile.id);
|
||||||
@@ -50,7 +53,7 @@ function AudioPlayer(props) {
|
|||||||
setIsPreparing(true);
|
setIsPreparing(true);
|
||||||
fetch("/api/v1/prepare_file_stream_direct", {
|
fetch("/api/v1/prepare_file_stream_direct", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: {"Content-Type": "application/json"},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
id: props.playingFile.id,
|
id: props.playingFile.id,
|
||||||
config_name: selectedFfmpegConfig.name,
|
config_name: selectedFfmpegConfig.name,
|
||||||
@@ -191,16 +194,37 @@ function AudioPlayer(props) {
|
|||||||
id="dom-player"
|
id="dom-player"
|
||||||
controls
|
controls
|
||||||
autoPlay
|
autoPlay
|
||||||
loop={loop}
|
|
||||||
className="audio-player"
|
className="audio-player"
|
||||||
src={playingURL}
|
src={playingURL}
|
||||||
|
onEnded={async () => {
|
||||||
|
const player = document.getElementById('dom-player')
|
||||||
|
if (loop) {
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
const endPlayTime = new Date()
|
||||||
|
const duration = parseInt((endPlayTime - beginPlayTime) / 1000)
|
||||||
|
setBeginPlayTime(endPlayTime)
|
||||||
|
await fetch('/api/v1/record_playback', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
playback: {
|
||||||
|
file_id: props.playingFile.id,
|
||||||
|
method: 1,
|
||||||
|
duration: parseInt(duration),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}}
|
||||||
></audio>
|
></audio>
|
||||||
|
|
||||||
<FfmpegConfig
|
<FfmpegConfig
|
||||||
selectedFfmpegConfig={selectedFfmpegConfig}
|
selectedFfmpegConfig={selectedFfmpegConfig}
|
||||||
setSelectedFfmpegConfig={setSelectedFfmpegConfig}
|
setSelectedFfmpegConfig={setSelectedFfmpegConfig}
|
||||||
/>
|
/>
|
||||||
</footer>
|
</footer >
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user