feat(video): 添加获取播放器实例功能
- 在 AliPlayer 组件中新增 onGetPlayerInstance 属性定义 - 将 onGetPlayerInstance 作为参数传递给内部播放器组件 - 实现播放器实例回调功能,支持外部访问播放器对象 - 更新 Video 组件接口以透传播放器实例回调函数master
parent
ebb9af5aa8
commit
75b26f6b55
|
|
@ -25,6 +25,8 @@ export interface AliPlayerProps {
|
|||
onEnded?: () => void;
|
||||
/** 播放进度更新事件 */
|
||||
onTimeupdate?: (currentTime: number) => void;
|
||||
/** 获取播放器实例 */
|
||||
onGetPlayerInstance?: (player: any) => void;
|
||||
/** 传递给 AliPlayer 的属性 */
|
||||
aliPlayerProps?: Record<string, any>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ const AliPlayer = forwardRef(({
|
|||
playTime = 0,
|
||||
onEnded,
|
||||
onTimeupdate,
|
||||
onGetPlayerInstance,
|
||||
aliPlayerProps,
|
||||
}, ref) => {
|
||||
const playerRef = useRef(null);
|
||||
|
|
@ -125,6 +126,7 @@ const AliPlayer = forwardRef(({
|
|||
...aliPlayerProps,
|
||||
},
|
||||
(player) => {
|
||||
onGetPlayerInstance && onGetPlayerInstance(player);
|
||||
if (autoplay) {
|
||||
player.play();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const Video = forwardRef(({
|
|||
onCancel,
|
||||
onEnded,
|
||||
onTimeupdate,
|
||||
onGetPlayerInstance,
|
||||
aliPlayerProps = {},
|
||||
}, ref) => {
|
||||
const [internalVisible, setInternalVisible] = useState(false);
|
||||
|
|
@ -76,6 +77,7 @@ const Video = forwardRef(({
|
|||
aliPlayerProps={aliPlayerProps}
|
||||
onEnded={onEnded}
|
||||
onTimeupdate={onTimeupdate}
|
||||
onGetPlayerInstance={onGetPlayerInstance}
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue