我一直在尝试使用SoundPool播放默认铃声但没有成功。在下面的代码中
String ringtone = Settings.System.DEFAULT_RINGTONE_URI.getPath();
SoundPool ringPhone = new SoundPool(2, AudioManager.STREAM_RING, 1);
int soundID = ringPhone.load(Settings.System.DEFAULT_RINGTONE_URI.getPath(), 1);
int soundID = ringPhone.load(ringtone, 1);
ringPhone.play(soundID, 0.99f, 0.99f, 1, 0, 1);
我收到消息“错误加载内容/系统/铃声示例0未就绪”。用sd卡上现有mp3文件的硬路径替换URI会产生类似的结果。
我做错了什么?谢谢,
凯尔
答案 0 :(得分:22)
您可能不希望将SoundPool用于此类型的音频播放。 SoundPool通常用于播放非常小的音频片段,存储为本地文件,甚至比大多数铃声还要小。您应该考虑使用MediaPlayer。以下应该很好地工作:
MediaPlayer player = MediaPlayer.create(this,
Settings.System.DEFAULT_RINGTONE_URI);
player.start();
虽然如果您没有权限从您的应用程序访问该铃声,您可能会收到FileNotFoundException。