Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Discussion > Android Lounge

Android Lounge A place for general Android discussion and questions.



Reply
 
LinkBack Thread Tools
Old February 11th, 2012, 07:52 PM   #1 (permalink)
New Member
 
Join Date: Feb 2012
Posts: 1
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default AUDIO PLAYING IN DIFFERENT BUTTON onTouch USING SOUND POOL

I WOULD LIKE TO ASK, I'M CURRENTLY WORKING ON A PROJECT AND I JUST WANT TO KNOW
I HAVE 2 BUTTONS, AND I WANT TO PLAY 2 DIFFERENT SOUNDS ON EACH. BUT I'M GETTING THE SAME SOUND ALTHOUGH IN MY RESOURCE FOR AUDIO IS DIFFERENT FROM ONE ANOTHER...


PLEASE CHECK IF I COMMIT A MISTAKE

HERE'S THE CODE



import android.app.Activity;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.media.SoundPool.OnLoadCompleteListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class Mobile_guitarActivity extends Activity implements OnTouchListener {
public SoundPool soundpool, soundpool2, soundpool3;
public int soundID, soundID2, soundID3;
boolean loaded = false,loaded2 = false, loaded3 = false;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


//button25
View view = findViewById(R.id.button25);
Button bSoundButton1 = (Button) findViewById(R.id.button25);
bSoundButton1.setVisibility(View.VISIBLE);
bSoundButton1.setBackgroundColor(Color.TRANSPARENT );
bSoundButton1.setTextColor(Color.TRANSPARENT);
view.setOnTouchListener(this);
this.setVolumeControlStream(AudioManager.STREAM_MU SIC);
soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundpool.setOnLoadCompleteListener(new OnLoadCompleteListener(){

public void onLoadComplete(SoundPool soundpool, int sampleId, int status ){
loaded = true;
}
});
soundID = soundpool.load(this, R.raw.s_1, 1);

//button 26
View view2 = findViewById(R.id.button26);
Button bSoundButton2 = (Button) findViewById(R.id.button26);
bSoundButton2.setVisibility(View.VISIBLE);
bSoundButton2.setBackgroundColor(Color.TRANSPARENT );
bSoundButton2.setTextColor(Color.TRANSPARENT);
view2.setOnTouchListener(this);
this.setVolumeControlStream(AudioManager.STREAM_MU SIC);
soundpool2 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);

soundpool2.setOnLoadCompleteListener(new OnLoadCompleteListener(){
public void onLoadComplete(SoundPool soundpool2, int sampleId2, int status2)
{loaded2 = true;}
});
soundID2 = soundpool2.load(this, R.raw.s_2, 1);


public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
AudioManager audioManager1 = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualvolume = (float) audioManager1.getStreamVolume(AudioManager.STREAM_ MUSIC);
float maxvolume = (float) audioManager1.getStreamMaxVolume(AudioManager.STRE AM_MUSIC);
float volume = actualvolume/maxvolume;

if(loaded){
soundpool.play(soundID, volume, volume, 1, 0, 1f);
Log.e("Test", "Played Sound");
}
}
return false;
}

public boolean onTouch1(View v1, MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
AudioManager audioManager2 = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualvolume2 = (float)audioManager2.getStreamVolume(AudioManager. STREAM_MUSIC);
float maxvolume2 = (float) audioManager2.getStreamMaxVolume(AudioManager.STRE AM_MUSIC);
float volume2 = actualvolume2/maxvolume2;

if(loaded2){
soundpool2.play(soundID2, volume2, volume2, 2, 1, 2f);
Log.e("Test2","Played Sound2");
}
}
return false;
}

rainmark is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Discussion > Android Lounge User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 01:48 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo