gpt4 book ai didi

java - Android 使用 jaudiotagger

转载 作者:太空狗 更新时间:2023-10-29 12:53:24 27 4
gpt4 key购买 nike

我尝试像这样使用 jaudiotagger但是它崩溃了

主要的 app.java : 导入java.io.文件; 导入 java.io.IOException;

import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.AudioHeader;
import org.jaudiotagger.audio.exceptions.CannotReadException;
import org.jaudiotagger.audio.exceptions.CannotWriteException;
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.tag.FieldDataInvalidException;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.KeyNotFoundException;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.TagException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class App extends Activity {
/** Called when the activity is first created. */


private TextView txt1;
private TextView txt2;
private TextView txt3;
private TextView txt4;
private TextView txt5;
private TextView txt6;
private TextView txt7;
private TextView txt8;
private TextView txt9;






@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// try
//{
File mp3 = new File("/sdcard/test.mp3");
AudioFile f = null;
try {
f = AudioFileIO.read(mp3);
} catch (CannotReadException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
} catch (TagException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
} catch (ReadOnlyFileException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
} catch (InvalidAudioFrameException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
}
Tag tag = f.getTag();
AudioHeader AudioHeader = f.getAudioHeader();
txt1.setText(tag.getFirst(FieldKey.ARTIST));
txt2.setText(tag.getFirst(FieldKey.ALBUM));
txt3.setText(tag.getFirst(FieldKey.TITLE));
txt4.setText(tag.getFirst(FieldKey.COMMENT));
txt5.setText(tag.getFirst(FieldKey.YEAR));
txt6.setText(tag.getFirst(FieldKey.TRACK));
txt7.setText(tag.getFirst(FieldKey.DISC_NO));
txt8.setText(tag.getFirst(FieldKey.COMPOSER));
txt9.setText(tag.getFirst(FieldKey.ARTIST_SORT));




try {
tag.setField(FieldKey.ARTIST,"Kings of Leon");
} catch (KeyNotFoundException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
} catch (FieldDataInvalidException e) {
// TODO Auto-generated catch block
txt1.setText(e.toString());
}
try {
AudioFileIO.write(f);
} catch (CannotWriteException e) {
txt1.setText(e.toString());
}
/* }
catch(Exception x)
{
txt1.setText(x.toString());
}
*/




}
}

日志:

02-22 21:12:22.546: E/AndroidRuntime(19738): FATAL EXCEPTION: main 02-22 21:12:22.546: E/AndroidRuntime(19738): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mp3.tag.editor.alexander.fuchs/com.mp3.tag.editor.alexander.fuchs.App}: java.lang.NullPointerException 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.os.Handler.dispatchMessage(Handler.java:99) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.os.Looper.loop(Looper.java:130) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread.main(ActivityThread.java:3691) 02-22 21:12:22.546: E/AndroidRuntime(19738): at java.lang.reflect.Method.invokeNative(Native Method) 02-22 21:12:22.546: E/AndroidRuntime(19738): at java.lang.reflect.Method.invoke(Method.java:507) 02-22 21:12:22.546: E/AndroidRuntime(19738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 02-22 21:12:22.546: E/AndroidRuntime(19738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 02-22 21:12:22.546: E/AndroidRuntime(19738): at dalvik.system.NativeStart.main(Native Method) 02-22 21:12:22.546: E/AndroidRuntime(19738): Caused by: java.lang.NullPointerException 02-22 21:12:22.546: E/AndroidRuntime(19738): at com.mp3.tag.editor.alexander.fuchs.App.onCreate(App.java:72) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 02-22 21:12:22.546: E/AndroidRuntime(19738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 02-22 21:12:22.546: E/AndroidRuntime(19738): ... 11 more

最佳答案

有两个拦截器在 Android 上使用 jaudiotagger:

1 - javax.swing

2 - javax.imageio

android 不支持这两个类,jaudiotagger 使用它们

解决您的问题:修复源代码,使它们不再依赖于这两个 JAVAX 类

关于java - Android 使用 jaudiotagger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9402245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com