提交 e59580e0 编写于 作者: W wanganxp

更新video和webview示例

上级 3e5b78a9
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view class="page-scroll-view"> <scroll-view class="page-scroll-view">
<!-- #endif --> <!-- #endif -->
<page-head :title="title"></page-head> <page-head title="video-format"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<view class="uni-title"> <view class="uni-title">
<text class="uni-title-text">支持的视频格式示例</text> <text class="uni-title-text">支持的视频格式示例</text>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</view> </view>
<view v-for="(item,index) in notSupportFormats" :key="index"> <view v-for="(item,index) in notSupportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text> <text class="uni-subtitle-text">{{item.format}}</text>
<video :id="'video-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"></video> <video :id="'video-' + item.format" :ref="'videoRef-' + item.format" class="video" :src="item.src" :controls="true" :direction="-90"></video>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -25,82 +25,81 @@ ...@@ -25,82 +25,81 @@
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script setup>
type VideoFormat = { type VideoFormat = {
format : string format : string
src : string src : string
} }
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>)
export default { let notSupportFormats =ref([
data() { // #ifndef WEB
return { {
title: 'video-format', format: 'ogg',
supportFormats: [ src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.ogg'
// 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>,
notSupportFormats: [
// #ifndef WEB
{
format: 'ogg',
src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.ogg'
},
// #endif
{
format: 'avi',
src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.avi'
}
] as Array<VideoFormat>,
// 自动化测试
isError: false
}
}, },
methods: { // #endif
onError: function (format : string, e : UniVideoErrorEvent) { {
console.log(format + ":" + JSON.stringify(e)); format: 'avi',
if (format != "错误路径") { src: 'https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.avi'
this.isError = true; }
} ] as Array<VideoFormat>)
}
let isError = false // 自动化测试
const onError = (format : string, e : UniVideoErrorEvent) => {
console.log(format + ":" + JSON.stringify(e));
if (format != "错误路径") {
isError = true;
} }
} }
onReady(() => {
// const v = uni.createVideoContext("video-mp4",getCurrentInstance()!.proxy!)
// v?.play()
})
defineExpose({isError})
</script> </script>
<style> <style>
......
...@@ -90,7 +90,8 @@ ...@@ -90,7 +90,8 @@
import { ItemType } from '@/components/enum-data/enum-data'; import { ItemType } from '@/components/enum-data/enum-data';
export default { export default {
onReady() { onReady() {
this.videoContext = uni.createVideoContext('video', this); this.videoContext = uni.createVideoContext('video');
// this.videoContext = uni.createVideoContext('video', this);
}, },
data() { data() {
return { return {
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
} }
}, },
webviewContext: null as WebviewContext | null, webviewContext: null as WebviewContext | null,
webviewElement: null as UniWebViewElement | null,
loadError: false, loadError: false,
horizontalScrollBarAccess: true, horizontalScrollBarAccess: true,
verticalScrollBarAccess: true, verticalScrollBarAccess: true,
...@@ -65,7 +66,10 @@ ...@@ -65,7 +66,10 @@
onReady() { onReady() {
// #ifdef APP // #ifdef APP
// TODO web 实现createWebviewContext // TODO web 实现createWebviewContext
this.webviewContext = uni.createWebviewContext('web-view', this) this.webviewContext = uni.createWebviewContext('web-view',this)
this.webviewElement = uni.getElementById('web-view') as UniWebViewElement //推荐使用element,功能更丰富
// console.log('url: ',this.webviewElement?.getAttribute("src"));
// this.webviewElement?.setAttribute("src","https://ext.dcloud.net.cn/")
// #endif // #endif
}, },
methods: { methods: {
...@@ -77,6 +81,7 @@ ...@@ -77,6 +81,7 @@
}, },
reload() { reload() {
this.webviewContext?.reload(); this.webviewContext?.reload();
// this.webviewElement?.reload();
}, },
stop() { stop() {
this.webviewContext?.stop(); this.webviewContext?.stop();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册