Read mp3 tags in android application

旧巷老猫 提交于 2019-12-24 13:25:28

问题


I use jid3lib for java. When i'm working with this library on file that stored in my computer it works great, but when I try to read mp3 tags of files on the emulator's sdcard I got Exeption.

I use the following code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    File musicPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);

    File[] songs = musicPath.listFiles();

    for (int i=0; i < songs.length; i++){
        try {
            MP3File song = new MP3File(new File(songs[i].getPath()));
            Log.d("TEST", song.getID3v1Tag().getAlbum() );

        } catch (TagException e) {
            Log.d("TEST", "Tag Exception");
            e.printStackTrace();
        } catch (Exception e) {
            Log.d("TEST", "Exception");             
            e.printStackTrace();
        }

    }
}

I put 2 mp3 files in the sdcard, but I still got Exception in the Log. What can be the problem here?

I got the following error at the LogCat:

java.io.FileNotFoundException: /mnt/sdcard/Music/song.mp3: open failed: EACCES (Permission denied)

But when I'm looking in the File Explorer of the DDMS I can see the files under this path, and even if I use a loop in order to print the file's names It show the correct names.


回答1:


EACCES (Permission denied)

Add READ_EXTERNAL_STORAGE permission in manifest file.

And, maybe WRITE_EXTERNAL_STORAGE also.



来源:https://stackoverflow.com/questions/15200852/read-mp3-tags-in-android-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!