Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package dissinyou.soundboard;
  2.  
  3. import android.app.Activity;
  4. import android.media.MediaPlayer;
  5. import android.os.Bundle;
  6. import android.view.MotionEvent;
  7. import android.view.View;
  8. import android.widget.Button;
  9.  
  10.  
  11. public class MainActivity extends Activity {
  12.    
  13.         private SoundManager mSoundManager;
  14.  
  15.     @Override
  16.     public void onCreate(Bundle savedInstanceState)
  17.     {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.        
  21.         mSoundManager = new SoundManager();
  22.         mSoundManager.initSounds(getBaseContext());
  23.         mSoundManager.addSound(1, R.raw.haha);
  24.        
  25.         final MediaPlayer mp = MediaPlayer.create(this, R.raw.haha);
  26.        
  27.        
  28.        
  29.        
  30.         findViewById(R.id.but3).setOnTouchListener(new View.OnTouchListener() {
  31.  
  32.             public boolean onTouch(View v, MotionEvent event) {
  33.                 findViewById(R.id.but3).setPressed(true);
  34.                 mp.setOnCompletionListener(this);
  35.                 mp.start();
  36.                 return true;
  37.             }
  38.  
  39.                
  40.             public void onCompletion(MediaPlayer mp) {
  41.                 findViewById(R.id.but3).setPressed(false);
  42.             }
  43.  
  44.         });
  45.      
  46.     }
  47. }