提交 1cfb37fd 编写于 作者: 打打卡夫卡's avatar 打打卡夫卡

音频播放增加停止按钮

上级 2b853412
......@@ -89,6 +89,14 @@
"enablePullDownRefresh": false
}
},{
"path" : "pages/advance/android/assetaudio",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/SystemAPI/ScreenListen/screenlisten",
......
......@@ -38,10 +38,11 @@
<uni-list>
<uni-list-item @tap="testLifecyle" title="activity生命周期监听" :clickable="true" link />
<uni-list-item @tap="testAssetLoad" title="播放asset音频(需自定义基座)" :clickable="true" link/>
<uni-list-item @tap="gotoDecorView" title="操作DecorView" :clickable="true" link />
<uni-list-item @tap="testInputDialog" title="同步获取用户输入" :clickable="true" />
<uni-list-item @tap="testMetaRead" title="读取meta配置" :clickable="true" />
<uni-list-item @tap="testAssetLoad" title="播放asset音频(需自定义基座)" :clickable="true" />
</uni-list>
......@@ -134,7 +135,10 @@
})
},
testAssetLoad() {
playAssetAudio();
// playAssetAudio();
uni.navigateTo({
url: '/pages/advance/android/assetaudio'
})
},
testInputDialog() {
getUserInput(function(res){
......
<template>
<view>
<page-head title="asset 音频播放示例" accordion></page-head>
<uni-list>
<uni-list-item title="播放asset音频" :clickable="true" @tap="testStart"></uni-list-item>
<uni-list-item title="停止播放asset音频" :clickable="true" @tap="testStop"></uni-list-item>
</uni-list>
</view>
</template>
<script>
import {
playAssetAudio,
stopAssetAudio
} from "../../../uni_modules/uts-advance";
export default {
data() {
return {
}
},
methods: {
/**
* 测试添加View实例至顶层容器
*/
testStart: function() {
playAssetAudio();
},
/**
* 测试移除顶层容器的View实例
*/
testStop: function() {
stopAssetAudio();
}
}
}
</script>
<style>
</style>
\ No newline at end of file
......@@ -149,7 +149,9 @@ export function removeViewToDecorView() {
getUniActivity()!.runOnUiThread(uiRunable)
}
/**
* 用户输入对话框监听器
*/
class DialogListener extends DialogInterface.OnClickListener{
inputET:EditText
......@@ -172,7 +174,9 @@ class DialogListener extends DialogInterface.OnClickListener{
}
/**
* Dialog ui任务封装
*/
class DialogUIRunnable extends Runnable {
callback:UTSCallback
......@@ -238,6 +242,10 @@ export function getLogoPath(): string {
return logo;
}
/**
* 音频播放器对象
*/
let globalPlayer:MediaPlayer| null = null;
/**
* 播放asset资源中的音频
*/
......@@ -245,14 +253,29 @@ export function playAssetAudio() {
let assetManager = getAppContext()!.getAssets();
let afd = assetManager.openFd("free.mp3");
let mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
mediaPlayer.prepare();
mediaPlayer.start();
if(globalPlayer == null){
globalPlayer = new MediaPlayer();
globalPlayer!.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(), afd.getLength());
globalPlayer!.prepare();
globalPlayer!.start();
}
}
/**
* 停止播放asset资源中的音频
*/
export function stopAssetAudio() {
if(globalPlayer != null){
globalPlayer!.stop();
globalPlayer = null;
}
}
export function goOtherActivity(imageDone: (event:string) => void):boolean {
// 检查相关权限是否已经具备
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册