video-format.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view class="page-scroll-view">
  4. <!-- #endif -->
  5. <page-head title="video-format"></page-head>
  6. <view class="uni-padding-wrap uni-common-mt">
  7. <view class="uni-title">
  8. <text class="uni-title-text">支持的视频格式示例</text>
  9. </view>
  10. <view v-for="(item,index) in supportFormats" :key="index">
  11. <text class="uni-subtitle-text">{{item.format}}</text>
  12. <video :id="'video-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"
  13. @error="onError(item.format, $event as UniVideoErrorEvent)"></video>
  14. </view>
  15. <view class="uni-title">
  16. <text class="uni-title-text">暂不支持的格式</text>
  17. </view>
  18. <view v-for="(item,index) in notSupportFormats" :key="index">
  19. <text class="uni-subtitle-text">{{item.format}}</text>
  20. <video :id="'video-' + item.format" :ref="'videoRef-' + item.format" class="video" :src="item.src"
  21. :controls="true" :direction="-90"></video>
  22. </view>
  23. </view>
  24. <!-- #ifdef APP -->
  25. </scroll-view>
  26. <!-- #endif -->
  27. </template>
  28. <script setup>
  29. type VideoFormat = {
  30. format : string
  31. src : string
  32. }
  33. let supportFormats = ref([
  34. // TODO web本地运行时本地服务返回的content-type不对,导致本地视频无法播放。此外web端原生video不支持flv、m3u8、avi格式,但是和app端相比多了ogg格式的支持
  35. {
  36. format: 'mp4',
  37. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4'
  38. },
  39. {
  40. format: 'm4v',
  41. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.m4v'
  42. },
  43. {
  44. format: 'mov',
  45. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mov'
  46. },
  47. {
  48. format: 'webm(iOS、Safari、鸿蒙不支持)',
  49. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.webm'
  50. },
  51. {
  52. format: '3gp',
  53. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.3gp'
  54. },
  55. // #ifndef WEB || MP
  56. {
  57. format: 'flv',
  58. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.flv'
  59. },
  60. // #endif
  61. // #ifndef WEB
  62. {
  63. format: 'm3u8',
  64. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.m3u8'
  65. },
  66. // #endif
  67. // #ifndef WEB || MP
  68. {
  69. format: '本地m3u8',
  70. src: '/static/test-video/2minute-demo.m3u8'
  71. },
  72. // #endif
  73. {
  74. format: '错误路径',
  75. src: 'https://www.dcloud.net.cn/errorpath.mp4'
  76. },
  77. ] as Array<VideoFormat>)
  78. let notSupportFormats = ref([
  79. // #ifndef WEB
  80. {
  81. format: 'ogg',
  82. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.ogg'
  83. },
  84. // #endif
  85. // #ifndef MP
  86. {
  87. format: 'avi',
  88. src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.avi'
  89. }
  90. // #endif
  91. ] as Array<VideoFormat>)
  92. // 自动化测试
  93. const isError = reactive({ value: false })
  94. const onError = (format : string, e : UniVideoErrorEvent) => {
  95. console.log(format + ":" + JSON.stringify(e));
  96. if (format != "错误路径") {
  97. isError['value'] = true;
  98. }
  99. }
  100. onReady(() => {
  101. // const v = uni.createVideoContext("video-mp4",getCurrentInstance()!.proxy!)
  102. // v?.play()
  103. })
  104. defineExpose({ isError })
  105. </script>
  106. <style>
  107. .video {
  108. height: 200px;
  109. }
  110. </style>