Created
February 23, 2019 08:36
-
-
Save mnaraniya/5c8b04ff1473d96073f1023437bceb94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
//set up MediaPlayer | |
MediaPlayer mp = new MediaPlayer(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Button stop = findViewById(R.id.stop); | |
stop.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
mp.reset(); | |
} | |
}); | |
Button button1 = (Button) findViewById(R.id.button1); | |
button1.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
playAudio(R.raw.aa); | |
} | |
}); | |
} | |
private void playAudio(final int path) { | |
mp.reset(); | |
mp = MediaPlayer.create(getApplicationContext(), path); | |
mp.start(); | |
Toast.makeText(MainActivity.this, "playing", | |
Toast.LENGTH_SHORT).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment