HarmongOS音频开发之本地音频播放列表的获取

Posted 码上夏雨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HarmongOS音频开发之本地音频播放列表的获取相关的知识,希望对你有一定的参考价值。

HarmongOS音频开发之本地音频播放列表的获取

获取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;
}   

以上是关于HarmongOS音频开发之本地音频播放列表的获取的主要内容,如果未能解决你的问题,请参考以下文章

iOS音频播放之AudioQueue:播放本地音乐

iOS音频播放之AudioQueue:播放本地音乐

第十一章 视频播放器开发之音频播放

HarmongOS音乐播放器开发示例教程

iOS开发之音频播放录音

小程序音频播放缓存本地