播放默认铃声
我一直尝试使用 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 未就绪时出错”。将 URI 替换为 sd 卡上现有 mp3 文件的硬路径会产生类似的结果。
我做错了什么?谢谢,
凯尔
I've been trying to use SoundPool to play the default ringtone without success. In the code below
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);
I get the message "error loading content /system/ringtone sample 0 not READY". Replacing the URI with a hard path to an existing mp3 file on the sd card yields similar results.
What am I doing wrong? Thanks,
kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能不希望使用 SoundPool 来播放此类音频。 SoundPool 通常用于播放非常小的音频片段,存储为本地文件,甚至比大多数铃声还要小。您应该考虑使用 MediaPlayer。以下内容应该可以很好地工作:
尽管如果您没有从应用程序访问该铃声的权限,则可能会收到 FileNotFoundException。
You probably don't want to be using the SoundPool for this type of audio playing. SoundPool is usually used to play very small snippets of audio, stored as local files, even smaller than most ringtones. You should consider MediaPlayer instead. The following ought to work very nicely:
Although if you don't have permission to access that ringtone from your application, you could get a FileNotFoundException.