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

音频开发之音频信息获取 以获取艺术家为例2021/05/31号编辑
2021/06/01号编辑
在昨天进行第一次文档编辑后,我认为其过程过于繁琐,觉得肯定有更简单的方法,我查阅了官方文档,以下是文档中关于字段的总结:
我总感觉还有其他字段,于是借助 query() 方法查询外部存储的Uri,获取到对应的,并打印其所有的
1.获取
DataAbilityHelper helper = DataAbilityHelper.creator(context);resultSet = helper.query(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI, null, null);
2.获取所有的
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]

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

文章插图
你可以看到字段,因而我们可以直接通过下面的语句获取艺术家
3.获取艺术家
resultSet.getString(resultSet.getColumnIndexForName("artist"));
2021/05/31号编辑 1.获取指示外部存储的Uri
文档链接..Media
AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI
2.借助()方法获取Uri对应的
文档链接(Uri uri)
AVStorage.fetchVolumeName(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI)
3.借助()方法获取://格式的URI,该URI用于处理音频艺术家信息 。
文档链接?( )
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.获取所有的
HiLog.info(hiLogLabel,Arrays.toString(result.getAllColumnNames()));
结果
[number_of_tracks, artist, _id, artist_key, number_of_albums]
6.获取艺术家
【以获取艺术家为例HarmongOS音频开发之音频信息获取】result.getString(result.getColumnIndexForName("artist"))