Android - Play audio from earpiece

后端 未结 7 1984
旧巷少年郎
旧巷少年郎 2020-12-02 08:27

I\'d like to play audio from a file into the phone\'s earpiece (or headset of that is connected) using the android MediaPlayer. I tried using the MODE_IN_CALL h

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 09:13

    I found i needed to set both the mediaplayer and Audiomanager

    private MediaPlayer mp = new MediaPlayer();
    AudioManager mAudioManager = (AudioManager) v.getContext()
                                    .getSystemService(Context.AUDIO_SERVICE);
                            mAudioManager.setSpeakerphoneOn(false);
                            mp.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
    

提交回复
热议问题