Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
f0cc4ff8
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6005
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f0cc4ff8
编写于
10月 30, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[audio]添加音频示例
上级
615b79f6
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
162 addition
and
148 deletion
+162
-148
pages/API/create-inner-audio-context/create-inner-audio-context.uvue
...reate-inner-audio-context/create-inner-audio-context.uvue
+14
-8
pages/API/create-inner-audio-context/inner-audio-format.uvue
pages/API/create-inner-audio-context/inner-audio-format.uvue
+145
-137
pages/API/create-inner-audio-context/inner-audio-path.uvue
pages/API/create-inner-audio-context/inner-audio-path.uvue
+3
-3
未找到文件。
pages/API/create-inner-audio-context/create-inner-audio-context.uvue
浏览文件 @
f0cc4ff8
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
<button :disabled="isPlaying" type="primary" @click="play" class="uni-btn">播放</button>
<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" type="primary" @click="pause" class="uni-btn">暂停</button>
<button :disabled="!isPlaying && !isPaused" type="primary" @click="stop" 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="onchange
Value
(20)" class="uni-btn">跳转到指定位置20</button>
<view class="uni-title">
<view class="uni-title">
<text class="uni-title-text">格式/路径示例</text>
<text class="uni-title-text">格式/路径示例</text>
...
@@ -87,24 +87,30 @@
...
@@ -87,24 +87,30 @@
this.isCanplay = true;
this.isCanplay = true;
// 当音频可以播放时,获取缓冲信息
// 当音频可以播放时,获取缓冲信息
this.buffered = this._audioContext!.buffered;
this.buffered = this._audioContext!.buffered;
this.duration = this._audioContext!.duration
|| 0;
this.duration = this._audioContext!.duration
});
});
},
},
onchanging() {
onchanging() {
this._isChanging = true;
this._isChanging = true;
},
},
onchange(e) {
onchange(e
: UniSliderChangeEvent
) {
console.log(e, 'e');
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._audioContext!.seek(pos);
this.onSeeking()
this.onSeeking()
this.onSeeked()
this.onSeeked()
this._isChanging = false;
this._isChanging = false;
},
},
startTimeInput(e : InputEvent) {
startTimeInput(e : InputEvent) {
let startTimeValue =
Number
(e.detail.value)
let startTimeValue =
parseInt
(e.detail.value)
this._audioContext!.startTime = startTimeValue;
this._audioContext!.startTime = startTimeValue;
this.onchange(startTimeValue)
this.onchange
Value
(startTimeValue)
},
},
setAutoplay() {
setAutoplay() {
this._audioContext!.autoplay = !this._audioContext!.autoplay;
this._audioContext!.autoplay = !this._audioContext!.autoplay;
...
@@ -125,7 +131,7 @@
...
@@ -125,7 +131,7 @@
this._audioContext!.play();
this._audioContext!.play();
this.isPlayEnd = false;
this.isPlayEnd = false;
if (this._audioContext!.startTime > 0) {
if (this._audioContext!.startTime > 0) {
this.onchange(this._audioContext!.startTime)
this.onchange
Value
(this._audioContext!.startTime)
}
}
this._audioContext!.onPlay(() => {
this._audioContext!.onPlay(() => {
this.isPaused = false;
this.isPaused = false;
...
@@ -158,7 +164,7 @@
...
@@ -158,7 +164,7 @@
this._audioContext!.onTimeUpdate(() => {
this._audioContext!.onTimeUpdate(() => {
// console.log('onTimeUpdate:音频播放进度更新事件,currentTime',this._audioContext!.currentTime);
// console.log('onTimeUpdate:音频播放进度更新事件,currentTime',this._audioContext!.currentTime);
if (this._isChanging === true) { return; }
if (this._isChanging === true) { return; }
this.currentTime = this._audioContext!.currentTime
||
0;
this.currentTime = this._audioContext!.currentTime
??
0;
console.log('currentTime', this.currentTime);
console.log('currentTime', this.currentTime);
if (this.currentTime > this.buffered) {
if (this.currentTime > this.buffered) {
console.log('缓冲不足');
console.log('缓冲不足');
...
...
pages/API/create-inner-audio-context/inner-audio-format.uvue
浏览文件 @
f0cc4ff8
<template>
<template>
<page-head :title="title"></page-head>
<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-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>
</view>
</view>
<view class="formats" v-for="(item,index) in supportFormats" :key="index">
<view class="formats" v-for="(item,index) in supportFormats" :key="index">
<text class="uni-subtitle-text">{{item.format}}</text>
<text class="uni-subtitle-text">{{item.format}}</text>
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
...
@@ -18,7 +22,11 @@
...
@@ -18,7 +22,11 @@
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
<image class="icon-play" :src="(isPlaying && playIndex==index)?'/static/pause.png':'/static/play.png'"
@click="play(item.src,index)"></image>
@click="play(item.src,index)"></image>
</view>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
</template>
<script>
<script>
...
@@ -98,7 +106,7 @@
...
@@ -98,7 +106,7 @@
this._audioContext!.pause();
this._audioContext!.pause();
this.isPlaying = false;
this.isPlaying = false;
},
},
play(audioUrl, index) {
play(audioUrl : string, index : number) {
// console.log(index,audioUrl);
// console.log(index,audioUrl);
if (this.isPlaying && this.playIndex == index) {
if (this.isPlaying && this.playIndex == index) {
this.pause();
this.pause();
...
...
pages/API/create-inner-audio-context/inner-audio-path.uvue
浏览文件 @
f0cc4ff8
...
@@ -62,7 +62,7 @@
...
@@ -62,7 +62,7 @@
this._audioContext!.pause();
this._audioContext!.pause();
this.isPlaying = false;
this.isPlaying = false;
},
},
play(audioUrl
, index
) {
play(audioUrl
:string, index:number
) {
// console.log(index,audioUrl);
// console.log(index,audioUrl);
if (this.isPlaying && this.playIndex == index) {
if (this.isPlaying && this.playIndex == index) {
this.pause();
this.pause();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录