我尝试使用jaudiotagger 2.0.1库但是当我尝试设置元标记时出现此错误:
08-28 11:27:21.477: W/System.err(25763): org.jaudiotagger.audio.exceptions.CannotWriteException: org.jaudiotagger.audio.exceptions.UnableToCreateFileException: Cannot modify /storage/emulated/0/Music/01-Happy Christmas (War is Over) - John Lennon and Yoko Ono.mp3 because do not have permissions to modify file
08-28 11:27:21.477: W/System.err(25763): at org.jaudiotagger.audio.mp3.MP3File.commit(MP3File.java:722)
08-28 11:27:21.477: W/System.err(25763): at com.mypackage$1.onClick(Tag.java:142)
08-28 11:27:21.477: W/System.err(25763): at android.view.View.performClick(View.java:4445)
08-28 11:27:21.477: W/System.err(25763): at android.view.View$PerformClick.run(View.java:18446)
08-28 11:27:21.477: W/System.err(25763): at android.os.Handler.handleCallback(Handler.java:733)
08-28 11:27:21.477: W/System.err(25763): at android.os.Handler.dispatchMessage(Handler.java:95)
08-28 11:27:21.485: W/System.err(25763): at android.os.Looper.loop(Looper.java:136)
08-28 11:27:21.485: W/System.err(25763): at android.app.ActivityThread.main(ActivityThread.java:5139)
08-28 11:27:21.485: W/System.err(25763): at java.lang.reflect.Method.invokeNative(Native Method)
08-28 11:27:21.485: W/System.err(25763): at java.lang.reflect.Method.invoke(Method.java:515)
08-28 11:27:21.485: W/System.err(25763): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
08-28 11:27:21.485: W/System.err(25763): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
08-28 11:27:21.485: W/System.err(25763): at dalvik.system.NativeStart.main(Native Method)
08-28 11:27:21.485: W/System.err(25763): Caused by: org.jaudiotagger.audio.exceptions.UnableToCreateFileException: Cannot modify /storage/emulated/0/Music/01-Happy Christmas (War is Over) - John Lennon and Yoko Ono.mp3 because do not have permissions to modify file
08-28 11:27:21.485: W/System.err(25763): at org.jaudiotagger.tag.id3.AbstractID3v2Tag.writeBufferToFile(AbstractID3v2Tag.java:1165)
08-28 11:27:21.485: W/System.err(25763): at org.jaudiotagger.tag.id3.ID3v23Tag.write(ID3v23Tag.java:741)
08-28 11:27:21.485: W/System.err(25763): at org.jaudiotagger.audio.mp3.MP3File.save(MP3File.java:790)
08-28 11:27:21.485: W/System.err(25763): at org.jaudiotagger.audio.mp3.MP3File.save(MP3File.java:706)
08-28 11:27:21.485: W/System.err(25763): at org.jaudiotagger.audio.mp3.MP3File.commit(MP3File.java:718)
08-28 11:27:21.485: W/System.err(25763): ... 12 more
我使用的代码是:
String mTitle = title.getText().toString();
String mAlbum = album.getText().toString();
String mArtist = artist.getText().toString();
String mGenre = genre.getText().toString();
if(tag != null) {
if(mTitle.length() > 0) {
tag.setField(FieldKey.TITLE, mTitle);
}
if(mAlbum.length() > 0) {
tag.setField(FieldKey.ALBUM, mAlbum);
}
if(mArtist.length() > 0) {
tag.setField(FieldKey.ARTIST, mArtist);
}
if(mGenre.length() > 0) {
tag.setField(FieldKey.GENRE, mGenre);
}
}
if(audioFile != null) {
audioFile.commit();
}
我不明白为什么我无法编辑代码。错误在哪里?我怎么解决?
答案 0 :(得分:1)
您没有相应的权限来更改文件。编辑id3标签涉及读取,修改文件,然后将文件写入其原始位置。
如果您正在运行KitKat或更高版本,并且音频文件存储在SD卡中,则Google已撤销开发人员修改文件的权限。
否则,可能只是您没有在清单中请求写访问权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />