我有一个应用收音机,它使用exoplayer几乎可以很好地完成工作,但是当后台广播中的电话播放大约10-20分钟并停下来并且我打开电话广播时,继续播放。如何以编程方式修复它?Mediaplayer有一个类似setWakeMode()的方法,但Exoplayer却找不到。对不起,我的英语
我在exoPlayer上遇到了同样的问题,当手机屏幕锁定AudioTrack几分钟后关闭时,因此您可以在代码中添加WakeLock或WifiLock以使exoplayer在后台运行,甚至如果手机的屏幕已锁定。
if (intent.getAction().equals(ACTION_PLAY)) {
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager.requestAudioFocus(this,
AudioManager.STREAM_MUSIC,
AudioManager.AUDIOFOCUS_GAIN) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
wifiLock = ((WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock");
wifiLock.acquire();
if(exoPlayer == null){
//Your code Exoplayer her
}
} else if (action.equalsIgnoreCase(ACTION_STOP)) {
if (exoPlayer != null) {
exoPlayer.stop();
}
if (wifiLock != null && wifiLock.isHeld()) {
wifiLock.release();
}
}
}