Skip to content

Commit

Permalink
修复artplayer的倍速不同步问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Rcrwrate committed Jul 14, 2023
1 parent 93ab371 commit 8dc257b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

- [x] Artplayer ASS字幕

- [ ] Artplayer ASS字幕在某些时候无法正常显示(应该是前一个ASS元素未被销毁导致的问题)

- [x] Artplayer弹幕

- [x] 支持多种播放器
Expand All @@ -32,6 +34,8 @@

有一说一,React有点过于神秘(确信)

### React一番细嗦

具体举个例子,我还是不是很懂

这段代码用于生成Websocket客户端,ws将作为prop传递给其他的组件,然后神奇的事情出现了
Expand Down Expand Up @@ -77,7 +81,7 @@ PS: No.1和No.2视为同一种方案,实践中只使用了No.2
更有甚者,二者接不需要


### 二番细嗦
### React二番细嗦

我在翻了一遍文档之后,发现了真相(**总结:切忌不看文档就上手!**)

Expand Down Expand Up @@ -131,6 +135,8 @@ const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
```
使用暴力`sleep(1000)`去强行等待初始化完成
**最终的问题出现了,这个不符合官方规范的问题到底要不要修**
### ASS.js学习记录
这个库,可比react还要神奇,鉴于真的没有官方说明文档,以下所有东西都是瞎几把摸索
Expand Down
3 changes: 0 additions & 3 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { ConfigUI, Waiting, Sysytem } from './config';
import 'mdui/dist/css/mdui.min.css';
import 'mdui/dist/js/mdui.min.js';
import './console.css'
import testASS from './test';
import TestASS from './test';


const App = () => {
Expand Down Expand Up @@ -60,7 +58,6 @@ const App = () => {
: <></>
}
{ws.Init ? <LeaveRoom ws={ws} Auto={Auto} /> : <></>}
{/* <TestASS /> */}
</div>
);
};
Expand Down
21 changes: 17 additions & 4 deletions client/src/Video.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ import Artplayer from 'artplayer';
import artplayerPluginDanmuku from 'artplayer-plugin-danmuku';
import ASS from 'assjs';

/**
* @param {URL} url
* @return {string}
*/
async function subtitle(url) {
var r = await fetch(url)
return await r.text()
// return URL.createObjectURL(new Blob([r], { type: "text/plain" }))
}

/**
* @param {URL} url
* @return {string}
*/
function get_id(url) {
var id = new URL(url).searchParams.get("UniqueId")
if (id == null) { var id = "0000000" }
return id
}

const DP = ({ ws }) => {
const playerRef = useRef(null);
// const [dp, setdp] = useState(null)

useEffect(() => {
var id = new URL(ws.setting.url).searchParams.get("UniqueId")
if (id == null) { var id = "0000000" }
var id = get_id(ws.setting.url)
const player = new DPlayer({
container: playerRef.current,
video: {
Expand Down Expand Up @@ -106,8 +119,7 @@ function AP({ ws }) {
}

useEffect(() => {
var id = new URL(ws.setting.url).searchParams.get("UniqueId")
if (id == null) { var id = "0000000" }
var id = get_id(ws.setting.url)

const player = new Artplayer({
container: artRef.current,
Expand Down Expand Up @@ -184,6 +196,7 @@ function AP({ ws }) {
player._play = () => { player.video._play() }
player._pause = () => { player.video._pause() }
player._seek = (t) => { player.video.currentTime = t }
player._speed = (t) => { player.video.playbackRate = t }
player.video.play = ban
player.video.pause = ban
// player.video.fastSeek = ban
Expand Down

0 comments on commit 8dc257b

Please sign in to comment.