提交 f41eb0c7 编写于 作者: W wanganxp

web端屏蔽音频播放和uni-icon字体不支持的部分

上级 eb13c34c
......@@ -26,7 +26,7 @@
<boolean-data :defaultValue="false" title="是否自动开始播放" @change="setAutoplay"></boolean-data>
<boolean-data :defaultValue="false" title="是否循环播放" @change="setLoop"></boolean-data>
<text class="uni-subtitle-text uni-title"
style="padding-left: 10px;padding-top: 10px;padding-right: 10px;">播放倍率</text>
style="padding-left: 10px;padding-top: 10px;padding-right: 10px;">播放倍率(Web不支持)</text>
<radio-group class="uni-flex uni-row radio-group" @change="playbackRateChange"
style="flex-wrap: wrap;padding: 10px;">
<radio value="0.5" style="margin-right: 3px">0.5
......@@ -41,30 +41,30 @@
<view class="uni-title">
<text class="uni-title-text">方法示例</text>
</View>
<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="stop" class="uni-btn">停止</button>
<button type="primary" @click="onchangeValue(20)" class="uni-btn">跳转到指定位置20</button>
<button type="primary" @click="onTimeUpdate" class="uni-btn">onTimeUpdate</button>
<button type="primary" @click="offTimeUpdate" class="uni-btn">offTimeUpdate</button>
<button type="primary" @click="onWaiting" class="uni-btn">onWaiting</button>
<button type="primary" @click="offWaiting" class="uni-btn">offWaiting</button>
<button :disabled="isPlaying" @click="play" class="uni-btn">播放</button>
<button :disabled="!isPlaying" @click="pause" class="uni-btn">暂停</button>
<button :disabled="!isPlaying" @click="stop" class="uni-btn">停止</button>
<button @click="onchangeValue(20)" class="uni-btn">跳转到指定位置20</button>
<button @click="onTimeUpdate" class="uni-btn">onTimeUpdate</button>
<button @click="offTimeUpdate" class="uni-btn">offTimeUpdate</button>
<button @click="onWaiting" class="uni-btn">onWaiting</button>
<button @click="offWaiting" class="uni-btn">offWaiting</button>
<text style="color: red;font-size: 15px;margin-top: 10px;">tip:销毁后请重新进入此界面再播放</text>
<button type="primary" @click="destory" class="uni-btn">销毁</button>
<button @click="destory" class="uni-btn">销毁</button>
<view class="uni-title">
<text class="uni-title-text">格式/路径示例</text>
</View>
<navigator url="/pages/API/create-inner-audio-context/inner-audio-format" class="uni-btn">
<button type="primary" @click="pause">音频格式示例</button>
<button @click="pause">音频格式示例</button>
</navigator>
<navigator url="/pages/API/create-inner-audio-context/inner-audio-path" class="uni-btn">
<button type="primary" @click="pause">音频路径示例</button>
<button @click="pause">音频路径示例</button>
</navigator>
<navigator url="/pages/API/create-inner-audio-context/inner-audio-mult" class="uni-btn">
<button type="primary" @click="pause">多音频同时播放</button>
<button @click="pause">多音频同时播放</button>
</navigator>
</view>
<!-- #ifdef APP -->
......@@ -304,4 +304,4 @@
width: 60px;
height: 60px;
}
</style>
\ No newline at end of file
</style>
<template>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<!-- #ifdef APP -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<view class="uni-title">
<text class="uni-title-text">音频路径示例</text>
</view>
......@@ -9,7 +10,9 @@
<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>
......@@ -20,25 +23,30 @@
export default {
data() {
return {
title: 'audio-path',
playIndex: 0,
isPlaying: false,
nativePath:uni.env.CACHE_PATH+'uni-audio/test/test.mp3' as string,
sdcardPath :'sdcard/uni-audio/test.mp3',
isPlaying: false,
// #ifdef APP
nativePath: uni.env.CACHE_PATH + 'uni-audio/test/test.mp3' as string,
// #endif
// #ifdef APP-ANDROID
sdcardPath: 'sdcard/uni-audio/test.mp3',
// #endif
_audioContext: null as InnerAudioContext | null,
supportPaths: [
{
description: '本地路径:/static方式',
src: '/static/test-audio/ForElise.mp3'
},
{
{
description: '本地路径:../static/',
src: '../../../static/test-audio/ForElise.mp3'
},
{
description: '本地路径:env方式',
src: 'env'
},
},
// #ifdef APP
{
description: '本地路径:env方式',
src: 'env'
},
// #endif
{
description: '网络路径',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app-x/audio/ForElise.mp3'
......@@ -55,37 +63,39 @@
}
},
onReady() {
this._audioContext = uni.createInnerAudioContext();
this._audioContext!.onPlay(() => {
console.log('开始播放');
});
this._audioContext!.onEnded(() => {
console.log('播放结束');
this.isPlaying = false;
});
this._audioContext!.onError((err) => {
this.isPlaying = false;
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){
}
},
this._audioContext = uni.createInnerAudioContext();
this._audioContext!.onPlay(() => {
console.log('开始播放');
});
this._audioContext!.onEnded(() => {
console.log('播放结束');
this.isPlaying = false;
});
this._audioContext!.onError((err) => {
this.isPlaying = false;
console.log('err', err);
});
// #ifdef APP
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) {
}
// #endif
},
onUnload() {
if (this._audioContext != null) {
this.pause();
......@@ -97,16 +107,18 @@
this._audioContext!.pause();
this.isPlaying = false;
},
play(audioUrl:string, index:number) {
console.log(index,audioUrl);
play(audioUrl : string, index : number) {
console.log(index, audioUrl);
if (this.isPlaying && this.playIndex == index) {
this.pause();
return;
}
if(audioUrl == 'env'){
audioUrl=this.nativePath
}
}
// #ifdef APP
if (audioUrl == 'env') {
audioUrl = this.nativePath
}
// #endif
this.playIndex = index
this._audioContext!.src = audioUrl;
this._audioContext!.play();
......@@ -126,4 +138,4 @@
height: 60px;
margin: 10px;
}
</style>
</style>
......@@ -8,9 +8,11 @@
<!-- <text class="common" style="font-family: AlimamaDaoLiTiWOFF">font-family: 阿里妈妈刀隶体-woff</text>
<text class="common" style="font-family: AlimamaDaoLiTiWOFF2">font-family: 阿里妈妈刀隶体-woff2</text> -->
</view>
<!-- #ifdef APP -->
<view style="margin: 24px 12px;">
<button type="default" @click="openUniIcon">内置字体图标uni-icon示例</button>
</view>
<!-- #endif -->
</template>
<script lang="uts">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册