HarmonyOS音频开发之本地音频播放列表的获取 原创
码上夏雨
发布于 2021-6-1 16:36
浏览
1收藏
@TOC
获取ResultSet
/**
* @param context
* @return
* If you want to get information about AVStorage.Audio.Media, please refer to:
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/avstorage_audio_media-0000001054678942
* If you want to get information about this function, please refer to:
* https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tv-media-playback-0000001050714866
*/
private ResultSet queryAvStore(Context context) {
ResultSet resultSet = null;
DataAbilityHelper helper = DataAbilityHelper.creator(context);
try {
resultSet = helper.query(AVStorage.Audio.Media.EXTERNAL_DATA_ABILITY_URI, null, null);
} catch (DataAbilityRemoteException e) {
e.printStackTrace();
}
return resultSet;
}
获取播放列表
/**
* @param context
* @return
* get playlist
* If you want to get information about AVStorage.AVBaseColumns.ID or others, please refer to:
* https://developer.harmonyos.com/cn/docs/documentation/doc-references/avstorage_avbasecolumns-0000001054358919#ZH-CN_TOPIC_0000001054358919__DATA
*/
public List<MusicBean> getMusicBeanList(Context context) {
ResultSet resultSet = queryAvStore(context);
List<MusicBean> musicBeans = new ArrayList<>();
while (resultSet.goToNextRow()) {
MusicBean musicBean = new MusicBean();
musicBean.setId(resultSet.getInt(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.ID)));
musicBean.setData(resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DATA)));
musicBean.setTitle(resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.TITLE)));
musicBean.setDuration(resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DURATION)));
musicBean.setSong(resultSet.getString(resultSet.getColumnIndexForName(AVStorage.AVBaseColumns.DISPLAY_NAME)));
musicBeans.add(musicBean);
}
return musicBeans;
}
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2021-6-2 12:54:03修改
赞
2
收藏 1
回复
相关推荐
11-14 21:30:33.020 8944-10531/com.it360.hmos_player E 00000/LogUtil: SourceFactory: Audio resource is unavailable: ===/storage/emulated/0/Music/大风吹 (Live) - 刘惜君 王赫野.mp4: open failed: EACCES (Permission denied)
播放报错 怎么解决?