From 1cfb37fd71351f961d2ae7845533b5ab432b6bde Mon Sep 17 00:00:00 2001 From: duqingquan-jpc Date: Sat, 12 Nov 2022 12:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9F=B3=E9=A2=91=E6=92=AD=E6=94=BE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=81=9C=E6=AD=A2=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 8 ++++ pages/advance/advance.vue | 8 +++- pages/advance/android/assetaudio.vue | 46 +++++++++++++++++++ .../uts-advance/utssdk/app-android/index.uts | 35 +++++++++++--- 4 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 pages/advance/android/assetaudio.vue diff --git a/pages.json b/pages.json index 6162307..425243e 100644 --- a/pages.json +++ b/pages.json @@ -89,6 +89,14 @@ "enablePullDownRefresh": false } + },{ + "path" : "pages/advance/android/assetaudio", + "style" : + { + "navigationBarTitleText": "", + "enablePullDownRefresh": false + } + }, { "path" : "pages/SystemAPI/ScreenListen/screenlisten", diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index 693c110..37ef0da 100644 --- a/pages/advance/advance.vue +++ b/pages/advance/advance.vue @@ -38,10 +38,11 @@ + - + @@ -134,7 +135,10 @@ }) }, testAssetLoad() { - playAssetAudio(); + // playAssetAudio(); + uni.navigateTo({ + url: '/pages/advance/android/assetaudio' + }) }, testInputDialog() { getUserInput(function(res){ diff --git a/pages/advance/android/assetaudio.vue b/pages/advance/android/assetaudio.vue new file mode 100644 index 0000000..9b71746 --- /dev/null +++ b/pages/advance/android/assetaudio.vue @@ -0,0 +1,46 @@ + + + + + \ No newline at end of file diff --git a/uni_modules/uts-advance/utssdk/app-android/index.uts b/uni_modules/uts-advance/utssdk/app-android/index.uts index 394bcbf..5cb7d89 100644 --- a/uni_modules/uts-advance/utssdk/app-android/index.uts +++ b/uni_modules/uts-advance/utssdk/app-android/index.uts @@ -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 { // 检查相关权限是否已经具备 -- GitLab