Android MediaPlayer 在 onCompletionListener 后停止播放

问题描述

我的应用正在使用 MediaPlayer 播放音乐。 我的应用程序在 AndroidManifest.xml 中有“android.permission.WAKE_LOCK”。 我的手机已关闭“自适应电池”、“省电模式”和“省电排除”设置。 当手机连接到充电器时,我的应用程序工作正常。 但。 当手机没有连接到充电器并且当“onCompletionListener”被调用并将下一首歌曲加载到 MediaPlayer 时,它会停止播放。如果从桌子上拿起手机——不要打开屏幕,只需移动手机——它会继续播放。

我创建了一个计时器,每 500 毫秒调用一次我的程序。 此过程检查播放器是否正在播放,并且是曲目的第一秒还是曲目的最后一秒,它将信息写入日志。 因此,当手机正在充电并且应用程序运行良好时,我可以看到该过程正在写入日志,例如

21:45:50.123 playing 2 ms of 100000
21:45:50.723 playing 502 ms of 100000
... 9 minutes of music...
21:45:59.007 playing 999012 ms of 100000
21:45:59.600 playing 999789 ms of 100000
...then next song is loaded...

当手机没有充电并且 MediaPlayer 停止播放时,它看起来像

21:45:50.123 playing 2 ms of 100000
21:45:50.126 playing 6 ms of 100000
21:45:50.130 playing 8 ms of 100000
21:45:50.132 playing 10 ms of 100000
.... and many many times like this. 

所以看起来我的计时器程序不是每 500 毫秒调用一次,而是每 2 或 3 毫秒调用一次。

日志的时间戳取自 currentTimeMillis();

我也写日志

Thread.currentThread().getId() (it's the same thread every time)
PowerManager.isdeviceidleMode() (no,it is not idle)
and PowerManager.isPowerSaveMode() (no it is not)

请帮帮我 - 我该怎么做才能阻止 MediaPlayer 停止?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)