Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Notification Sound from Assets folder

Tags:

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.

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.

I tried

notification.sound = Uri.parse("file:///android_asset/Sound/Long/AlarmClock.mp3"); 

also tried like this

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.

like image 512
Dharmendra Avatar asked Jan 10 '12 09:01

Dharmendra


2 Answers

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"); 
like image 59
rajpara Avatar answered Oct 11 '22 01:10

rajpara


This worked perfectly for me. I found it on another post.

notification.sound = Uri.parse("android.resource://my.package.name/raw/notification"); 
like image 23
Comacoco Avatar answered Oct 11 '22 01:10

Comacoco