Files
JKVideo/store/liveStore.ts
Developer 33a3148b38 feat: 直播小窗播放(PiP)功能
- 新增 store/liveStore.ts:Zustand store,存储小窗直播状态(roomId/title/cover/hlsUrl)
- 新增 components/LiveMiniPlayer.tsx:可拖动悬浮迷你直播播放器
  - 原生端实际播放 HLS 流(react-native-video,有声)
  - Web 端降级展示封面图 + LIVE 徽标
  - LIVE 红点徽标 + 标题条底部
  - 关闭按钮(×)和点击进入直播间
  - HLS 出错时自动关闭(onError → clearLive)
  - 视频 MiniPlayer 激活时自动上移避免重叠
- _layout.tsx:全局挂载 <LiveMiniPlayer />
- live/[roomId].tsx:顶部栏添加小窗按钮(browsers-outline)
  - 仅直播中且有流地址时显示,离线时占位保持 title 居中
  - 点击后 setLive + router.back(),返回首页继续看直播
  - 进入同房间时自动 clearLive() 避免双播
2026-03-25 13:16:16 +08:00

24 lines
657 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { create } from 'zustand';
interface LiveStore {
isActive: boolean;
roomId: number;
title: string;
cover: string; // room.keyframe直播截图用于 web 端降级封面
hlsUrl: string;
setLive: (roomId: number, title: string, cover: string, hlsUrl: string) => void;
clearLive: () => void;
}
export const useLiveStore = create<LiveStore>(set => ({
isActive: false,
roomId: 0,
title: '',
cover: '',
hlsUrl: '',
setLive: (roomId, title, cover, hlsUrl) =>
set({ isActive: true, roomId, title, cover, hlsUrl }),
clearLive: () =>
set({ isActive: false, roomId: 0, title: '', cover: '', hlsUrl: '' }),
}));