video-format.uvue 3.3 KB
Newer Older
1
<template>
xuty73419315's avatar
xuty73419315 已提交
2
  <scroll-view style="flex: 1;">
3 4 5 6 7 8 9 10
    <page-head :title="title"></page-head>
    <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"
雪洛's avatar
雪洛 已提交
11
          @error="onError(item.format, $event as VideoErrorEvent)"></video>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
      </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>
        <video :id="'video-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"></video>
      </view>
    </view>
  </scroll-view>
</template>

<script>
  export default {
    data() {
      return {
        title: 'video-format',
        supportFormats: [
雪洛's avatar
雪洛 已提交
30
          // TODO web本地运行时本地服务返回的content-type不对,导致本地视频无法播放。此外web端原生video不支持flv、m3u8、avi格式,但是和app端相比多了ogg格式的支持
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
          {
            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',
            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'
          },
雪洛's avatar
雪洛 已提交
51
          // #ifndef WEB
52 53 54 55 56 57 58 59 60 61 62
          {
            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'
W
wanganxp 已提交
63
          },
雪洛's avatar
雪洛 已提交
64
          // #endif
W
wanganxp 已提交
65 66 67 68
          {
            format: '错误路径',
            src: 'https://www.dcloud.net.cn/errorpath.mp4'
          },
69 70
        ] as Array<VideoFormat>,
        notSupportFormats: [
雪洛's avatar
雪洛 已提交
71
          // #ifndef WEB
72 73 74 75
          {
            format: 'ogg',
            src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.ogg'
          },
雪洛's avatar
雪洛 已提交
76
          // #endif
77 78 79 80 81 82 83 84 85
          {
            format: 'avi',
            src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.avi'
          }
        ] as Array<VideoFormat>,
        isError: false
      }
    },
    methods: {
雪洛's avatar
雪洛 已提交
86
      onError: function (format: string, e : VideoErrorEvent) {
雪洛's avatar
雪洛 已提交
87
        console.log(format + ":" + JSON.stringify(e));
88
        if (format != "错误路径") {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
89 90
          this.isError = true;
        }
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      }
    }
  }

  type VideoFormat = {
    format : string
    src : string
  }
</script>

<style>
  .video {
    height: 400rpx;
  }
</style>