video-format.uvue 3.2 KB
Newer Older
1
<template>
2
  <!-- #ifdef APP -->
H
hdx 已提交
3 4
  <scroll-view class="page-scroll-view">
  <!-- #endif -->
W
wanganxp 已提交
5
    <page-head title="video-format"></page-head>
6 7 8 9 10 11 12
    <view class="uni-padding-wrap uni-common-mt">
      <view class="uni-title">
        <text class="uni-title-text">支持的视频格式示例</text>
      </view>
      <view v-for="(item,index) in supportFormats" :key="index">
        <text class="uni-subtitle-text">{{item.format}}</text>
        <video :id="'video-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
13
          @error="onError(item.format, $event as UniVideoErrorEvent)"></video>
14 15 16 17 18 19
      </view>
      <view class="uni-title">
        <text class="uni-title-text">暂不支持的格式</text>
      </view>
      <view v-for="(item,index) in notSupportFormats" :key="index">
        <text class="uni-subtitle-text">{{item.format}}</text>
W
wanganxp 已提交
20
        <video :id="'video-' + item.format" :ref="'videoRef-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"></video>
21 22
      </view>
    </view>
H
hdx 已提交
23
  <!-- #ifdef APP -->
24
  </scroll-view>
25
  <!-- #endif -->
26 27
</template>

W
wanganxp 已提交
28
<script setup>
H
hdx 已提交
29 30 31 32
  type VideoFormat = {
    format : string
    src : string
  }
W
wanganxp 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  let supportFormats = ref([
    // TODO web本地运行时本地服务返回的content-type不对,导致本地视频无法播放。此外web端原生video不支持flv、m3u8、avi格式,但是和app端相比多了ogg格式的支持
    {
      format: 'mp4',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4'
    },
    {
      format: 'm4v',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.m4v'
    },
    {
      format: 'mov',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mov'
    },
    {
      format: 'webm(iOS和Safari不支持)',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.webm'
    },
    {
      format: '3gp',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.3gp'
    },
    // #ifndef WEB
    {
      format: 'flv',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.flv'
    },
    {
      format: 'm3u8',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.m3u8'
    },
    {
      format: '本地m3u8',
      src: '/static/test-video/2minute-demo.m3u8'
    },
    // #endif
    {
      format: '错误路径',
      src: 'https://www.dcloud.net.cn/errorpath.mp4'
    },
  ] as Array<VideoFormat>)
H
hdx 已提交
74

W
wanganxp 已提交
75 76 77 78 79
  let notSupportFormats =ref([
    // #ifndef WEB
    {
      format: 'ogg',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.ogg'
80
    },
W
wanganxp 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93
    // #endif
    {
      format: 'avi',
      src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.avi'
    }
  ] as Array<VideoFormat>)

  let isError = false         // 自动化测试

  const onError = (format : string, e : UniVideoErrorEvent) => {
    console.log(format + ":" + JSON.stringify(e));
    if (format != "错误路径") {
      isError = true;
94 95
    }
  }
W
wanganxp 已提交
96 97 98 99 100 101 102

  onReady(() => {
    // const v = uni.createVideoContext("video-mp4",getCurrentInstance()!.proxy!)
    // v?.play()
  })

  defineExpose({isError})
103 104 105 106
</script>

<style>
  .video {
H
hdx 已提交
107
    height: 200px;
108 109
  }
</style>