1

我想为来电播放铃声。我喜欢下面的,

Uri defaultRingToneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            if(currentRingtonePlayer != null ){
                stopRingTonePlayer();
            }
            currentRingtonePlayer = new MediaPlayer();
            currentRingtonePlayer.setDataSource(this, defaultRingToneUri);
            currentRingtonePlayer.setLooping(true);
            currentRingtonePlayer.prepare();
            currentRingtonePlayer.start();

使用此代码播放铃声。但我越来越低于例外,

2021-03-16 11:59:05.415 12096-12096/ W/MediaPlayer: Couldn't open content://0@settings/system/ringtone_cache
    java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
        at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149)
        at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1700)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1516)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1433)
        at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1157)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1106)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1022)
        at com.CallActivity.playRingTone(CallActivity.java:620)
        at com.CallActivity.onCreate(CallActivity.java:348)
        at android.app.Activity.performCreate(Activity.java:7893)
        at android.app.Activity.performCreate(Activity.java:7880)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3310)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3484)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2068)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7551)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)

在我的情况下,播放铃声。尽管我得到了这个例外。有人知道为什么会这样吗?提前致谢

4

1 回答 1

0

如何使用 getActualDefaultRingtoneUri

Uri defaultRingToneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_RINGTONE);

于 2021-03-24T13:22:37.887 回答