|
|
@ -1,7 +1,7 @@ |
|
|
|
import {BaseEventOrig, Video, VideoProps} from "@tarojs/components"; |
|
|
|
import {BaseEventOrig, Video, VideoProps} from "@tarojs/components"; |
|
|
|
import {HVideoOptions} from "@/components/video/type"; |
|
|
|
import {HVideoOptions} from "@/components/video/type"; |
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
import {FC, useState} from "react"; |
|
|
|
import {FC, useEffect, useState} from "react"; |
|
|
|
import unique_ident from "@/hooks/unique_ident"; |
|
|
|
import unique_ident from "@/hooks/unique_ident"; |
|
|
|
import videoEvents from "@/hooks/videoEvents"; |
|
|
|
import videoEvents from "@/hooks/videoEvents"; |
|
|
|
|
|
|
|
|
|
|
@ -12,6 +12,10 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
video = Taro.createVideoContext('myVideo') |
|
|
|
video = Taro.createVideoContext('myVideo') |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
videoEvents.onSetVideoState(({name}) => { |
|
|
|
videoEvents.onSetVideoState(({name}) => { |
|
|
|
switch (name) { |
|
|
|
switch (name) { |
|
|
|
case "pause": |
|
|
|
case "pause": |
|
|
@ -22,8 +26,7 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
}, []) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function onTimeUpdate(event: BaseEventOrig<VideoProps.onTimeUpdateEventDetail>) { |
|
|
|
function onTimeUpdate(event: BaseEventOrig<VideoProps.onTimeUpdateEventDetail>) { |
|
|
|
const time = event.detail.currentTime |
|
|
|
const time = event.detail.currentTime |
|
|
@ -66,6 +69,7 @@ const HVideo: FC<HVideoOptions> = (opt: HVideoOptions) => { |
|
|
|
function onEnded() { |
|
|
|
function onEnded() { |
|
|
|
if (currentTime + 1 > opt.duration) { |
|
|
|
if (currentTime + 1 > opt.duration) { |
|
|
|
opt.onEnded() |
|
|
|
opt.onEnded() |
|
|
|
|
|
|
|
videoEvents.videoState('pause') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
video?.seek(currentTime) |
|
|
|
video?.seek(currentTime) |
|
|
|
unique_ident.remove() |
|
|
|
unique_ident.remove() |
|
|
|