Android will pause playback (but not disconnect) after a while in the background, even if battery optimization is turned off

Description and Steps to reproduce

  1. Open AudioRelay on windows (as server) and android (as player). On android 14, give audiorelay all permissions. Turn on the software’s self-start and turn off battery optimization. Play a video on windows. Both of them work fine at this stage. I can hear the sound.
  2. On windows, pause the video. On android 14, switch to other apps and use them for a while. Wait for about 3 minutes.
  3. On windows, play the video again. You can see that the windows app and android still running and connecting. But no sound is playing by android.

Devices

Device A:
Windows 10
AudioRelay 0.27.5

Device B:
Xiaomi 13 Pro, MIUI 14, Android 14
AudioRelay 0.26.1

Logs that may help:
audiorelay.backend.log

2023-11-05 20:37:26.068 [INF] Changing process audiorelay-backend priority from High to Normal
2023-11-05 20:37:26.101 [INF] Changing process AudioRelay priority from High to Normal
2023-11-05 20:37:29.150 [INF] Starting a capture...
2023-11-05 20:37:29.157 [INF] Changing process audiorelay-backend priority from Normal to High
2023-11-05 20:37:29.162 [INF] Capture using the suggested format 16 bit PCM: 48kHz 2 channels
2023-11-05 20:37:29.186 [INF] Changing process AudioRelay priority from Normal to High
2023-11-05 20:38:03.806 [INF] Detected audio devices changes
2023-11-05 20:39:19.323 [INF] Detected audio devices changes
2023-11-05 20:39:28.708 [INF] Detected audio devices changes
2023-11-05 20:52:57.271 [INF] Detected audio devices changes
2023-11-05 20:52:57.281 [INF] Stopping the capture...
2023-11-05 20:52:57.399 [INF] Starting a capture...
2023-11-05 20:52:57.399 [INF] Stopping the capture...
2023-11-05 20:52:57.399 [INF] Starting a capture...
2023-11-05 20:52:57.420 [INF] Capture using the suggested format 16 bit PCM: 48kHz 2 channels
2023-11-05 20:52:59.222 [INF] Detected audio devices changes
2023-11-05 20:52:59.232 [INF] Stopping the capture...
2023-11-05 20:52:59.348 [INF] Starting a capture...
2023-11-05 20:52:59.348 [INF] Stopping the capture...
2023-11-05 20:52:59.348 [INF] Starting a capture...
2023-11-05 20:52:59.367 [INF] Capture using the suggested format 16 bit PCM: 48kHz 2 channels
2023-11-05 20:53:00.695 [INF] Detected audio devices changes
2023-11-05 21:01:02.824 [INF] Detected audio devices changes
2023-11-05 21:01:04.016 [INF] Detected audio devices changes
2023-11-05 21:01:24.001 [INF] Detected audio devices changes
2023-11-05 21:01:26.249 [INF] Detected audio devices changes
2023-11-05 21:12:05.600 [INF] Detected audio devices changes
2023-11-05 21:12:09.983 [INF] Detected audio devices changes
2023-11-05 21:12:13.764 [INF] Detected audio devices changes
2023-11-05 21:12:41.148 [INF] Detected audio devices changes
2023-11-05 21:13:04.871 [INF] Detected audio devices changes
2023-11-05 21:14:56.054 [INF] Detected audio devices changes

audiorelay.log

2023-11-05 20:37:27:434 [INFO] Remote device connected: 192.168.1.194
2023-11-05 20:37:27:437 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:27:593 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:27:618 [INFO] Remote device connected: 192.168.1.194
2023-11-05 20:37:27:799 [INFO] Remote device connected: 192.168.1.194
2023-11-05 20:37:27:954 [INFO] Remote device connected: 192.168.1.194
2023-11-05 20:37:28:127 [INFO] Remote device connected: 192.168.1.194
2023-11-05 20:37:28:435 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:28:621 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:28:807 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:28:960 [ERROR] Initial TCP communication failed: Pb0
	at Ob0.a(SourceFile:2)
	at lT0.a(SourceFile:154)
	at l8.b(SourceFile:4)
	at O7.a(SourceFile:43)
	at Wi0.b(SourceFile:14)
	at nk0.b(SourceFile:3)
	at pj0.run(SourceFile:68)
	at MG0.invoke(SourceFile:1)
	at bT.invokeSuspend(SourceFile:6)
	at bT.invoke(SourceFile:1)
	at ki1.a(SourceFile:136)
	at a0.a(SourceFile:41)
	at OG0.a(SourceFile:139)
	at NG0.invoke(SourceFile:2)
	at Hu.invokeSuspend(SourceFile:12)
	at jUr4.resumeWith(SourceFile:5)
	at Eu.run(SourceFile:163)
	at Q40.run(SourceFile:4)
	at Ba1.run(SourceFile:1)
	at Yj.run(SourceFile:19)
