2014-08-28 167 views
0

我試圖使用jaudiotagger 2.0.1庫的,但是當我嘗試設置meta標籤我得到這個錯誤:無法編輯MP3標籤

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

我不明白爲什麼我不能編輯標籤。錯誤在哪裏?我該如何解決?

回答

1

您沒有相應的權限來更改文件。編輯id3標籤涉及讀取,修改,然後將文件寫入它的原始位置。

如果您正在運行KitKat或更高版本,並且音頻文件存儲在SD卡中,Google已經撤銷了開發者修改文件的權限。

否則,它可能只是你還沒有要求寫訪問權限在您的清單:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+0

呀。現在它工作了! – 2014-08-28 12:37:08