我想要一个AlertDialog,当显示播放铃声时,我做了这个:
ad.show();
try {
MediaPlayer mt = MediaPlayer.create(context,R.raw.ringtone);
mt.setVolume(5,5);
mt.start();
mt.setLooping(true);
}
catch(Exception e)
{
Log.d("erreur sonnerie","erreur",e);
}
在显示AlertDialog之后,铃声正常播放,但我总是有例外。 我该如何解决这个问题?
非常感谢。
日志:
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): erreur
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): android.content.res.Resources$NotFoundException: File res/raw/ringtone from drawable resource ID #0x7f050000
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.content.res.Resources.openRawResourceFd(Resources.java:860)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.media.MediaPlayer.create(MediaPlayer.java:662)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at com.sip_communicator.Dialog.répondre(Dialog.java:101)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at com.sip_communicator.IncomingCallReceiver.onReceive(IncomingCallReceiver.java:28)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.os.Handler.handleCallback(Handler.java:587)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.os.Handler.dispatchMessage(Handler.java:92)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.os.Looper.loop(Looper.java:123)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at java.lang.reflect.Method.invoke(Method.java:507)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at dalvik.system.NativeStart.main(Native Method)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:427)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): at android.content.res.Resources.openRawResourceFd(Resources.java:857)
04-27 00:55:07.658: DEBUG/erreur sonnerie(893): ... 13 more