Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development

Reply
Highlighted
Contributor
Posts: 34
Registered: ‎10-26-2010
My Device: Not Specified

Play audio file in phone handset

Hi!

I need to play an mp3 file without using loudspeaker, but using the handset.

This is my sample code

Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View v) {
		AudioManager audioService = (AudioManager) MainActivity.this.getSystemService(Context.AUDIO_SERVICE);
		audioService.setMode(AudioManager.MODE_IN_CALL);
		audioService.setSpeakerphoneOn(false); 
		MediaPlayer inCallMediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.file);
		inCallMediaPlayer.start();
		
	}
});

All works fine, but the "setSpeakerPhoneOn(false)" is completely ignored. The audio file is played in phone loudspeaker. It seems a platform bug

There is a way to play an audio file in phone handset?