2023-11-05 20:37:29:149 [INFO] Received client config, clientVersion: 0.26.1, os: ANDROID, osVersion: Android API 34
2023-11-05 20:37:29:150 [INFO] Asking backend to start capture. EventSync: false, ContinuousStream: true, AudioConfig: AudioConfig(sampleRate=48000, bits=16, channels=2), AudioDevice: Realtek Digital Output (Realtek(R) Audio), 
2023-11-05 20:37:29:659 [INFO] Audio pipeline is emitting values
2023-11-05 20:52:57:280 [INFO] Asking backend to stop capture...
2023-11-05 20:52:57:280 [INFO] Windows' backend devices: [WindowsAudioDevice(id={0.0.0.00000000}.{d8993cf6-0597-46c6-8ebe-e10327bcd3c9}, type=Render, name=Realtek Digital Output (Realtek(R) Audio), isDefault=true, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.1.00000000}.{b595aa7f-9b12-47c8-affb-5bb45505755c}, type=Capture, name=Virtual Mic (Virtual Mic for AudioRelay), isDefault=false, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.0.00000000}.{139cf6d8-2d2a-444a-8714-1fb9c3777d11}, type=Render, name=Virtual Speakers (Virtual Speakers for AudioRelay), isDefault=false, sampleRate=48000, channels=2)]
2023-11-05 20:52:57:281 [INFO] Asking backend to start capture. EventSync: false, ContinuousStream: true, AudioConfig: AudioConfig(sampleRate=48000, bits=16, channels=2), AudioDevice: Realtek Digital Output (Realtek(R) Audio), 
2023-11-05 20:52:57:281 [INFO] Asking backend to stop capture...
2023-11-05 20:52:57:282 [INFO] Asking backend to start capture. EventSync: false, ContinuousStream: true, AudioConfig: AudioConfig(sampleRate=48000, bits=16, channels=2), AudioDevice: Realtek Digital Output (Realtek(R) Audio), 
2023-11-05 20:52:59:232 [INFO] Windows' backend devices: [WindowsAudioDevice(id={0.0.0.00000000}.{51aa7506-54c9-4e9a-bcc4-f3bada01e053}, type=Render, name=Q2401W1 (NVIDIA High Definition Audio), isDefault=false, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.0.00000000}.{d8993cf6-0597-46c6-8ebe-e10327bcd3c9}, type=Render, name=Realtek Digital Output (Realtek(R) Audio), isDefault=true, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.0.00000000}.{22f0a270-9d67-4ea1-bb0c-d72799e143c5}, type=Render, name=U28P2G6B (NVIDIA High Definition Audio), isDefault=false, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.1.00000000}.{b595aa7f-9b12-47c8-affb-5bb45505755c}, type=Capture, name=Virtual Mic (Virtual Mic for AudioRelay), isDefault=false, sampleRate=48000, channels=2), WindowsAudioDevice(id={0.0.0.00000000}.{139cf6d8-2d2a-444a-8714-1fb9c3777d11}, type=Render, name=Virtual Speakers (Virtual Speakers for AudioRelay), isDefault=false, sampleRate=48000, channels=2)]
2023-11-05 20:52:59:232 [INFO] Asking backend to stop capture...
2023-11-05 20:52:59:233 [INFO] Asking backend to start capture. EventSync: false, ContinuousStream: true, AudioConfig: AudioConfig(sampleRate=48000, bits=16, channels=2), AudioDevice: Realtek Digital Output (Realtek(R) Audio), 
2023-11-05 20:52:59:233 [INFO] Asking backend to stop capture...
2023-11-05 20:52:59:233 [INFO] Asking backend to start capture. EventSync: false, ContinuousStream: true, AudioConfig: AudioConfig(sampleRate=48000, bits=16, channels=2), AudioDevice: Realtek Digital Output (Realtek(R) Audio),