在Android应用程序中读取mp3标签

编程入门 行业动态 更新时间:2024-10-27 06:27:01
本文介绍了在Android应用程序中读取mp3标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将jid3lib用于Java.当我使用此库中存储在计算机中的文件来工作时,它很好用,但是当我尝试在模拟器的sdcard上读取文件的mp3标签时,我得到了Exeption.

我使用以下代码:

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(); } } }

我在sdcard中放入了2个mp3文件,但在日志中仍然出现异常. 这可能是什么问题?

我在LogCat上遇到以下错误:

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

但是,当我在DDMS的文件资源管理器中查看时,即使在使用循环来打印文件名的情况下,也可以看到该路径下的文件.

解决方案

EACCES(权限被拒绝)

在清单文件中添加 READ_EXTERNAL_STORAGE 权限. /p>

而且,也许WRITE_EXTERNAL_STORAGE也是如此.

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.

解决方案

EACCES (Permission denied)

Add READ_EXTERNAL_STORAGE permission in manifest file.

And, maybe WRITE_EXTERNAL_STORAGE also.

更多推荐

在Android应用程序中读取mp3标签

本文发布于:2023-11-23 15:36:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   标签   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!