Reputation: 423
Hey I'm trying to play a R.raw file thru my earpiece instead of the main phone speaker on my app but everyhting I throw at it isn't working. WIht my current code... it just plays very light static through the earpiece and not the R.raw I want.
Here is my code below and I set it in the manifest: <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setSpeakerphoneOn(false);
am.setMode(AudioManager.MODE_IN_CALL);
MediaPlayer tellSecret = MediaPlayer.create(this, R.raw.secret);
tellSecret.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
tellSecret.start();
Any thoughts?
Upvotes: 3
Views: 4868
Reputation: 21
do not use 'create' api for media player, instead use 'setDataSource' and 'prepare' apis seperately. Also call 'setAudioStreamType' api on mediaplayer instance with STREAM_VOICE_CALL before calling 'setDataSource'.
In the end after starting media player, call setSpeakerphoneOn(false) on audio manager.
Upvotes: 1
Reputation: 892
Try setting the Audio Manager and the Media Player modes to be AudioManager.STREAM_MUSIC.
Upvotes: 1