Recording audio while device put to sleep

77 views
Skip to first unread message

Farley Lai

unread,
Sep 28, 2016, 11:56:34 AM9/28/16
to android-ndk

Hi,


I am looking for the way to record audio while the device is put to sleep just like the wake-up sensors. The Java APIs (AudioReocrd) does not provide the callback interface as OpenSL ES does. However, it is not clear whether the wakelock is automatically acquired and the device is woken up when the callback is invoked.  After conducted a simple audio recording experiment using both OpenSL ES and Android AudioRecord class on Nexus 6. Both APIs seem to acquire the wakelock internally and never releases it until the recording is stopped. Does this behavior depend on the driver implementation or the APIs intentionally acquire the wakelock for some essential reason? Can you give a definitive clarification?


Thanks

Farley

Glenn Kasten

unread,
Sep 28, 2016, 12:18:23 PM9/28/16
to android-ndk
First for your specific question: yes CPU wakelocks are taken when audio I/O is active.

Next I want to mention the user experience.

I'm more familiar with the playback (output) side so I'll start with that.  
As long as an app is actively playing audio, the app will wake up intermittently to continue to decoder/render and output the audio data.
This is how music players can work with screen off.  
They usually do their work in a service so that the app does not need to be displayed on screen for the music to keep playing.

However, though this may be a good user experience for music playback, it can be a bad user experience
in other situations such as when a game plays a background soundtrack but then continues playing
even when you move to another app.   
This is why you should handle onPause, and other activity transitions appropriately.

I think similar guidelines apply for recording, but in my opinion it is even more important to handle transitions
because of privacy concerns.  I've tried a few recording apps, and some pause recording when not in foreground,
but others can continue even when not displayed. I would prefer to use an app that made it clear when it was
recording, either with a dialog or a notification.
Reply all
Reply to author
Forward
0 new messages