简体   繁体   中英

RingtoneManager is not able to play the tone after reading from res/raw folder in android

I have following code snippet for playing the tone that is saved in the res/raw folder. I can see the alert dialogue but the sound that I wanted to play is not happening. What mistake I am doing here?

 if(min < thresHold)
                    {

                        Uri faulttone = Uri.parse("android.resource://"
                                + getActivity().getPackageName() + "/raw/" + "distancefault.mp3");

                        Ringtone r = RingtoneManager.getRingtone(getActivity(), faulttone);
                        r.play();
                        alertDialogue.show();

                    }

Okay, I didn't get any idea on how to do this thing with Ringtone Manager, but changed the approach and used MediaPlayer class. If anyone has idea how to do this with RingtoneManager please post your answer.

final MediaPlayer mp = MediaPlayer.create(getActivity(),R.raw.distancefault);
                            mp.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM