10

我一直在尝试使用 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);

我收到消息“加载内容时出错 /system/ringtone sample 0 not READY”。将 URI 替换为 sd 卡上现有 mp3 文件的硬路径会产生类似的结果。

我究竟做错了什么?谢谢,

凯尔

4

1 回答 1

27

您可能不想将 SoundPool 用于此类音频播放。SoundPool 通常用于播放非常小的音频片段,存储为本地文件,甚至比大多数铃声还要小。您应该考虑使用 MediaPlayer。以下应该可以很好地工作:

MediaPlayer player = MediaPlayer.create(this,
    Settings.System.DEFAULT_RINGTONE_URI);
player.start();

尽管如果您无权从您的应用程序访问该铃声,您可能会收到 FileNotFoundException。

于 2010-11-01T02:38:54.637 回答