RSDMotionAudioSessionController

public final class RSDMotionAudioSessionController : NSObject, RSDAudioSessionController

The audio session controller to use when recording motion sensor data in the background with the phone screen locked.

Note

Using this audio session controller includes playing an audio file in the background in order to keep the app responsive to step transitions and voice commands. Without the audio playing in the background or the use of GPS, the app will stop responding to timing events.
  • The audio session is a shared pointer to the current audio session (if running). This is used to allow background audio. Background audio is required in order for an active step to play sound such as voice commands to a participant who make not be looking at their screen.

    For example, a Walk and Balance task that measures gait and balance by having the participant walk back and forth followed by having them turn in a circle would require turning on background audio in order to play spoken instructions even if the screen is locked before putting the phone in the participant’s pocket.

    Note

    The application settings will need to include setting capabilities appropriate for background audio if this feature is used.

    Declaration

    Swift

    public private(set) var audioSession: AVAudioSession? {
      get
      }
  • The audio player that plays the background sound used to keep the motion sensors active. This is a work-around to allow the task to continue running in the background without requiring GPS by instead playing an audio file of silence.

    Note

    As of this writing, speech-to-text using the AVSpeechSynthesizer will not run in the background after 5 seconds and turning on background audio using AVAudioSession is not enough to keep any timers running. syoung 05/21/2019

    Declaration

    Swift

    public private(set) var audioPlayer: AVAudioPlayer! {
      get
      }
  • Start the background audio session if needed. This will look to see if audioSession is already started and if not, will start a new session.

    Declaration

    Swift

    public func startAudioSessionIfNeeded()
  • Stop the audio session and audio player.

    Declaration

    Swift

    public func stopAudioSession()