Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ExoPlayer停止在后台播放_Android_Exoplayer - Fatal编程技术网

Android ExoPlayer停止在后台播放

Android ExoPlayer停止在后台播放,android,exoplayer,Android,Exoplayer,我有一个应用程序,它保存了一个ExoPlayer实例的全局实例,以便在后台处理音频流。 打开大量应用程序后,音频停止播放 发生的情况如下: 打开开始播放音频的活动 按后退按钮关闭活动 如果您不使用设备,音频仍在播放,并将继续播放(如预期的那样) 然而,当你在最后一步后打开十几个或更多的应用程序时,ExoPlayer会在某个时候停止播放。 我的猜测是内存清理发生了,因此ExoPlayer被释放。我试图从日志中获取更多信息,但到目前为止没有什么帮助 在android.app.Service中保留

我有一个应用程序,它保存了一个ExoPlayer实例的全局实例,以便在后台处理音频流。 打开大量应用程序后,音频停止播放

发生的情况如下:

  • 打开开始播放音频的
    活动
  • 按后退按钮关闭
    活动
  • 如果您不使用设备,音频仍在播放,并将继续播放(如预期的那样)
然而,当你在最后一步后打开十几个或更多的应用程序时,ExoPlayer会在某个时候停止播放。 我的猜测是内存清理发生了,因此ExoPlayer被释放。我试图从日志中获取更多信息,但到目前为止没有什么帮助

android.app.Service
中保留ExoPlayer的引用没有什么区别

我正在测试的设备是带有安卓5.1.x的Nexus5,但问题也发生在其他设备上


我无法在ExoPlayer页面或StackOverflow或Google上找到解决方案。有人知道防止ExoPlayer停止播放的正确方法吗?

要确保
服务在不被系统杀死的情况下尽可能保持活动状态,您需要确保将其作为主机启动

这意味着将有一个通知通知用户活动服务,以便用户能够知道它。因此,您必须使用相应的通知启动服务。以下是文档中的示例:

Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
            System.currentTimeMillis()); 
Intent notificationIntent = new Intent(this, ExampleActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
notification.setLatestEventInfo(this, getText(R.string.notification_title),
            getText(R.string.notification_message), pendingIntent); 
startForeground(ONGOING_NOTIFICATION_ID, notification);

你试过把它放在前台的
服务上吗?
?是的,我试过在
android.app.Service
中保留它的引用。我想知道如果它是从该服务中创建的,是否会有所不同……我不是指任何服务,而是从中开始的。谢谢,我会尝试的!非常感谢您的知识+1@AnkitAggarwal这个代码块在你的终端工作吗?对于未来的访问者:Android 8.0+需要频道id来通知。这里有更多信息。