播放特定的通知声音

播放特定的通知声音

本文介绍了播放特定的通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个对话框,选择一个通知声音的应用程序。我查询通知通过获得来自RingtoneManager光标声音:

I've created a dialog for selecting a notification sound for an app. I'm querying the notification sounds by getting a cursor from the RingtoneManager:

RingtoneManager manager = new RingtoneManager(this);
manager.setType(RingtoneManager.TYPE_NOTIFICATION);
Cursor cursor = manager.getCursor();

我然后通过连接的名称声音路径存储完整路径。

I then store the full path to it by concatenating the sound path with the name.

这工作得很好,当我设置选定的声音作为通知的声音,但我不能让媒体播放器上播放的选择:

This works fine when I set the selected sound as the notification sound but I can't get media player to play it on selection:

MediaPlayer mp = MediaPlayer.create(this, Uri.parse(path));

这抛出IllegalStateException:

This throws an IllegalStateException:

java.lang.IllegalStateException: Unknown URL: content://media/internal/audio/media/Capella

这是如何得到一个特定的通知声音的正确路径任何想法?

Any ideas on how to get the correct path to a specific notification sound?

推荐答案

播放声音正确的方法是使用它的ID,而不是名称:

The correct way to play a sound is to use it's ID and not the name:

cursor.getInt(RingtoneManager.ID_COLUMN_INDEX)

感谢Darkie指着我正确的方向。

Thanks Darkie for pointing me to the right direction.

这篇关于播放特定的通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 10:11