Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


A simultaneous playback of media stream and a local media file to BT headphone

It is necessary to set the attribute AudioAttributes.USAGE_VOICE_COMMUNICATION and request audio focus for a mediaplayer in application to play simultaneously a media stream from server and a local media file from device to Bluetooth headphone, for example

Code Block
                                                         * Audio focus example
                                                        MediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.sound1);

                                                          *    Audio focus example
new AudioAttributes.Builder()
                                                                MediaPlayer  music = MediaPlayer.create(getBaseContextbuild(), R.raw.sound1);
                                                        AudioManager.OnAudioFocusChangeListener audioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
                                                            public void onAudioFocusChange(int focusChange) {
                                                                Log.d("AudioFocus,", "onAudioFocusChange="+focusChange);
                                                                music.setVolume(1, 1);
                                                        // Request audio focus for playback
                                                        int requestResult = Flashphoner.getAudioManager().getAudioManager().requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
                                                        Log.d("AudioFocus,", "requestResult="+requestResult);
                                                        // Abandon audio focus when playback complete
                                                        music.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                                                            public void onCompletion(MediaPlayer mp) {