Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
b6a669a0
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5998
Star
91
Fork
163
代码
文件
提交
分支
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看板
提交
b6a669a0
编写于
11月 15, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[audio]添加音频路径env示例与多音频同时播放示例
上级
c0778ac1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
134 addition
and
5 deletion
+134
-5
pages.json
pages.json
+6
-0
pages/API/create-inner-audio-context/create-inner-audio-context.uvue
...reate-inner-audio-context/create-inner-audio-context.uvue
+3
-0
pages/API/create-inner-audio-context/inner-audio-mult.uvue
pages/API/create-inner-audio-context/inner-audio-mult.uvue
+92
-0
pages/API/create-inner-audio-context/inner-audio-path.uvue
pages/API/create-inner-audio-context/inner-audio-path.uvue
+33
-5
未找到文件。
pages.json
浏览文件 @
b6a669a0
...
@@ -1125,6 +1125,12 @@
...
@@ -1125,6 +1125,12 @@
"navigationBarTitleText"
:
"inner-audio-path"
"navigationBarTitleText"
:
"inner-audio-path"
}
}
},
},
{
"path"
:
"pages/API/create-inner-audio-context/inner-audio-mult"
,
"style"
:
{
"navigationBarTitleText"
:
"inner-audio-mult"
}
},
//
#endif
//
#endif
//
#ifdef
WEB
||
MP
//
#ifdef
WEB
||
MP
{
{
...
...
pages/API/create-inner-audio-context/create-inner-audio-context.uvue
浏览文件 @
b6a669a0
...
@@ -63,6 +63,9 @@
...
@@ -63,6 +63,9 @@
<navigator url="/pages/API/create-inner-audio-context/inner-audio-path" class="uni-btn uni-common-mb">
<navigator url="/pages/API/create-inner-audio-context/inner-audio-path" class="uni-btn uni-common-mb">
<button type="primary" @click="pause">音频路径示例</button>
<button type="primary" @click="pause">音频路径示例</button>
</navigator>
</navigator>
<navigator url="/pages/API/create-inner-audio-context/inner-audio-mult" class="uni-btn uni-common-mb">
<button type="primary" @click="pause">同时播放</button>
</navigator>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
</scroll-view>
...
...
pages/API/create-inner-audio-context/inner-audio-mult.uvue
0 → 100644
浏览文件 @
b6a669a0
<template>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">
<text class="uni-title-text">多音频同时播放</text>
</view>
<button type="primary" @tap="play1()"> 播放/停止(进度:{{currentTime1}})</button>
<button type="primary" @tap="play2()"> 播放/停止(进度:{{currentTime2}})</button>
</view>
</template>
<script>
type AudioPath = {
description : string
src : string
}
export default {
data() {
return {
title: "多音频同时播放",
_audioContext1: null as InnerAudioContext | null,
src: 'https://web-ext-storage.dcloud.net.cn/uni-app/ForElise.mp3',
_audioContext2: null as InnerAudioContext | null,
playing1: false,
playing2: false,
currentTime1: 0,
currentTime2: 0,
}
},
onReady() {
this._audioContext1 = uni.createInnerAudioContext();
this._audioContext1!.src = this.src
this._audioContext1!.onTimeUpdate((res) => {
this.currentTime1 = this._audioContext1!.currentTime;
})
this._audioContext2 = uni.createInnerAudioContext();
this._audioContext2!.src = this.src
this._audioContext2!.onTimeUpdate((res) => {
this.currentTime2 = this._audioContext2!.currentTime;
})
},
onUnload() {
if (this._audioContext1 != null) {
this._audioContext1!.stop()
this._audioContext1!.destroy()
}
if (this._audioContext2 != null) {
this._audioContext2!.stop()
this._audioContext2!.destroy()
}
},
methods: {
play1() {
if (this._audioContext1 != null) {
this.currentTime1=0
if (this.playing1) {
this._audioContext1!.stop()
} else {
this._audioContext1!.play()
}
}
this.playing1 = !this.playing1
},
play2() {
if (this._audioContext2 != null) {
this.currentTime2=0
if (this.playing2) {
this._audioContext2!.stop()
} else {
this._audioContext2!.play()
}
}
this.playing2 = !this.playing2
}
}
}
</script>
<style>
.formats {
align-items: center;
}
.icon-play {
width: 60px;
height: 60px;
margin: 10px;
}
</style>
\ No newline at end of file
pages/API/create-inner-audio-context/inner-audio-path.uvue
浏览文件 @
b6a669a0
...
@@ -22,7 +22,9 @@
...
@@ -22,7 +22,9 @@
return {
return {
title: 'audio-path',
title: 'audio-path',
playIndex: 0,
playIndex: 0,
isPlaying: false,
isPlaying: false,
nativePath:uni.env.CACHE_PATH+'uni-audio/test/test.mp3' as string,
sdcardPath :'sdcard/uni-audio/test.mp3',
_audioContext: null as InnerAudioContext | null,
_audioContext: null as InnerAudioContext | null,
supportPaths: [
supportPaths: [
{
{
...
@@ -32,7 +34,11 @@
...
@@ -32,7 +34,11 @@
{
{
description: '本地路径:../static/',
description: '本地路径:../static/',
src: '../../../static/test-audio/ForElise.mp3'
src: '../../../static/test-audio/ForElise.mp3'
},
},
{
description: '本地路径:env方式',
src: 'env'
},
{
{
description: '网络路径',
description: '网络路径',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3'
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3'
...
@@ -60,8 +66,26 @@
...
@@ -60,8 +66,26 @@
this._audioContext!.onError((err) => {
this._audioContext!.onError((err) => {
this.isPlaying = false;
this.isPlaying = false;
console.log('err', err);
console.log('err', err);
});
});
},
const fileManager = uni.getFileSystemManager()
try {
fileManager.rmdirSync(uni.env.CACHE_PATH+'uni-audio/test',true)
} catch (e) {
}
try {
fileManager.mkdirSync(uni.env.CACHE_PATH+'uni-audio/test',true)
} catch (e) {
}
try{
fileManager.copyFileSync(
'/static/test-audio/ForElise.mp3',
this.nativePath)
} catch(e){
}
},
onUnload() {
onUnload() {
if (this._audioContext != null) {
if (this._audioContext != null) {
this.pause();
this.pause();
...
@@ -78,7 +102,11 @@
...
@@ -78,7 +102,11 @@
if (this.isPlaying && this.playIndex == index) {
if (this.isPlaying && this.playIndex == index) {
this.pause();
this.pause();
return;
return;
}
}
if(audioUrl == 'env'){
audioUrl=this.nativePath
}
this.playIndex = index
this.playIndex = index
this._audioContext!.src = audioUrl;
this._audioContext!.src = audioUrl;
this._audioContext!.play();
this._audioContext!.play();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录