提交 f0cc4ff8 编写于 作者: M mahaifeng

[audio]添加音频示例

上级 615b79f6
......@@ -27,7 +27,7 @@
<button :disabled="isPlaying" type="primary" @click="play" class="uni-btn">播放</button>
<button :disabled="!isPlaying" type="primary" @click="pause" class="uni-btn">暂停</button>
<button :disabled="!isPlaying && !isPaused" type="primary" @click="stop" class="uni-btn">停止</button>
<button type="primary" @click="onchange(20)" class="uni-btn">跳转到指定位置20</button>
<button type="primary" @click="onchangeValue(20)" class="uni-btn">跳转到指定位置20</button>
<view class="uni-title">
<text class="uni-title-text">格式/路径示例</text>
......@@ -87,24 +87,30 @@
this.isCanplay = true;
// 当音频可以播放时,获取缓冲信息
this.buffered = this._audioContext!.buffered;
this.duration = this._audioContext!.duration || 0;
this.duration = this._audioContext!.duration
});
},
onchanging() {
this._isChanging = true;
},
onchange(e) {
onchange(e : UniSliderChangeEvent) {
console.log(e, 'e');
let pos = typeof e === "number" ? e : e.detail.value;
let pos = e.detail.value;
this._audioContext!.seek(pos);
this.onSeeking()
this.onSeeked()
this._isChanging = false;
},
onchangeValue(pos:number) {
this._audioContext!.seek(pos);
this.onSeeking()
this.onSeeked()
this._isChanging = false;
},
startTimeInput(e : InputEvent) {
let startTimeValue = Number(e.detail.value)
let startTimeValue = parseInt(e.detail.value)
this._audioContext!.startTime = startTimeValue;
this.onchange(startTimeValue)
this.onchangeValue(startTimeValue)
},
setAutoplay() {
this._audioContext!.autoplay = !this._audioContext!.autoplay;
......@@ -125,7 +131,7 @@
this._audioContext!.play();
this.isPlayEnd = false;
if (this._audioContext!.startTime > 0) {
this.onchange(this._audioContext!.startTime)
this.onchangeValue(this._audioContext!.startTime)
}
this._audioContext!.onPlay(() => {
this.isPaused = false;
......@@ -158,7 +164,7 @@
this._audioContext!.onTimeUpdate(() => {
// console.log('onTimeUpdate:音频播放进度更新事件,currentTime',this._audioContext!.currentTime);
if (this._isChanging === true) { return; }
this.currentTime = this._audioContext!.currentTime || 0;
this.currentTime = this._audioContext!.currentTime ?? 0;
console.log('currentTime', this.currentTime);
if (this.currentTime > this.buffered) {
console.log('缓冲不足');
......
<template>
<page-head :title="title"></page-head>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">支持的音频格式示例</text>
</view>
<view class="formats" v-for="(item,index) in supportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
......@@ -18,7 +22,11 @@
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
@click="play(item.src,index)"></image>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
......@@ -98,7 +106,7 @@
this._audioContext!.pause();
this.isPlaying = false;
},
play(audioUrl, index) {
play(audioUrl : string, index : number) {
// console.log(index,audioUrl);
if (this.isPlaying && this.playIndex == index) {
this.pause();
......
......@@ -62,7 +62,7 @@
this._audioContext!.pause();
this.isPlaying = false;
},
play(audioUrl, index) {
play(audioUrl:string, index:number) {
// console.log(index,audioUrl);
if (this.isPlaying && this.playIndex == index) {
this.pause();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册