HarmonyOS音频开发之音频信息获取 以获取艺术家为例
头像 宋你一朵小红花 2021-06-02 10:00:00    发布
3904 浏览 10 点赞 23 收藏

HarmonyOS音频开发之音频信息获取 以获取艺术家为例


2021/06/01号编辑

在昨天进行第一次文档编辑后,我认为其过程过于繁琐,觉得肯定有更简单的方法,我查阅了官方文档,以下是文档中关于字段的总结:

HarmonyOS音频开发之音频信息获取  以获取艺术家为例-鸿蒙开发者社区
我总感觉还有其他字段,于是借助 query() 方法查询外部存储的Uri,获取到对应的 resultSet ,并打印其所有的ColumnName


1.获取ResultSet


DataAbilityHelper helper = DataAbilityHelper.creator(context);
resultSet = helper.query(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI, null, null);

2.获取所有的ColumnName


HiLog.info(hiLogLabel,Arrays.toString(resultSet.getAllColumnNames()));

结果


[title_key, instance_id, duration, is_ringtone, album_artist, orientation, artist, height, is_drm, bucket_display_name, is_audiobook, owner_package_name, volume_name, title_resource_uri, date_modified, date_expires, composer, _display_name, datetaken, mime_type, is_notification, _id, year, _data, _hash, _size, album, is_alarm, title, track, width, is_music, album_key, is_trashed, group_id, document_id, artist_id, artist_key, is_pending, date_added, is_podcast, album_id, primary_directory, secondary_directory, original_document_id, bucket_id, bookmark, relative_path]

你可以看到artist字段,因而我们可以直接通过下面的语句获取艺术家

3.获取艺术家


resultSet.getString(resultSet.getColumnIndexForName("artist"));

2021/05/31号编辑

1.获取指示外部存储的Uri

文档链接AVStorage.Images.Media


AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI

2.借助fetchVolumeName()方法获取Uri对应的VolumeName

文档链接fetchVolumeName(Uri uri)


AVStorage.fetchVolumeName(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI)

3.借助fetchResource()方法获取dataability://格式的URI,该URI用于处理音频艺术家信息。

文档链接fetchResource​(String volumeName)


AVStorage.Audio.Artists.fetchResource(AVStorage.fetchVolumeName(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI)

4.使用query()方法查询Uri

文档链接访问Data


DataAbilityHelper helper = DataAbilityHelper.creator(this);
ResultSet result = helper.query(AVStorage.Audio.Artists.fetchResource(AVStorage.fetchVolumeName(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI)), null,null);

5.获取result所有的ColumnName


HiLog.info(hiLogLabel,Arrays.toString(result.getAllColumnNames()));

结果


[number_of_tracks, artist, _id, artist_key, number_of_albums]

6.获取艺术家


result.getString(result.getColumnIndexForName("artist"))
©本站发布的所有内容,包括但不限于文字、图片、音频、视频、图表、标志、标识、广告、商标、商号、域名、软件、程序等,除特别标明外,均来源于网络或用户投稿,版权归原作者或原出处所有。我们致力于保护原作者版权,若涉及版权问题,请及时联系我们进行处理。
分类
其它
地址:北京市朝阳区北三环东路三元桥曙光西里甲1号第三置业A座1508室 商务内容合作QQ:2291221 电话:13391790444或(010)62178877
版权所有:电脑商情信息服务集团 北京赢邦策略咨询有限责任公司
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,我司致力于保护作者版权,如有侵权,请与我司联系删除
京ICP备:2022009079号-2
京公网安备:11010502051901号
ICP证:京B2-20230255