opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
211 stars 169 forks source link

[OPENTOK-42902] Issue with Audio when minimizing app #371

Closed marcqtan closed 1 year ago

marcqtan commented 3 years ago

I'm using opentok to publish and subscribe to audio and video, but there's an issue with publishing audio after putting the application in the background (minimize), it stops working.

The audio stops working at exactly 1 minute after minimizing the device.

Note: I can still hear other audio publishers.

The audio works again as soon as I put the app in the foreground.

Logs:

2021-02-17 18:24:24.945 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:24:24.945 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:24:25.427 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:24:25.428 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:1)
2021-02-17 18:24:25.428 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:1)

minimized the app and after 1 minute:

2021-02-17 18:25:25.430 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:0)
2021-02-17 18:25:25.436 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:0)
2021-02-17 18:25:25.437 1267-1645/? V/AudioService.RecordingActivityMonitor: updateSoundAppPolicy packageName = com.testonly.package
2021-02-17 18:25:25.440 14736-14844/? I/A: Mic not exclusive, user is in voice call or video recording.

As you can see the state is set to 0? I'm not sure what that means. But that's the reason why the audio cannot be heard anymore. It seems like the microphone of the device is being muted?

And as soon as I put the app again in the foreground, I'm receiving this logs: As you can see it is setting it to state: 2 again. The audio works now at this point.

2021-02-17 18:28:43.200 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:0)
2021-02-17 18:28:43.200 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:0)
2021-02-17 18:28:43.200 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:28:43.203 30465-30480/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:28:43.682 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)
2021-02-17 18:28:43.683 30465-30481/? V/APM_AudioPolicyManager: setAppState(uid:10552, state:2)

Device: Samsung Galaxy A31 - Android 10 Opentok version: 2.18.1, also tried 2.15.3 and still got the same issue.

marcqtan commented 3 years ago

any update on this? I think i should use foreground service? I've researched and found the values for appState. https://android.googlesource.com/platform/system/media/+/master/audio/include/system/audio_policy.h

typedef enum {
   APP_STATE_IDLE = 0,   /* client is idle: cannot capture */
  APP_STATE_FOREGROUND, /* client has a foreground service: can capture */
  APP_STATE_TOP, /* client has a visible UI: can capture and select use case */
  } app_state_t;
igorwojda commented 3 years ago

We are taking a look at this @marcqtan

v-kpheng commented 1 year ago

@marcqtan, apologies for the belated reply.

This isn't a bug. When an application is minimized, there's privacy concerns if it continues to capture audio.

cc'ing @kapilmishr, @Daniel085, since this is a product question.