【问题标题】:How do you access the name, artist, album name off the music stored on the phone?如何从手机上存储的音乐中获取姓名、艺术家、专辑名称?
【发布时间】:2019-02-03 02:27:28
【问题描述】:

就像音乐应用程序一样,我想要访问歌曲的名称(而不是文件的名称)或艺术家或专辑。例如,我想用手机上所有歌曲的名称填充一个列表视图。

【问题讨论】:

    标签: android listview


    【解决方案1】:

    有两种方法,一种是从音乐文件本身读取元标记,另一种是使用MediaStore 内容提供程序。 MediaStore本质上是一个公共数据库,您可以在手机上查询所有与媒体相关的信息。

    使用MediaStore 非常简单,可以在文档here 中找到。

    这是我的一个应用程序中的一个简单示例:

    String[] proj = { MediaStore.Audio.Media._ID,
    MediaStore.Audio.Media.DATA,
    MediaStore.Audio.Media.DISPLAY_NAME,
    MediaStore.Audio.Artists.ARTIST };
    
    tempCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                                proj, null, null, null);
    
    tempCursor.moveToFirst(); //reset the cursor
    int col_index=-1;
    int numSongs=tempCursor.getCount();
    int currentNum=0;
    do{
      col_index = tempCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
      artist = tempCursor.getString(col_index);
      //do something with artist name here
      //we can also move into different columns to fetch the other values
      }
      currentNum++;
    }while(tempCursor.moveToNext());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多