|
@@ -1,27 +1,61 @@
|
|
|
-import Taro, { useLoad, useReady, useUnload } from '@tarojs/taro'
|
|
|
+import Taro, { useLoad, useReady, useUnload, useScope } from '@tarojs/taro'
|
|
|
import { PropsWithChildren, useState } from 'react'
|
|
|
import { View, Video, Navigator, Image } from '@tarojs/components'
|
|
|
import useGetCustomClient from '@/hooks/useGetCustomClient'
|
|
|
+import { wrapProps } from '@/plugin/share'
|
|
|
import './index.less'
|
|
|
|
|
|
-const WEB_VIEW_URL = 'plugin-private://wxf7261ed54f2e450e/pages/customPage/index'
|
|
|
+// const WEB_VIEW_URL = 'plugin-private://wxf7261ed54f2e450e/pages/customPage/index'
|
|
|
const VIDEO_SRC = 'https://xycdn.yishihui.com/ad/prod/video/material_AD_1708595757_1708595757542.mp4'
|
|
|
const VIDEO_COVER = 'http://rescdn.yishihui.com/ad/prod/video/material_AD_1702267670_1702267670233.mp4?x-oss-process=video/snapshot,t_5000,f_jpg,w_0,h_0,m_fast'
|
|
|
|
|
|
// 在一些场景下 loadedMetaFiredInOnce 被触发了很多次
|
|
|
let loadedMetaFiredInOnce = 0
|
|
|
-let durationTime = 0
|
|
|
|
|
|
-const noop = () => {}
|
|
|
|
|
|
function PqCustom(props: PropsWithChildren<CustomPropsType>) {
|
|
|
- const {
|
|
|
- width, zIndex, onLoad = noop, onView = noop, onClick = noop, onClose = noop, onError = noop
|
|
|
- } = props
|
|
|
+ let {
|
|
|
+ adpId,
|
|
|
+ autoplay,
|
|
|
+ loop,
|
|
|
+ muted,
|
|
|
+ showMusk,
|
|
|
+ zIndex,
|
|
|
+ openEmbeddedMiniProgram,
|
|
|
+ onPlay,
|
|
|
+ onPause,
|
|
|
+ onEnded,
|
|
|
+ onTimeUpdate,
|
|
|
+ onStop,
|
|
|
+ onError,
|
|
|
+ onLoad,
|
|
|
+ onView,
|
|
|
+ onClick,
|
|
|
+ onClose
|
|
|
+ } = wrapProps(props)
|
|
|
const [show, setShow] = useState(true)
|
|
|
|
|
|
- function clickCustom() {
|
|
|
-
|
|
|
+ function videoPlay() {
|
|
|
+ onPlay()
|
|
|
+ }
|
|
|
+
|
|
|
+ function videoPause() {
|
|
|
+ onPause()
|
|
|
+ }
|
|
|
+
|
|
|
+ function videoPlayEnded() {
|
|
|
+ onEnded()
|
|
|
+ }
|
|
|
+
|
|
|
+ function videoTimeUpdate() {
|
|
|
+ onTimeUpdate()
|
|
|
+ }
|
|
|
+
|
|
|
+ function videoStop() {
|
|
|
+ onStop()
|
|
|
+ }
|
|
|
+
|
|
|
+ function videoClick() {
|
|
|
closeCustom()
|
|
|
}
|
|
|
|
|
@@ -47,9 +81,18 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
|
|
|
|
|
|
{/* <Navigator url={WEB_VIEW_URL}> */}
|
|
|
<Custom
|
|
|
- width={width}
|
|
|
- zIndex={zIndex}
|
|
|
- onClick={clickCustom}
|
|
|
+ autoplay={autoplay}
|
|
|
+ loop={loop}
|
|
|
+ muted={muted}
|
|
|
+ src={VIDEO_SRC}
|
|
|
+ poster={VIDEO_COVER}
|
|
|
+ onPlay={videoPlay}
|
|
|
+ onTimeUpdate={videoTimeUpdate}
|
|
|
+ onPause={videoPause}
|
|
|
+ onEnded={videoPlayEnded}
|
|
|
+ onStop={videoStop}
|
|
|
+
|
|
|
+ onClick={videoClick}
|
|
|
onLoad={onLoad}
|
|
|
onView={onView}
|
|
|
onError={onError}
|
|
@@ -61,69 +104,59 @@ function PqCustom(props: PropsWithChildren<CustomPropsType>) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-function Custom({ width, zIndex, onClick, onLoad, onView, onError }) {
|
|
|
- const [style, setStyle] = useState({ width: '0px', height: 'px', zIndex })
|
|
|
+function Custom({
|
|
|
+ autoplay, loop, muted, src, poster,
|
|
|
+ onPlay, onPause, onEnded, onTimeUpdate, onStop, // 播放事件
|
|
|
+ onClick, onLoad, onView, onError
|
|
|
+}) {
|
|
|
+ const [style, setStyle] = useState({ width: '0px', height: 'px' })
|
|
|
|
|
|
useReady(() => {
|
|
|
loadedMetaFiredInOnce = 0
|
|
|
- durationTime = 0
|
|
|
-
|
|
|
- observerAdCustom()
|
|
|
})
|
|
|
|
|
|
useGetCustomClient((customClient) => {
|
|
|
let clientWidth = customClient.width
|
|
|
let clientHeight = customClient.height
|
|
|
- if (width) {
|
|
|
- clientWidth = width
|
|
|
- clientHeight = width / 375 * 667
|
|
|
- }
|
|
|
|
|
|
setStyle({
|
|
|
- zIndex: zIndex || 1,
|
|
|
width: `${clientWidth}px`,
|
|
|
height: `${clientHeight}px`
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- // TODO: 监听无效 需要再想别的办法
|
|
|
- function observerAdCustom() {
|
|
|
- const viewObserver = Taro.createIntersectionObserver(PqCustom, {
|
|
|
- thresholds: [0, 0.5]
|
|
|
- }).relativeToViewport()
|
|
|
-
|
|
|
- console.log(viewObserver)
|
|
|
-
|
|
|
- viewObserver.observe('#pq-custom', res => {
|
|
|
- const { intersectionRatio } = res
|
|
|
- if (intersectionRatio >= 0.5) {
|
|
|
- console.log('onView')
|
|
|
- onView()
|
|
|
- viewObserver.disconnect()
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
function onLoadedMetaData() {
|
|
|
if (loadedMetaFiredInOnce++ < 1) {
|
|
|
// 上报load
|
|
|
onLoad()
|
|
|
}
|
|
|
}
|
|
|
- // 播放上报
|
|
|
- function onPlay() {
|
|
|
- console.log('onPlay')
|
|
|
- }
|
|
|
-
|
|
|
- // 播放进度,广告的整个生命周期中需要记录视频播放的进度
|
|
|
- function onTimeUpdate(res) {
|
|
|
- const { detail } = res
|
|
|
- durationTime += (detail?.currentTime || 0)
|
|
|
- }
|
|
|
|
|
|
return (
|
|
|
<View className='custom' style={style}>
|
|
|
- <Video id='pq-custom' className='custom-video' autoplay={true} controls={false} loop src={VIDEO_SRC} onClick={onClick} onLoadedMetaData={onLoadedMetaData} onPlay={onPlay} onTimeUpdate={onTimeUpdate} onError={onError} objectFit='fill' poster={VIDEO_COVER} />
|
|
|
+ <Video
|
|
|
+ id='pq-custom'
|
|
|
+ className='custom-video'
|
|
|
+ objectFit='fill'
|
|
|
+ controls={false}
|
|
|
+ // video属性
|
|
|
+ autoplay={autoplay}
|
|
|
+ loop={loop}
|
|
|
+ muted={muted}
|
|
|
+ src={src}
|
|
|
+ poster={poster}
|
|
|
+ // video事件
|
|
|
+ onPlay={onPlay}
|
|
|
+ onTimeUpdate={onTimeUpdate}
|
|
|
+ onPause={onPause}
|
|
|
+ onEnded={onEnded}
|
|
|
+ onStop={onStop}
|
|
|
+ onError={onError}
|
|
|
+
|
|
|
+ // video交互
|
|
|
+ onClick={onClick}
|
|
|
+ onLoadedMetaData={onLoadedMetaData}
|
|
|
+ />
|
|
|
<View className='custom-bottom'>
|
|
|
<Image src='http://rescdn.yishihui.com/ad/prod/image/logo_AD_1702267670_1702267670233.png' className='logo' />
|
|
|
<View className='title'>5天站桩入门课</View>
|