#鸿蒙学习大百科#如何在申请ohos.permission.READ_AUDIO权限时,使用AudioViewPicker来做替代方案?

如何在申请ohos.permission.READ_AUDIO权限时,使用AudioViewPicker来做替代方案?


HarmonyOS
2024-10-21 09:23:54
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
自封的不算
//1.导入选择器模块和文件管理模块。
import picker from '@ohos.file.picker';
import fs from '@ohos.file.fs';
import { BusinessError } from '@ohos.base';
//2.创建音频类型文件选择选项实例。
//目前AudioSelectOptions不支持参数配置,默认可以选择所有类型的用户文件。
const audioSelectOptions = new picker.AudioSelectOptions();

@Entry
@Component
struct Index {
  build() {
    Row() {
      Column() {
        Text("Hello")
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            // 3.创建音频选择器实例。调用select()接口拉起FilePicker应用界面进行文件选择。
            const audioViewPicker = new picker.AudioViewPicker();
            audioViewPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => {
              let uri: string = '';
              uri = audioSelectResult[0];
              console.info('audioViewPicker.select to file succeed and uri is:' + uri);
            }).catch((err: BusinessError) => {
              console.error(`Invoke audioViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
            })
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
分享
微博
QQ
微信
回复
2024-10-21 14:48:33
相关问题
#鸿蒙学习大百科#ArkTS如何生成xml?
1178浏览 • 1回复 待解决