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
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