我使用MediaOnCompletionListener来释放对象,所以它非常重要。但是,正如您从下面的logcat片段中看到的那样,它并不总是被触发!!
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 :(得分:0)
不确定,但也许 Garbage Collection causes : MediaPlayer finalized without being released 会给出一个线索。
人们发现在某些情况下,玩家在被释放之前会被垃圾收集。也许,onCompletionListener并没有为已经垃圾收集的玩家调用。