operateVideoPlayer.ts 1.7 KB
Newer Older
1 2
import { ComponentPublicInstance } from 'vue'
import { findElmById, invokeVmMethod, invokeVmMethodWithoutArgs } from '../util'
3
import { getPageById } from '../../framework/page/getCurrentPages'
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

const METHODS = {
  play(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'play')
  },
  pause(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'pause')
  },
  seek(ctx: any, args: { position: number }) {
    return invokeVmMethod(ctx, 'seek', args.position)
  },
  stop(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'stop')
  },
  sendDanmu(ctx: any, args: WechatMiniprogram.Danmu) {
    return invokeVmMethod(ctx, 'sendDanmu', args)
  },
  playbackRate(ctx: any, args: { rate: number }) {
    return invokeVmMethod(ctx, 'playbackRate', args.rate)
  },
  requestFullScreen(
    ctx: any,
    args: WechatMiniprogram.VideoContextRequestFullScreenOption = {}
  ) {
    return invokeVmMethod(ctx, 'requestFullScreen', args)
  },
  exitFullScreen(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'exitFullScreen')
  },
  showStatusBar(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'showStatusBar')
  },
  hideStatusBar(ctx: any) {
    return invokeVmMethodWithoutArgs(ctx, 'hideStatusBar')
  },
}

D
DCloud_LXH 已提交
41 42 43 44 45 46
export function operateVideoPlayer(
  videoId: string,
  pageId: number,
  type: string,
  data?: unknown
) {
47
  const page = getPageById(pageId)
48 49 50 51 52 53 54
  if (page?.$page.meta.isNVue) {
    const pageVm = (page as any).$vm as ComponentPublicInstance
    return METHODS[type as keyof typeof METHODS](
      findElmById(videoId, pageVm),
      data as any
    )
  }
D
DCloud_LXH 已提交
55 56 57 58 59 60 61 62 63 64
  UniServiceJSBridge.invokeViewMethod(
    'video.' + videoId,
    {
      videoId,
      type,
      data,
    },
    pageId
  )
}