简体   繁体   English

从Android中的res / raw文件夹读取后,RingtoneManager无法播放声音

[英]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. 我有以下代码片段,用于播放保存在res / raw文件夹中的音调。 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. 好的,我对如何使用Ringtone Manager做到这一点一无所知,但是改变了方法并使用了MediaPlayer类。 If anyone has idea how to do this with RingtoneManager please post your answer. 如果有人知道如何使用RingtoneManager做到这一点,请发表您的答案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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