提交 87b9bba2 编写于 作者: DCloud-yinjiacheng's avatar DCloud-yinjiacheng

更新video示例

上级 5eaa72cf
......@@ -12,7 +12,6 @@
@fullscreenclick="onFullScreenClick" @controlstoggle="onControlsToggle" @fullscreenchange="onFullScreenChange">
</video>
<scroll-view class="uni-padding-wrap uni-common-mt uni-flex-item">
<input class="input" placeholder="输入视频地址播放" @confirm="onSrcInputConfirm"></input>
<view class="uni-btn-v">
<navigator url="/pages/component/video/video-format">
<button type="primary" @click="pause">视频格式示例</button>
......@@ -28,10 +27,12 @@
<button type="primary" @click="pause">暂停</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="seek(pos)">跳转到指定位置</button>
<input class="input" placeholder="输入要跳转的位置,单位s" type="number" @input="onSeekInput"></input>
<button type="primary" @click="seek">跳转到指定位置</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="requestFullScreen(requestFullScreenOptions)">进入全屏</button>
<enum-data title="选择进入全屏时的视频方向" :items="directionItemTypes" @change="onRequestFullScreenDirectionChange"></enum-data>
<button type="primary" @click="requestFullScreen">进入全屏</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="exitFullScreen">退出全屏</button>
......@@ -40,103 +41,53 @@
<button type="primary" @click="stop">停止</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="sendDanmu(danmu)">发送弹幕</button>
<input class="input" placeholder="输入弹幕" value="{ 'text': '要显示的文本', 'color': '#FF0000' }" type="string" @input="onSendDanmuInput"></input>
<button type="primary" :disabled="!enableDanmu" @click="sendDanmu">发送弹幕</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="playbackRate(rate)">设置倍速</button>
<enum-data title="选择倍速" :items="rateItemTypes" @change="onPlaybackRateChange"></enum-data>
<button type="primary" @click="playbackRate">设置倍速</button>
</view>
<view class="uni-title">
<text class="uni-title-text">属性示例</text>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setSrc(_src)">设置播放资源</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setAutoplay()">设置是否自动播放(未播放时设置有效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setLoop()">设置是否循环播放(本次播放完成后生效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setMuted()">设置是否静音播放</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setInitialTime(_initialTime)">设置初始播放位置(本次播放完成后生效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setDuration(_duration)">设置视频时长(未播放时设置有效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setControls()">设置是否显示默认播放控件</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setDanmuBtn()">设置是否显示弹幕按钮</button>
</view>
<input class="input margin-10" type="string" placeholder="设置播放资源" @confirm="onSrcComfirm"></input>
<input class="input margin-10" type="number" placeholder="设置初始播放位置(播放前设置有效)" @confirm="onInitialTimeComfirm"></input>
<input class="input margin-10" type="number" placeholder="设置视频时长(播放前设置有效)" @confirm="onDurationComfirm"></input>
<input class="input margin-10" type="string" placeholder="设置视频封面" @confirm="onPosterComfirm"></input>
<input class="input margin-10" type="string" placeholder="设置视频标题(仅限非 Web 平台)" @confirm="onTitleComfirm"></input>
<input class="input margin-10" type="string" placeholder="设置header(json格式)" @confirm="onHeaderComfirm"></input>
<boolean-data title="设置是否展示弹幕(播放前设置有效)" :defaultValue="enableDanmu" @change="onEnableDanmuChange"></boolean-data>
<boolean-data title="设置是否自动播放(播放前设置有效)" :defaultValue="autoplay" @change="onAutoplayChange"></boolean-data>
<boolean-data title="设置是否循环播放(播放完成后生效)" :defaultValue="loop" @change="onLoopChange"></boolean-data>
<boolean-data title="设置是否静音播放" :defaultValue="muted" @change="onMutedChange"></boolean-data>
<boolean-data title="设置是否显示默认播放控件" :defaultValue="controls" @change="onControlsChange"></boolean-data>
<boolean-data title="设置是否显示弹幕按钮" :defaultValue="danmuBtn" @change="onDanmuBtnChange"></boolean-data>
<boolean-data title="设置是否显示进度条" :defaultValue="showProgress" @change="onShowProgressChange"></boolean-data>
<boolean-data title="设置是否显示全屏按钮" :defaultValue="showFullscreenBtn" @change="onShowFullscreenBtnChange"></boolean-data>
<boolean-data title="设置是否显示视频底部控制栏的播放按钮" :defaultValue="showPlayBtn" @change="onShowPlayBtnChange"></boolean-data>
<boolean-data title="设置是否显示静音按钮(仅限非 Web 平台)" :defaultValue="showMuteBtn" @change="onShowMuteBtnChange"></boolean-data>
<enum-data title="设置全屏时视频的方向" :items="directionItemTypes" @change="onDirectionChange"></enum-data>
<boolean-data title="设置是否显示视频中间的播放按钮" :defaultValue="showCenterPlayBtn" @change="onShowCenterPlayBtnChange"></boolean-data>
<boolean-data title="设置是否显示loading控件" :defaultValue="showLoading" @change="onShowLoadingChange"></boolean-data>
<boolean-data title="设置是否开启控制进度的手势" :defaultValue="enableProgressGesture" @change="onEnableProgressGestureChange"></boolean-data>
<boolean-data title="设置是否开启播放手势(仅限非 Web 平台)" :defaultValue="enablePlayGesture" @change="onEnablePlayGestureChange"></boolean-data>
<!-- #ifndef WEB -->
<view class="uni-btn-v">
<button type="primary" @click="setPageGesture()">非全屏模式下,设置是否开启亮度与音量调节手势</button>
</view>
<boolean-data title="非全屏模式下,设置是否开启亮度与音量调节手势" :defaultValue="pageGesture" @change="onPageGestureChange"></boolean-data>
<!-- #endif -->
<view class="uni-btn-v">
<button type="primary" @click="setDirection(_direction)">设置全屏时视频的方向</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowProgress()">设置是否显示进度条</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowFullscreenBtn()">设置是否显示全屏按钮</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowPlayBtn()">设置是否显示视频底部控制栏的播放按钮</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowCenterPlayBtn()">设置是否显示视频中间的播放按钮</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowLoading()">设置是否显示loading控件</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setEnableProgressGesture()">设置是否开启控制进度的手势</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setObjectFit(_objectFit)">设置视频大小与video容器大小不一致时,视频的表现形式</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setPoster(_poster)">设置视频封面</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setShowMuteBtn()">设置是否显示静音按钮(仅限非 Web 平台)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setTitle(_title)">设置视频标题(仅限非 Web 平台)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setEnablePlayGesture()">设置是否开启播放手势(仅限非 Web 平台)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setVslideGesture()">非全屏模式下,设置是否开启亮度与音量调节手势(仅限非 Web 平台)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setVslideGestureInFullscreen()">全屏模式下,设置是否开启亮度与音量调节手势(仅限非 Web 平台)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setCodec(_codec)">设置解码器(仅 App 平台,未播放时设置有效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setHttpCache()">设置是否对http、https视频源开启本地缓存(仅 App 平台,未播放时设置有效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setPlayStrategy(_playStrategy)">设置播放策略(仅 App 平台,未播放时设置有效)</button>
</view>
<view class="uni-btn-v">
<button type="primary" @click="setHeader(_header)">设置header</button>
</view>
<boolean-data title="非全屏模式下,设置是否开启亮度与音量调节手势(仅限非 Web 平台)" :defaultValue="vslideGesture" @change="onVslideGestureChange"></boolean-data>
<boolean-data title="全屏模式下,设置是否开启亮度与音量调节手势(仅限非 Web 平台)" :defaultValue="vslideGestureInFullscreen" @change="onVslideGestureInFullscreenChange"></boolean-data>
<boolean-data title="设置是否对http、https视频源开启本地缓存(仅 App 平台,播放前设置有效)" :defaultValue="httpCache" @change="onHttpCacheChange"></boolean-data>
<enum-data title="设置视频大小与video容器大小不一致时,视频的表现形式" :items="objectFitItemTypes" @change="onObjectFitChange"></enum-data>
<enum-data title="设置解码器(仅 App 平台,播放前设置有效)" :items="codecItemTypes" @change="onCodecChange"></enum-data>
<enum-data title="设置播放策略(仅 App 平台,播放前设置有效)" :items="playStrategyItemTypes" @change="onPlayStrategyChange"></enum-data>
</scroll-view>
<video v-if="autoTest" :src="localSrc" @error="onError"></video>
</view>
</template>
<script>
import { ItemType } from '@/components/enum-data/enum-data';
export default {
onReady() {
this.videoContext = uni.createVideoContext('video', this);
......@@ -146,14 +97,11 @@
videoContext: null as VideoContext | null,
// 属性
src: "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4",
_src: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app-video-courses.mp4",
autoplay: false,
loop: false,
muted: false,
initialTime: 0,
_initialTime: 6,
duration: 0,
_duration: 60,
controls: true,
danmuList: [{
text: '要显示的文本',
......@@ -180,10 +128,8 @@
enableDanmu: true,
pageGesture: false,
direction: -1,
_direction: 0,
requestFullScreenOptions: {
direction: -90
} as RequestFullScreenOptions,
directionItemTypes: [{ "value": 0, "name": "0(正常竖向)" }, { "value": 1, "name": "90(屏幕逆时针90度)" }, { "value": 2, "name": "-90(屏幕顺时针90度)" }] as ItemType[],
directionItems: [0, 90, -90],
showProgress: true,
showFullscreenBtn: true,
showPlayBtn: true,
......@@ -191,37 +137,38 @@
showLoading: true,
enableProgressGesture: true,
objectFit: "contain",
_objectFit: "fill",
objectFitItemTypes: [{ "value": 0, "name": "contain(包含)" }, { "value": 1, "name": "fill(填充)" }, { "value": 2, "name": "cover(覆盖)" }] as ItemType[],
objectFitItems: ["contain", "fill", "cover"],
poster: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-android.png",
_poster: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-ios.png",
showMuteBtn: false,
title: "video-component",
_title: "video-component video-component",
enablePlayGesture: false,
vslideGesture: false,
vslideGestureInFullscreen: true,
codec: "hardware",
_codec: "software",
codecItemTypes: [{ "value": 0, "name": "hardware(硬解码)" }, { "value": 1, "name": "software(软解码)" }] as ItemType[],
codecItems: ["hardware", "software"],
httpCache: true,
playStrategy: 0,
_playStrategy: 2,
playStrategyItemTypes: [{ "value": 0, "name": "0(普通模式)" }, { "value": 1, "name": "1(平滑播放模式)" }, { "value": 1, "name": "2(M3U8优化模式)" }] as ItemType[],
playStrategyItems: [0, 1, 2],
header: {
'User-Agent': 'User-Agent test',
'header': 'header test',
'cookie': 'cookie test'
} as UTSJSONObject,
_header: {
'User-Agent': 'User-Agent test2',
'header': 'header test2',
'cookie': 'cookie test2'
} as UTSJSONObject,
// API
pos: 10,
rate: 1.5,
pos: 0,
requestFullScreenOptions: {
direction: -90
} as RequestFullScreenOptions,
danmu: {
text: '要显示的文本',
color: '#FF0000'
} as Danmu,
rate: 1,
rateItemTypes: [{ "value": 0, "name": "0.5" }, { "value": 1, "name": "0.8" }, { "value": 2, "name": "1.0" }, { "value": 3, "name": "1.25" }, { "value": 4, "name": "1.5" }] as ItemType[],
rateItems: [0.5, 0.8, 1.0, 1.25, 1.5],
// 自动化测试
autoTest: false,
isPlaying: false,
......@@ -243,13 +190,16 @@
(uni.getElementById("video") as UniVideoElement).pause(); //as写法测试。注意id不对时as会崩溃
// this.videoContext?.pause();
},
seek: function (pos : number) {
console.log("seek -> " + pos);
this.videoContext?.seek(pos);
seek: function () {
console.log("seek -> " + this.pos);
this.videoContext?.seek(this.pos);
},
requestFullScreen: function (options : RequestFullScreenOptions | null) {
console.log("requestFullScreen -> " + options);
this.videoContext?.requestFullScreen(options);
onSeekInput: function (event : UniInputEvent) {
this.pos = parseInt(event.detail.value);
},
requestFullScreen: function () {
console.log("requestFullScreen -> " + this.requestFullScreenOptions);
this.videoContext?.requestFullScreen(this.requestFullScreenOptions);
},
exitFullScreen: function () {
console.log("exitFullScreen");
......@@ -260,121 +210,151 @@
uni.getElementById<UniVideoElement>("video")?.stop(); //泛型写法测试
// this.videoContext?.stop();
},
sendDanmu: function (danmu : Danmu) {
console.log("sendDanmu -> " + danmu);
this.videoContext?.sendDanmu(danmu);
sendDanmu: function () {
console.log("sendDanmu -> " + this.danmu);
this.videoContext?.sendDanmu(this.danmu);
},
onSendDanmuInput: function (event : UniInputEvent) {
let json = JSON.parse<Danmu>(event.detail.value)
if (json == null) return;
this.danmu = json as Danmu;
},
playbackRate: function (rate : number) {
console.log("playbackRate -> " + rate);
this.videoContext?.playbackRate(rate);
playbackRate: function () {
console.log("playbackRate -> " + this.rate);
this.videoContext?.playbackRate(this.rate);
},
onPlaybackRateChange: function (value : number) {
this.rate = this.rateItems[value];
},
// 属性
setSrc: function (src : string) {
this.src = src;
onSrcComfirm: function (event : UniInputConfirmEvent) {
let value = event.detail.value;
if (value == '') return;
this.src = value;
console.log("src -> " + this.src)
},
setAutoplay: function () {
this.autoplay = !this.autoplay;
onAutoplayChange: function (value : boolean) {
this.autoplay = value;
console.log("autoplay -> " + this.autoplay)
},
setLoop: function () {
this.loop = !this.loop;
onLoopChange: function (value : boolean) {
this.loop = value;
console.log("loop -> " + this.loop)
},
setMuted: function () {
this.muted = !this.muted;
onMutedChange: function (value : boolean) {
this.muted = value;
console.log("muted -> " + this.muted)
},
setInitialTime: function (initialTime : number) {
this.initialTime = initialTime;
onInitialTimeComfirm: function (event : UniInputConfirmEvent) {
let value = parseInt(event.detail.value)
if (value == NaN) value = 0;
this.initialTime = value;
console.log("initialTime -> " + this.initialTime)
},
setDuration: function (duration : number) {
this.duration = duration;
onDurationComfirm: function (event : UniInputConfirmEvent) {
let value = parseInt(event.detail.value)
if (value == NaN) value = 0;
this.duration = value;
console.log("duration -> " + this.duration)
},
setControls: function () {
this.controls = !this.controls;
onControlsChange: function (value : boolean) {
this.controls = value;
console.log("controls -> " + this.controls)
},
setDanmuBtn: function () {
this.danmuBtn = !this.danmuBtn;
onEnableDanmuChange: function (value : boolean) {
this.enableDanmu = value;
console.log("enableDanmu -> " + this.enableDanmu)
},
onDanmuBtnChange: function (value : boolean) {
this.danmuBtn = value;
console.log("danmuBtn -> " + this.danmuBtn)
},
setPageGesture: function () {
this.pageGesture = !this.pageGesture;
onPageGestureChange: function (value : boolean) {
this.pageGesture = value;
console.log("pageGesture -> " + this.pageGesture)
},
setDirection: function (direction : number) {
this.direction = direction;
onRequestFullScreenDirectionChange: function (value : number) {
let direction = this.directionItems[value];
this.requestFullScreenOptions = {
direction
} as RequestFullScreenOptions;
},
onDirectionChange: function (value : number) {
this.direction = this.directionItems[value];
console.log("direction -> " + this.direction)
},
setShowProgress: function () {
this.showProgress = !this.showProgress;
onShowProgressChange: function (value : boolean) {
this.showProgress = value;
console.log("showProgress -> " + this.showProgress)
},
setShowFullscreenBtn: function () {
this.showFullscreenBtn = !this.showFullscreenBtn;
onShowFullscreenBtnChange: function (value : boolean) {
this.showFullscreenBtn = value;
console.log("showFullscreenBtn -> " + this.showFullscreenBtn)
},
setShowPlayBtn: function () {
this.showPlayBtn = !this.showPlayBtn;
onShowPlayBtnChange: function (value : boolean) {
this.showPlayBtn = value;
console.log("showPlayBtn -> " + this.showPlayBtn)
},
setShowCenterPlayBtn: function () {
this.showCenterPlayBtn = !this.showCenterPlayBtn;
onShowCenterPlayBtnChange: function (value : boolean) {
this.showCenterPlayBtn = value;
console.log("showCenterPlayBtn -> " + this.showCenterPlayBtn)
},
setShowLoading: function () {
this.showLoading = !this.showLoading;
onShowLoadingChange: function (value : boolean) {
this.showLoading = value;
console.log("showLoading -> " + this.showLoading)
},
setEnableProgressGesture: function () {
this.enableProgressGesture = !this.enableProgressGesture;
onEnableProgressGestureChange: function (value : boolean) {
this.enableProgressGesture = value;
console.log("enableProgressGesture -> " + this.enableProgressGesture)
},
setObjectFit: function (objectFit : string) {
this.objectFit = objectFit;
onObjectFitChange: function (value : number) {
this.objectFit = this.objectFitItems[value];
console.log("objectFit -> " + this.objectFit)
},
setPoster: function (poster : string) {
this.poster = poster;
onPosterComfirm: function (event : UniInputConfirmEvent) {
let value = event.detail.value;
if (value == '') return;
this.poster = value;
console.log("poster -> " + this.poster)
},
setShowMuteBtn: function () {
this.showMuteBtn = !this.showMuteBtn;
onShowMuteBtnChange: function (value : boolean) {
this.showMuteBtn = value;
console.log("showMuteBtn -> " + this.showMuteBtn)
},
setTitle: function (title : string) {
this.title = title;
onTitleComfirm: function (event : UniInputConfirmEvent) {
let value = event.detail.value;
if (value == '') return;
this.title = value;
console.log("title -> " + this.title)
},
setEnablePlayGesture: function () {
this.enablePlayGesture = !this.enablePlayGesture;
onEnablePlayGestureChange: function (value : boolean) {
this.enablePlayGesture = value;
console.log("enablePlayGesture -> " + this.enablePlayGesture)
},
setVslideGesture: function () {
this.vslideGesture = !this.vslideGesture;
onVslideGestureChange: function (value : boolean) {
this.vslideGesture = value;
console.log("vslideGesture -> " + this.vslideGesture)
},
setVslideGestureInFullscreen: function () {
this.vslideGestureInFullscreen = !this.vslideGestureInFullscreen;
onVslideGestureInFullscreenChange: function (value : boolean) {
this.vslideGestureInFullscreen = value;
console.log("vslideGestureInFullscreen -> " + this.vslideGestureInFullscreen)
},
setCodec: function (codec : string) {
this.codec = codec;
onCodecChange: function (value : number) {
this.codec = this.codecItems[value];
console.log("codec -> " + this.codec)
},
setHttpCache: function () {
this.httpCache = !this.httpCache;
onHttpCacheChange: function (value : boolean) {
this.httpCache = value;
console.log("httpCache -> " + this.httpCache)
},
setPlayStrategy: function (playStrategy : number) {
this.playStrategy = playStrategy;
onPlayStrategyChange: function (value : number) {
this.playStrategy = this.playStrategyItems[value];
console.log("playStrategy -> " + this.playStrategy)
},
setHeader: function (header : UTSJSONObject) {
this.header = header;
onHeaderComfirm: function (event : UniInputConfirmEvent) {
let json = JSON.parse(event.detail.value)
if (json == null) return;
this.header = json as UTSJSONObject;
console.log("header -> " + JSON.stringify(this.header))
},
// 事件
......@@ -413,9 +393,6 @@
onControlsToggle: function (res : UniVideoControlsToggleEvent) {
console.log(res.type + " -> " + JSON.stringify(res.detail));
},
onSrcInputConfirm(event : UniInputConfirmEvent) {
this.src = event.detail.value;
},
// 自动化测试
downloadSource() {
uni.downloadFile({
......@@ -442,6 +419,10 @@
.input {
height: 40px;
background: #FFF;
margin: 5px 0;
padding: 8px 13px;
}
.margin-10 {
margin: 10px;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册