diff --git a/package.json b/package.json
index bc18133..3be8cd8 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,6 @@
"react-cookie": "^4.1.1",
"react-dom": "^18.2.0",
"react-redux": "^8.0.7",
- "react-resize-detector": "^9.1.0",
"react-router-dom": "^6.11.2",
"react-scripts": "5.0.1",
"sha1": "^1.1.1",
diff --git a/src/MainPage.js b/src/MainPage.js
index 9a7d1f4..cfcec80 100644
--- a/src/MainPage.js
+++ b/src/MainPage.js
@@ -112,6 +112,8 @@ export default function () {
const accessToken = useSelector(state => state.user.accessToken);
const passportId = useSelector(state => state.user.passportId);
const currentTime = useSelector(state => state.recorder.currentTime);
+ const currentLyric = useSelector(state => state.recorder.currentLyric);
+ const [playerBarWidth, setPlayerBarWidth] = useState(0);
const [open, setOpen] = useState(true);
useEffect(() => {
yzs.get_record_list(accessToken, passportId).then(list => {
@@ -126,17 +128,39 @@ export default function () {
const onClick = () => {
setOpen(!open);
+ setPlayerBarWidth(document.documentElement.clientWidth - 240 - 48); // 防止中途底部出现scrollbar
}
+ const handleResize = () => {
+ console.log("innerWidth", document.documentElement.clientWidth, document.documentElement.clientWidth - (open ? 240 : 0) - 48)
+ setPlayerBarWidth(document.documentElement.clientWidth - (open ? 240 : 0) - 48);
+ }
+
+ const onTransitionEnd = () => {
+ handleResize();
+ }
+
+ useEffect(() => {
+ handleResize();
+ window.addEventListener('resize', handleResize);
+ return () => {
+ window.removeEventListener('resize', handleResize);
+ };
+ }, []);
+
+ useEffect(() => { handleResize(); }, [currentLyric]);
+
return
-
-
-
+
+
+
diff --git a/src/PlayerBar.js b/src/PlayerBar.js
index 4a64be3..60f6b72 100644
--- a/src/PlayerBar.js
+++ b/src/PlayerBar.js
@@ -1,8 +1,6 @@
import { MenuItem, Select, IconButton, Typography, Stack, Container } from "@mui/material"
-import styles from './PlayerBar.module.css';
import { useSelector, useDispatch } from 'react-redux'
import { useEffect, useRef, useState, useCallback } from "react";
-import { useResizeDetector } from 'react-resize-detector';
import pauseIcon from "./assets/play.png";
import playIcon from "./assets/pause.png";
import downloadIcon from "./assets/download.png";
@@ -18,10 +16,9 @@ const durationFormat = (time) => {
return hour.toString().padStart(2, '0') + ":" + minute.toString().padStart(2, '0') + ":" + second.toString().padStart(2, '0');
}
-export default function ({ currentTime }) {
+export default function ({ width, currentTime }) {
const dispatch = useDispatch();
const [duration, setDuration] = useState(0); // 秒,有小数点
- const [canvasWidth, setCanvasWidth] = useState(0);
const currentIndex = useSelector(state => state.recorder.currentIndex);
const recordList = useSelector(state => state.recorder.list);
const currentBlob = useSelector(state => state.recorder.currentBlob);
@@ -49,14 +46,6 @@ export default function ({ currentTime }) {
dispatch(setCurrentTime(player.current.currentTime));
}
- const onResize = useCallback((width, height) => {
- setCanvasWidth(width - 90 - 70);
- }, []);
-
- const { ref: playerBar } = useResizeDetector({
- onResize: onResize
- });
-
const seekRecord = (second) => {
player.current.currentTime = second;
}
@@ -81,23 +70,25 @@ export default function ({ currentTime }) {
-
-
+
+
-
}
\ No newline at end of file