import { Image, Video, VideoProps, ImageProps, View } from "@tarojs/components"; import { useEffect, useRef } from "react"; import Taro from "@tarojs/taro"; import { DEFAULT_AVATAR } from '@/config' interface Props { source?: string; className: string; mode?: keyof ImageProps.Mode | undefined } export const AvatarMedia = ({ source, className, mode = 'widthFix' }: Props) => { const videoRef = useRef|null>(null); const videoContext = useRef(null); const videoId = useRef(`video-${Math.random().toString(36).substr(2, 9)}`); const videoErrorCallback = (e) => { console.log('Video error info:') console.log(e.detail) } // 处理 ios 上无法循环播放的 bug const handleOnEnded = () => { if(videoContext.current){ videoContext.current.seek(0) videoContext.current.play() } } useEffect(() => { if (videoRef.current) { videoContext.current = Taro.createVideoContext(videoId.current, this); } }, []); // 以 .mp4 结尾则认为是 视频 if (source && source.slice(-4) === '.mp4') { return (