Skip to content

Commit

Permalink
refactor: 调整弹幕的加载
Browse files Browse the repository at this point in the history
  • Loading branch information
duan602728596 committed Apr 24, 2023
1 parent a1c4cad commit f07ea5b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 87 deletions.
84 changes: 18 additions & 66 deletions packages/48tools/src/pages/PlayerWindow/LiveInfo/LiveInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { ipcRenderer } from 'electron';
import {
Fragment,
useState,
type ReactElement,
type ReactNode,
type Dispatch as D,
type SetStateAction as S,
type MouseEvent
} from 'react';
import type { ReactElement, ReactNode, MouseEvent } from 'react';
import * as PropTypes from 'prop-types';
import { Avatar, Button, Tag, Tooltip, Space, message } from 'antd';
import type { UseMessageReturnType } from '@48tools-types/antd';
import {
ToolTwoTone as IconToolTwoTone,
UnorderedListOutlined as IconUnorderedListOutlined,
StopOutlined as IconStopOutlined
} from '@ant-design/icons';
import { Avatar, Button, Tag, Tooltip } from 'antd';
import { ToolTwoTone as IconToolTwoTone } from '@ant-design/icons';
import { source } from '../../../utils/snh48';
import { getDanmuLocal, setDanmuLocal } from '../function/danmuLocal';
import type { PlayerInfo } from '../PlayerWindow';
import type { LiveRoomInfo } from '../../48/services/interface';

Expand All @@ -29,15 +15,6 @@ interface LiveInfoProps {
/* 显示直播信息 */
function LiveInfo(props: LiveInfoProps): ReactElement {
const { playerInfo, info }: LiveInfoProps = props;
const [messageApi, messageContextHolder]: UseMessageReturnType = message.useMessage();
const [dl, setDl]: [boolean, D<S<boolean>>] = useState(getDanmuLocal());

// 设置弹幕
function handleDanmuSwitchClick(value: boolean, event: MouseEvent): void {
setDl(value);
setDanmuLocal(value);
messageApi.info(`${ value ? '开启' : '关闭' }弹幕加载,下次观看录播时生效。`);
}

// 打开开发者工具
function handleOpenDeveloperToolsClick(event: MouseEvent): void {
Expand All @@ -59,47 +36,22 @@ function LiveInfo(props: LiveInfoProps): ReactElement {
}

return (
<Fragment>
<header className="shrink-0 mb-[8px]">
<h1 className="inline-block mb-[8px] mr-[6px] text-[16px]">{ playerInfo.title }</h1>
{
playerInfo.liveMode === 1
? <Tag color="blue">录屏</Tag>
: (playerInfo.liveType === 2 ? <Tag color="volcano">电台</Tag> : <Tag color="purple">视频</Tag>)
}
<div className="flex">
<div className="grow">{ infoRender() }</div>
<div className="shrink-0">
<Space>
{
dl ? (
<Tooltip title="关闭弹幕加载功能">
<Button type="primary"
danger={ true }
icon={ <IconStopOutlined /> }
aria-label="关闭弹幕加载功能"
onClick={ (event: MouseEvent): void => handleDanmuSwitchClick(false, event) }
/>
</Tooltip>
) : (
<Tooltip title="开启弹幕加载功能">
<Button type="primary"
icon={ <IconUnorderedListOutlined /> }
aria-label="开启弹幕加载功能"
onClick={ (event: MouseEvent): void => handleDanmuSwitchClick(true, event) }
/>
</Tooltip>
)
}
<Tooltip title="开发者工具">
<Button type="text" icon={ <IconToolTwoTone /> } aria-label="开发者工具" onClick={ handleOpenDeveloperToolsClick } />
</Tooltip>
</Space>
</div>
<header className="shrink-0 mb-[8px]">
<h1 className="inline-block mb-[8px] mr-[6px] text-[16px]">{ playerInfo.title }</h1>
{
playerInfo.liveMode === 1
? <Tag color="blue">录屏</Tag>
: (playerInfo.liveType === 2 ? <Tag color="volcano">电台</Tag> : <Tag color="purple">视频</Tag>)
}
<div className="flex">
<div className="grow">{ infoRender() }</div>
<div className="shrink-0">
<Tooltip title="开发者工具">
<Button type="text" icon={ <IconToolTwoTone /> } aria-label="开发者工具" onClick={ handleOpenDeveloperToolsClick } />
</Tooltip>
</div>
</header>
{ messageContextHolder }
</Fragment>
</div>
</header>
);
}

Expand Down
5 changes: 2 additions & 3 deletions packages/48tools/src/pages/PlayerWindow/Video/RecordVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { source, engineUserAgent } from '../../../utils/snh48';
import { requestDownloadFile } from '../../48/services/pocket48';
import { formatTsUrl } from '../../48/Pocket48/Pocket48Record/Pocket48Record';
import { danmuStore } from '../function/DanmuStore';
import { getDanmuLocal } from '../function/danmuLocal';
import type { PlayerInfo } from '../PlayerWindow';
import type { LiveRoomInfo } from '../../48/services/interface';
import type { DanmuItem } from '../types';
Expand Down Expand Up @@ -63,10 +62,10 @@ function RecordVideo(props: RecordVideoProps): ReactElement {

// 生成弹幕文件
function createVideoTrack(): void {
if (videoLoaded && danmuList.length && videoRef.current && getDanmuLocal()) {
if (videoLoaded && danmuList.length && videoRef.current) {
const track: TextTrack = videoRef.current.addTextTrack('subtitles', '弹幕', 'zh');

track.mode = 'showing';
track.mode = 'hidden';

for (const item of danmuList) {
const vttcue: VTTCue = new VTTCue(item.currentTime, item.currentTime + 3, `${ item.nickname }${ item.message }`);
Expand Down
18 changes: 0 additions & 18 deletions packages/48tools/src/pages/PlayerWindow/function/danmuLocal.ts

This file was deleted.

0 comments on commit f07ea5b

Please sign in to comment.