Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24973] iOS: Background audio-recording not working when screen is locked

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-07-03T16:39:39.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.5.0
ComponentsiOS
Labelsn/a
ReporterHans Knöchel
AssigneeHans Knöchel
Created2017-07-18T03:50:55.000+0000
Updated2018-09-13T11:07:57.000+0000

Description

This bug is very easy to reproduce, just follow the step below: 1. Add below code into tiapp.xml
<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
</array>
2. Using the blow code to do the testing
var win = Ti.UI.createWindow({ width: Ti.UI.FILL, height: Ti.UI.FILL, backgroundColor: '#fff' }); var recorder = Ti.Media.createAudioRecorder({ format: Titanium.Media.AUDIO_FILEFORMAT_WAVE, compression: Ti.Media.AUDIO_FORMAT_ULAW }) var startBtn = Ti.UI.createButton({ top: 50, title: 'start' }) var playBtn = Ti.UI.createButton({ top: 100, title: 'play' }) var stopBtn = Ti.UI.createButton({ top: 150, title: 'stop' }) var file; startBtn.addEventListener('click', function() { Titanium.Media.audioSessionCategory = Ti.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD recorder.start() }) playBtn.addEventListener('click', function() { Titanium.Media.audioSessionCategory = Titanium.Media.AUDIO_SESSION_CATEGORY_PLAYBACK var sound = Ti.Media.createSound({ url: file, allowBackground: true }); sound.play() }) stopBtn.addEventListener('click', function() { file = recorder.stop() }) win.add(startBtn) win.add(playBtn) win.add(stopBtn) win.open() ``` 3. Press the start button and lock the screen by press the power button of iPhone, the screen will be locked. Let me tell you what will happen after this - if you unlock the screen less than 10 seconds after you lock, everthing is fine - try to waiting more than 10 seconds before you unlocking your device, for example 30 seconds, you'll got a blank record, when you try to play this record it will never stop even thoung it's a blank file. *root cause* Everytime we start a new recording, a temp file will be created, however, the "ProtectionKey" is not set properly, so after the screen being locked, we don't have correct rights to write into that file, so we just unprotect this temp file to fix this bug. uh..., how does the magic "10 seconds" comes up? As we are know, iOS will left about 10 seconds to every app runing on it to do the cleanup thing before the system pause it(e.g. home button pressed), so if we unlock our device again shortly after we lock it everthing will be fine cause our App is stilling running in "foreground" now. Sorry for my broken English, hopes you guys understand it. If you have any question please let'me know, Thanks.

Comments

  1. Hans Knöchel 2018-06-28

  2. Samir Mohammed 2018-09-13

    *Closing ticket.* Verified improvement in SDK version: 7.5.0.v20180912080426. Background audio now records when the screen is locked for extended periods of time. *FR Passed (Test Steps):*

    Created a new Titanium application

    Added the code above in to the application

    Installed app on to the device

    Ran the app

    Pressed start

    Locked the screen

    waited about 2 minutes

    unlocked the screen

    pressed stop

    Navigated to the app

    pressed play

    able to hear the background recording where previously the application would close and the recording would be blank

    *Environment*
       APPC Studio:  5.1.0.201808080937
       APPC CLI: 7.0.6
       iphone 6 (12.0)
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13.6
       Node.js Version: 8.9.1
       Xcode 10.0 beta 6
       

JSON Source