搜索与mediastore音乐文件

搜索与mediastore音乐文件

本文介绍了搜索与mediastore音乐文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究这个好几个小时。我看着机器人的javadoc - MediaStore我只是不明白这一点。我看过的例子。什么也没有。

I have been researching this for hours now. I've looked at android javadoc - MediaStore and I just don't get it. I've looked for examples. Nothing.

我要搜索音乐库中的字符串。我主要的想法在我的脑海(获取音乐库数据库,搜索它,就像您一个SQLite数据库),但我硬是不知道该怎么做。

I want to search the music library for a string. I have the main idea in my mind (get music library DB, search it like you would a sqlite DB) but I literally have no idea how to do it.

我还发现了URI外部SD媒体文件 - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,

I have also found the URI for external SD media files - MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,

但我真的不知道该怎么该怎么做。

but I don't really know what to do with this.

一些出发点就好了。

感谢您。

推荐答案

MediaStore 更多或更少的的一个SQLite数据库。有很多方法可以查询。按专辑,艺术家,按播放列表,按歌曲,等等。这将返回所有歌曲光标,例如

The MediaStore more or less is an sqlite DB. There are many ways to query it. By album, by artist, by playlist, by song, and so on. This will return a Cursor of all songs, for example.

Cursor cursor = getContentResolver().query(
    MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
    null,
    null,
    null,
    MediaStore.Audio.Media.TITLE + " ASC");

然后,您可以从它那里得到特定的列像这样:

You can then get specific columns from it like so:

while (cursor.moveToNext()) {
    String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
    // Whatever else you need
}

这篇关于搜索与mediastore音乐文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:08