-2

How to run an audio file instantly when clicking on the application button and not when button returns with Android Media Player

Any help is welcome because I did not find solution.

denis
  • 140
  • 1
  • 8
  • 1
    Can you be more specific? Or at least show us what you already tried and didn't work? – BugaIulian Jul 02 '14 at 18:10
  • Maybe there is a click event to do the audio file to run in the act of click. In my code it runs only when you remove your finger from the button.. see image http://gamesantigos.com/android/pics/1.jpg – denis Jul 02 '14 at 18:38

1 Answers1

0

1.you add button 2.

public class Setting extends Activity implements OnClickListener{

private MediaPlayer Music;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_setting);

Music = MediaPlayer.create(this, R.raw.musicname);

findViewById(R.id.button).setOnClickListener(this);

}

public void onClick(View view) {

    if (view.getId() == R.id.button) {
    Music.start();
    }    

}

}

only Preview :D

  • I could not! I'm out of time and I'll come back another day! Thank you – denis Jul 02 '14 at 18:59
  • Try this when my old code not work : http://stackoverflow.com/questions/2615616/triggering-event-when-button-is-pressed-down-in-android – user3772588 Jul 02 '14 at 19:35
  • I modified the method OnClickListener to OnTouchListener and it worked thank you all. – denis Jul 04 '14 at 12:57