Android (Archos 5 IT) 上的音频 (MediaPlayer)
首先,Archos 的文件路径是什么?我正在尝试播放一些媒体/音频,但它找不到它......
public void onClick(View v1) {
final MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("ARCHOS5:/Music/manowar.mp3");
mp.start();
Toast.makeText(Textbox.this, "Working", Toast.LENGTH_LONG).show();
mp.setLooping(true);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
该代码有什么问题?
其次:我无法播放“R.raw.'filename'”中的音频文件。
它在模拟器上运行得很好,但是当我按下 Archos 上的播放按钮(另一个)时,它就崩溃了。
Firstly, what is the filepath for an Archos? I'm trying to get some media/audio to play, and it just won't find it...
public void onClick(View v1) {
final MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("ARCHOS5:/Music/manowar.mp3");
mp.start();
Toast.makeText(Textbox.this, "Working", Toast.LENGTH_LONG).show();
mp.setLooping(true);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
What is wrong with that code?
Secondly: I can't get audio files in "R.raw.'filename'" to play.
It works perfectly on the emulator, but when I press the play button (a different one) on the Archos, it just crashes.
您应该使用
openRawResource()
来访问
R.raw
中的项目。要访问 SD 卡,请查看这篇文章等资源。You should use
openRawResource()
to access items inR.raw
. To access the SD card, check out resources like this post.