7

我注意到我在 Android 6.0 设备上的音频流应用程序存在问题。音频流是通过 HLS 通过网络连接完成的。音频播放发生在具有活动通知的前台服务中。我注意到的是,当应用程序进入打盹模式/应用程序待机时,wifi 连接丢失并且播放暂停。我的服务在前台,并且有一个活动通知,根据文档,应该使我的应用程序不被中断。我还获得并维护了一个 Wifi Lock。我已经阅读了有关将我的应用列入白名单的信息,但是像 Spotify 这样的应用不需要任何特殊权限来避免这个问题。有什么想法或建议吗?

4

1 回答 1

2

The recommended solution is to have separate processes, one for audio playback and for the UI. See this long thread for lots of details

Here's the relevant section from Ms Hackborn:

... have your foreground service run in a different process than the activity. From what I can see, this will work fine. I would be interesting in seeing if you get the desired behavior there.

Also this is actually our recommended practice for this situation -- if you have a long-running foreground service, it should be in a separate process from the activity, so it doesn't force all of the memory associated with the activity to be kept around. (This is also why this bug got through, all of our [Google] apps use this pattern.)</p>

于 2016-05-03T21:44:02.073 回答