1

我正在尝试播放闹钟铃声。但是,播放会在随机数秒后停止,它不会播放整个铃声。有谁知道这可能是什么原因?

代码不是我自己的。这是一个经过研究的解决方案:

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
                        if(alert == null){
                            // alert is null, using backup
                            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                            if(alert == null){  // I can't see this ever being null (as always have a default notification) but just in case
                                // alert backup is null, using 2nd backup
                                alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);               
                            }
                        }
                        Ringtone a = RingtoneManager.getRingtone(getApplicationContext(), alert);
                        a.play();

此事件在按钮按下时发生。谢谢!

我只能从 AVD 打印 stacktrage,但我没有声音文件。

08-05 19:39:43.093: D/dalvikvm(611): GC_CONCURRENT freed 370K, 17% free 2526K/3016K, paused 5ms+52ms, total 230ms
08-05 19:39:43.093: W/ActivityManager(281): Unbind failed: could not find connection for android.os.BinderProxy@40e841e8
08-05 19:39:47.843: D/dalvikvm(781): GC_CONCURRENT freed 595K, 14% free 4530K/5256K, paused 24ms+23ms, total 94ms
08-05 19:39:55.403: D/dalvikvm(781): GC_CONCURRENT freed 586K, 14% free 4532K/5252K, paused 6ms+4ms, total 64ms
08-05 19:40:00.383: D/MediaPlayer(781): Couldn't open file on client side, trying server side
08-05 19:40:00.393: E/MediaPlayerService(40): Couldn't open fd for content://settings/system/alarm_alert
08-05 19:40:00.403: E/MediaPlayer(781): Unable to to create media player
08-05 19:40:00.403: D/Ringtone(781): Problem opening; delegating to remote player
08-05 19:40:00.413: D/dalvikvm(341): GREF has increased to 201
08-05 19:40:00.423: D/MediaPlayer(341): Couldn't open file on client side, trying server side
08-05 19:40:00.443: E/MediaPlayerService(40): Couldn't open fd for content://settings/system/alarm_alert
08-05 19:40:00.443: E/MediaPlayer(341): Unable to to create media player
08-05 19:40:00.443: W/Ringtone(341): Remote playback not allowed: java.io.IOException: setDataSource failed.: status=0x80000000
08-05 19:40:00.443: D/Ringtone(341): Problem opening; delegating to remote player
08-05 19:40:00.453: W/Ringtone(341): Neither local nor remote playback available
08-05 19:40:06.553: D/dalvikvm(781): GC_CONCURRENT freed 585K, 14% free 4537K/5252K, paused 6ms+4ms, total 90ms
08-05 19:40:19.173: D/dalvikvm(781): GC_CONCURRENT freed 583K, 14% free 4541K/5252K, paused 5ms+18ms, total 92ms

至于媒体播放器方法。我也试过了。同样的问题。

4

0 回答 0