Android的音乐文件的位置

Android的音乐文件的位置

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

问题描述

我正在写一个音乐播放器应用程序,我不知道我应该在哪里查找用户的音乐文件。我想找到所有的音乐应用程序,通常认定的歌曲,我很好奇如何该应用程序查找歌曲。是否有一个特定的文件夹中的枚举变量?就在SD卡的递归搜索?我知道我的手机上的SD卡有一个音乐文件夹;是,它是如何每一个Android设备上和我应该只是递归搜索该文件夹?或者我应该只是要求用户找到该文件夹​​?

I'm writing a music player app and I'm wondering where should I look for the user's music files. I want to find all the songs that the Music app normally finds and I'm curious how that app finds the songs. Is there an enum variable for a specific folder? Just a recursive search of the sd card? I know on my phone's sd card there's a Music folder; is that how it is on every android device and should I just recursively search that folder? Or should I just ask the user to find the folder?

推荐答案

您可以从SD卡使用以下功能找到的所有音乐文件。

You can find all music files from sdcard using below function.

public void getAllSongsFromSDCARD()
{
    String[] STAR = { "*" };
    Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";

    cursor = managedQuery(allsongsuri, STAR, selection, null, null);

    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {
                String song_name = cursor
                        .getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                int song_id = cursor.getInt(cursor
                        .getColumnIndex(MediaStore.Audio.Media._ID));

                String fullpath = cursor.getString(cursor
                        .getColumnIndex(MediaStore.Audio.Media.DATA));


                String album_name = cursor.getString(cursor
                        .getColumnIndex(MediaStore.Audio.Media.ALBUM));
                int album_id = cursor.getInt(cursor
                        .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));

                String artist_name = cursor.getString(cursor
                        .getColumnIndex(MediaStore.Audio.Media.ARTIST));
                int artist_id = cursor.getInt(cursor
                        .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));



            } while (cursor.moveToNext());

        }
        cursor.close();
    }
}

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

07-30 23:27