更新:课程视频播放改成原生video组件

This commit is contained in:
2025-11-21 18:09:24 +08:00
parent 754865e23e
commit ac60a863e3
15 changed files with 1729 additions and 333 deletions

248
types/video.d.ts vendored
View File

@@ -1,210 +1,92 @@
// types/video.d.ts
/**
* 视频相关类型定义
* 完全基于原项目 medicine_app 的数据结构
*/
import type { IApiResponse } from './book'
/**
* 视频基本信息
* 对应原项目中的视频数据结构
* 视频信息
*/
export interface IVideoInfo {
id: number // 视频 ID
title: string // 视频标题
type: '1' | '2' | string // 类型: 1-视频 2-音频
video?: string // 阿里云视频 ID(原始)
videoId?: string // 阿里云视频 ID(处理后,移除等号)
videoUrl?: string // 视频 URL(普通视频)
m3u8Url?: string | null // M3U8 地址(标准加密)
playAuth?: string // 播放凭证
sort?: number // 排序
chapterId?: number // 章节 ID
courseId?: number // 课程 ID
catalogueId?: number // 目录 ID
userCourseVideoPositionEntity?: {
position: number // 服务器记录的播放位置(秒)
}
[key: string]: any // 允许其他字段
id: number
chapterId: number
type: 0 | 1 // 0: MP4, 1: M3U8
video: string // 视频ID
sort: number
duration: number // 视频时长(秒)
createTime: string
delFlag: number
playAuth?: string // 阿里云播放授权
videoUrl?: string // 视频URL兼容字段
m3u8Url?: string // M3U8流地址
mp4Url?: string // MP4视频地址
mtsHlsUriToken?: string // M3U8 Token
userCourseVideoPositionEntity?: IVideoPosition
}
/**
* 视频数据(扩展)
* 包含播放时间等额外信息
* 视频播放位置
*/
export interface IVideoData extends IVideoInfo {
firstTime?: number // 初始播放时间(秒)
time?: number // 当前播放时间(秒)
export interface IVideoPosition {
id: number
userId: number
videoId: number
position: number // 播放位置(秒)
createTime: string
updateTime: string
delFlag: number
}
/**
* 本地存储的视频列表项
* 存储在 localStorage 的 videoOssList 中
* 视频检查接口响应
*/
export interface IVideoStorageItem {
id: number // 视频 ID
time: number // 播放时间(秒)
[key: string]: any // 其他视频信息
export interface IVideoCheckResponse {
msg: string
code: number
video: IVideoInfo
}
/**
* 检查视频请求参数
* 对应 sociology/course/checkVideo 接口
* 视频播放器组件 Props
*/
export interface ICheckVideoRequest {
id?: number // 视频 ID
video?: string // 视频标识
courseId?: number // 课程 ID
catalogueId?: number // 目录 ID
chapterId?: number // 章节 ID
[key: string]: any // 允许其他参数
}
/**
* 检查视频响应
* 对应 sociology/course/checkVideo 接口返回
*/
export interface ICheckVideoResponse extends IApiResponse {
video: IVideoInfo // 视频信息
}
/**
* 保存播放位置请求参数
* 对应 sociology/course/saveCoursePosition 接口
*/
export interface ISaveCoursePositionRequest {
videoId: number // 视频 ID
position: number // 播放位置(秒)
}
/**
* 保存播放位置响应
* 对应 sociology/course/saveCoursePosition 接口返回
*/
export interface ISaveCoursePositionResponse extends IApiResponse {
// 继承基础响应结构
}
/**
* 记录错误视频请求参数
* 对应 medical/course/addErrorCourse 接口
* 用于记录 iOS 不支持的视频
*/
export interface IAddErrorCourseRequest {
chapterId: number // 章节 ID
videoId: number // 视频 ID
sort: number // 排序
}
/**
* 记录错误视频响应
* 对应 medical/course/addErrorCourse 接口返回
*/
export interface IAddErrorCourseResponse extends IApiResponse {
// 继承基础响应结构
}
/**
* 章节详情
* 用于视频列表组件
*/
export interface IChapterDetail {
id: number // 章节 ID
title: string // 章节标题
imgUrl?: string // 章节图片
content?: string // 章节内容
questions?: string // 思考题
[key: string]: any // 其他字段
}
/**
* 平台类型
*/
export type PlatformType = 'ios' | 'android' | 'h5' | null
/**
* 屏幕方向类型
*/
export type ScreenOrientationType = 'portrait-primary' | 'landscape-primary'
/**
* 播放器配置选项
* 对应阿里云播放器配置
*/
export interface IPlayerOptions {
id: string // 容器 ID
width: string // 宽度
height: string // 高度
autoplay?: boolean // 自动播放
playsinline?: boolean // 内联播放
controlBarVisibility?: 'hover' | 'click' | 'always' // 控制栏显示方式
useH5Prism?: boolean // 使用 H5 播放器
qualitySort?: 'asc' | 'desc' // 清晰度排序
isLive?: boolean // 是否直播
rePlay?: boolean // 是否重播
cover?: string // 封面图
// 私有加密视频配置
vid?: string // 视频 ID
playauth?: string // 播放凭证
encryptType?: number // 加密类型: 1-私有加密
playConfig?: {
EncryptType: string // 加密类型名称
}
// 标准加密/普通视频配置
source?: string // 视频地址
// 组件配置
components?: Array<{
name: string
type: any
args?: any[]
}>
// 皮肤布局
skinLayout?: Array<{
name: string
align?: string
x?: number
y?: number
children?: Array<{
name: string
align?: string
x?: number
y?: number
}>
export interface IVideoPlayerProps {
videoList: Array<{
id: number
chapterId: number
video: string
sort: number
type?: 0 | 1
duration?: number
}>
currentIndex: number
countdownSeconds?: number
showWatermark?: boolean
watermarkText?: string
}
/**
* 全屏状态变化数据
* 视频播放器组件状态
*/
export interface IScreenChangeData {
status: boolean // 全屏状态
primary: ScreenOrientationType // 屏幕方向
export interface IVideoPlayerState {
currentVideoData: IVideoInfo | null
currentTime: number
firstTime: number
isSetFirstTime: boolean
isFullScreen: boolean
showCountdown: boolean
countdownRemaining: number
showError: boolean
errorMessage: string
isLoading: boolean
isChanging: boolean
playbackRate: number
volume: number
}
/**
* 播放时间记录数据
* 视频错误类型
*/
export interface IRecordTimeData {
time: number // 播放时间(秒)
status?: string // 播放状态
}
/**
* 错误提示数据
*/
export interface IOpenShowData {
msg?: string // 错误消息
}
/**
* 初始化数据
*/
export interface IInitData {
currentVideo: IVideoInfo // 当前视频
currentVideoList?: IVideoInfo[] // 视频列表
export enum VideoErrorType {
NETWORK_ERROR = 'NETWORK_ERROR',
VIDEO_LOAD_ERROR = 'VIDEO_LOAD_ERROR',
ENCRYPTION_ERROR = 'ENCRYPTION_ERROR',
PLATFORM_NOT_SUPPORTED = 'PLATFORM_NOT_SUPPORTED',
INVALID_PARAMS = 'INVALID_PARAMS',
API_ERROR = 'API_ERROR'
}