2012-12-31 57 views
1

我使用MediaOnCompletionListener來釋放對象,所以它非常重要。但是,正如您從下面的logcat代碼片段中看到的那樣,它並不總是觸發的!爲什麼MediaPlayer的onCompletionListener如此不可靠?

12-30 17:24:41.448: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:41.638: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:41.818: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:49.866: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:24:50.136: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:24:50.186: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:24:55.902: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:56.152: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:56.322: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:24:56.552: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:25:04.340: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:25:04.560: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:25:04.670: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:25:04.910: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:25:37.312: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:25:37.592: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:25:37.773: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:25:37.953: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:25:46.161: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:25:46.351: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:26:09.423: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:26:35.108: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:26:42.215: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:26:50.594: I/myApp(5117): MediaOnCompletionListener triggered 
12-30 17:27:17.059: I/myApp(5117): playSound(/mnt/sdcard/audio/clong-1.mp3 VolumePercent:100) 
12-30 17:27:25.448: I/myApp(5117): MediaOnCompletionListener triggered 

我在Android 2.3.5 測試這這是一個已知的問題? MediaPlayer的可靠性在更高版本的Android上有所提高嗎?

+0

您確定在沒有打印日誌的情況下,您的'OnCompletionListener'實際上已註冊到'MediaPlayer'嗎?可能需要附加一個調試器來確認相關字段在運行時是否爲非null。或者,IIRC,如果您在播放過程中的某個時刻設置了'setLooping(true)',則在每個'循環'後都不會使用回調(除非在完成之前將其設置回「false」)。 –

+0

當OnCompleition觸發時,確定啓動MediaPlayer的線程仍處於活動狀態嗎? 檢查此問題可能有所幫助: http://stackoverflow.com/questions/13875146/ensure-mediaplayer-oncompletionlistener-is-called-and-the-thread-is-not-dead/14061862#14061862 – iTech

回答

相關問題