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