Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int playSound(int file) {
- int duration = 1000;
- sound = new MediaPlayer();
- AssetFileDescriptor fd = getResources().openRawResourceFd(file);
- try {
- sound.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
- sound.prepare();
- sound.start();
- sound.setOnCompletionListener(new OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer mp) {
- // Do the work after completion of audio
- Toast.makeText(GameActivity.this, "good", Toast.LENGTH_SHORT).show();
- mp.release();
- }
- });
- duration = sound.getDuration();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalStateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return duration;
- }
- media.setVolume(0,0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement