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:
To stream audio from a SDL app, use the AudioStreamingManager
class. A reference to this class is available from the SdlManager
s audioStreamManager
property.
The AudioStreamManager
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.
To stream audio, we call sdlManager.getAudioStreamManager().start()
which will start the manager. When that callback returns with a success, call sdlManager.getAudioStreamManager().startAudioStream()
. Once this callback returns successfully you can send and play audio.
if (sdlManager.getAudioStreamManager() == null) { // Handle the failure return; } sdlManager.getAudioStreamManager().start(new CompletionListener() { @Override public void onComplete(boolean success) { if (!success) { // Failed to start audio streaming manager return; } sdlManager.getAudioStreamManager().startAudioStream(false, new CompletionListener() { @Override public void onComplete(boolean success) { if (!success) { // Failed to start audio stream return; } // Push Audio Source } }); } });
//Push from Uri Audio Source sdlManager.getAudioStreamManager().pushAudioSource(audioSourceUri, new CompletionListener() { @Override public void onComplete(boolean success) { if (success) { DebugTool.logInfo(TAG, "Audio Uri played successfully!"); } else { DebugTool.logInfo(TAG, "Audio Uri failed to play!"); } } }); //Push from Raw Audio Source sdlManager.getAudioStreamManager().pushResource(R.raw.exampleMp3, new CompletionListener() { @Override public void onComplete(boolean success) { if (success) { DebugTool.logInfo(TAG, "Audio file played successfully!"); } else { DebugTool.logInfo(TAG, "Audio file failed to play!"); } } });
//Push from ByteBuffer Audio Source sdlManager.getAudioStreamManager().pushBuffer(byteBuffer, new CompletionListener() { @Override public void onComplete(boolean success) { if (success) { DebugTool.logInfo(TAG, "Buffer played successfully!"); } else { DebugTool.logInfo(TAG, "Buffer failed to play!"); } } });
When the stream is complete, or you receive HMI_NONE
, you should stop the stream by calling:
sdlManager.getAudioStreamManager().stopAudioStream(new CompletionListener() { @Override public void onComplete(boolean success) { // do something once the stream is stopped } });