I am new to Android Auto and still trying to figure it out. I have successfully played music from my own programmed app but the music is coming out from my smartphone speakers instead of car speakers. Other (sample) apps do it the right way.
Which part of of the Media System is responsible to handle this behaviour? Android documentation says the sound is sent to the car speakers.
@Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
this.mPlayingQueue.add(item);
session.setActive(true);
session.setQueue(mPlayingQueue);
session.setQueueTitle("My Queue");
session.setPlaybackState(buildState(PlaybackState.ACTION_PLAY));
session.setMetadata(createRammsteinMetaData());
this.mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.rammstein_sonne);
this.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (tryToGetAudioFocus()) {
this.mediaPlayer.start();
Log.d("AUDIOTAG", "Playing");
} else {
Log.d("AUDIOTAG", "Playing not possible, no focus");
}
}
private boolean tryToGetAudioFocus() {
int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
Thanks in advance. Orrimp