Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-24973

iOS: Background audio-recording not working when screen is locked

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 7.5.0
    • Component/s: iOS
    • Labels:
      None

      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
      {code:js}
      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.

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              hknoechel Hans Knöchel
              Tester:
              Samir Mohammed
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Source Code