Switcing audio output between speaker/handset

All your problems with Audio, Video and Images.

Switcing audio output between speaker/handset

Postby btdownloads7 » Thu Oct 28, 2010 4:18 am

I havd an app that plays an MP3 using the MediaPlayer class. I also have a button that's supposed to switch between the handset and the speaker, but I can't seem to get it working. I've set the MODIFY_AUDIO_SETTINGS permission in the manifest, and here's the code I use to switch the output:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public final int HANDSET = 0;
  3.         public final int SPEAKER = 1;
  4.  
  5.         AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
  6.         am.setMode(AudioManager.MODE_NORMAL);
  7.         btnAudioPath = (ImageButton) findViewById(R.id.btn_audio);
  8.  
  9.         btnAudioPath.setOnClickListener(new OnClickListener(){
  10.             @Override
  11.             public void onClick(View view) {
  12.                 if(y.audioPath == HANDSET){
  13.                         btnAudioPath.setImageResource(R.drawable.spkr_off);
  14.                         y.am.setSpeakerphoneOn(false);
  15.                 }else if(y.audioPath == y.SPEAKER){
  16.                         btnAudioPath.setImageResource(R.drawable.spkr_on);
  17.                         y.am.setSpeakerphoneOn(true);
  18.                 }
  19.             }
  20.         });
  21.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


The onClick event gets triggered, the button image changes, but the audio still comes through the speaker. What am I doing wrong?
btdownloads7
Freshman
Freshman
 
Posts: 2
Joined: Tue Oct 26, 2010 12:40 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 15 guests