从“资产"文件夹设置通知声音 [英] Set Notification Sound from Assets folder
问题描述
我将声音文件附加到资源文件夹中,以便在通知中播放声音,但无法播放资源文件夹中的声音.
I am attaching the sound files in the assets folder for play sound in the notification but I am not able to play sound from the assets folder.
我有一个设置页面,用户可以从中设置通知的声音,也可以播放声音.这部分完成.我可以使用Media Player从资源文件夹播放声音.我可以在创建通知时使用相同的逻辑,但是当用户单击通知时可能会发生问题,因为媒体播放器仍在播放声音.
I have setting page from which user can set the sound for the notification and also user can play sound. This part is completed. I am able to play sound from the assets folder using Media Player. I can use same logic at the Notification creation time but problem can be happened when user click on the Notification because media player still playing the sound.
我尝试过
notification.sound = Uri.parse("file:///android_asset/Sound/Long/AlarmClock.mp3");
也尝试过这样
notification.sound = Uri.parse("android_asset/Sound/Long/AlarmClock.mp3");
但是我的问题仍然没有解决.
but my issue is still not solved.
还有其他方法可以在资产目录中的通知中设置声音吗?
Is there any other way to set the sound in the notification from the assets directory ?
Logcat
01-10 09:57:01.509: ERROR/PlayerDriver(31): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
01-10 09:57:01.509: ERROR/MediaPlayer(52): error (1, -4)
01-10 09:57:01.519: WARN/NotificationService(52): error loading sound for android_asset/Sound/Long/audio.mp3
01-10 09:57:01.519: WARN/NotificationService(52): java.io.IOException: Prepare failed.: status=0x1
01-10 09:57:01.519: WARN/NotificationService(52): at android.media.MediaPlayer.prepare(Native Method)
01-10 09:57:01.519: WARN/NotificationService(52): at android.media.AsyncPlayer.startSound(AsyncPlayer.java:64)
01-10 09:57:01.519: WARN/NotificationService(52): at android.media.AsyncPlayer.access$200(AsyncPlayer.java:33)
01-10 09:57:01.519: WARN/NotificationService(52): at android.media.AsyncPlayer$Thread.run(AsyncPlayer.java:99)
01-10 09:57:01.519: WARN/PlayerDriver(31): PVMFInfoErrorHandlingComplete
或其他任何想法?请给我提示.
or any other idea ? Please give me hint.
推荐答案
将ur mp3文件放入res->raw folder
,尝试从raw folder
中获取声音文件.
put ur mp3 file in res->raw folder
, try to fetch sound file from raw folder
.
Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);
OR
Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");
这篇关于从“资产"文件夹设置通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!