我尝试了下面的代码来播放mp3文件,但它会播放所有铃声。 谁能帮我为什么播放铃声?
MediaPlayer mMediaPlayer1 = new MediaPlayer();
AssetFileDescriptor fd = context.getResources().openRawResourceFd(R.raw.dialtone);
FileInputStream in = new FileInputStream(fd.getFileDescriptor());
mMediaPlayer1.setDataSource(in.getFD());
mMediaPlayer1.setLooping(true);
mMediaPlayer1.prepare();
mMediaPlayer1.start();`
答案 0 :(得分:1)
尝试一下:
public static void startSound(Context context, int soundResId) {
if (mMediaPlayer != null) {
mMediaPlayer.reset();
mMediaPlayer = null;
}
mMediaPlayer = MediaPlayer.create(context, soundResId);
mMediaPlayer.start();
}
然后
startSound(this, R.raw.dialtone);