Expand Minimize Picture-in-picture Power Device Status Voice Recognition Skip Back Skip Forward Minus Plus Play Search
Internet Explorer alert
This browser is not recommended for use with smartdevicelink.com, and may not function properly. Upgrade to a different browser to guarantee support of all features.
close alert
To Top Created with Sketch. To Top
To Bottom Created with Sketch. To Bottom
iOS Guides
Audio Streaming

Audio Streaming

A navigation app can stream raw audio to the head unit. This audio data is played immediately. If audio is already playing, the current audio source will be attenuated and your audio will play. Raw audio must be played with the following parameters:

  • Format: PCM
  • Sample Rate: 16k
  • Number of Channels: 1
  • Bits Per Second (BPS): 16 bits per sample / 2 bytes per sample

To stream audio from a SDL app, use the SDLStreamingMediaManager class. A reference to this class is available from the SDLManager's streamManager property.

Audio Stream Manager

The SDLAudioStreamManager will help you to do on-the-fly transcoding and streaming of your files in mp3 or other formats, or prepare raw PCM data to be queued and played.

Starting the Audio Manager

Like the lifecycle of the video stream, the lifecycle of the audio stream is maintained by the SDL library, therefore, you do not need to start the audio stream if you've set a streaming configuration when starting your SDLManager. When you receive the SDLAudioStreamDidStartNotification, you can begin streaming audio.

Playing from File

[self.sdlManager.streamManager.audioManager pushWithFileURL:audioFileURL];
[self.sdlManager.streamManager.audioManager playNextWhenReady];
sdlManager.streamManager?.audioManager.push(withFileURL: url)
sdlManager.streamManager?.audioManager.playNextWhenReady()

Playing from Data

[self.sdlManager.streamManager.audioManager pushWithData:audioData];
[self.sdlManager.streamManager.audioManager playNextWhenReady];
sdlManager.streamManager?.audioManager.push(with: audioData)
sdlManager.streamManager?.audioManager.playNextWhenReady()

Implementing the Delegate

- (void)audioStreamManager:(SDLAudioStreamManager *)audioManager errorDidOccurForFile:(NSURL *)fileURL error:(NSError *)error {

}

- (void)audioStreamManager:(SDLAudioStreamManager *)audioManager errorDidOccurForDataBuffer:(NSError *)error {

}

- (void)audioStreamManager:(SDLAudioStreamManager *)audioManager fileDidFinishPlaying:(NSURL *)fileURL successfully:(BOOL)successfully {
    if (audioManager.queue.count != 0) {
        [audioManager playNextWhenReady];
    }
}

- (void)audioStreamManager:(SDLAudioStreamManager *)audioManager dataBufferDidFinishPlayingSuccessfully:(BOOL)successfully {
    if (audioManager.queue.count != 0) {
        [audioManager playNextWhenReady];
    }
}
func audioStreamManager(_ audioManager: SDLAudioStreamManager, errorDidOccurForFile fileURL: URL, error: Error) {

}

func audioStreamManager(_ audioManager: SDLAudioStreamManager, errorDidOccurForDataBuffer error: Error) {

}

func audioStreamManager(_ audioManager: SDLAudioStreamManager, fileDidFinishPlaying fileURL: URL, successfully: Bool) {
    if audioManager.queue.count != 0 {
        audioManager.playNextWhenReady()
    }
}

func audioStreamManager(_ audioManager: SDLAudioStreamManager, dataBufferDidFinishPlayingSuccessfully successfully: Bool) {
    if audioManager.queue.count != 0 {
        audioManager.playNextWhenReady()
    }
}

Manually Sending Data

Once the audio stream is connected, data may be easily passed to the Head Unit. The function sendAudioData: provides us with whether or not the PCM Audio Data was successfully transferred to the Head Unit. If your app is in a state that it is unable to send audio data, this method will return a failure. If successful playback will begin immediately.

NSData *audioData = <#Acquire Audio Data#>;

if (![self.sdlManager.streamManager sendAudioData:audioData]) {
    <#Could not send audio data#>
}
let audioData = <#Acquire Audio Data#>

guard let streamManager = self.sdlManager.streamManager, streamManager.isAudioConnected else { return }

if !streamManager.sendAudioData(audioData) {
    <#Could not send audio data#>
}
View on GitHub.com
Previous Section Next Section