Question

I've tried to follow the other questions, but I don't think that they are what I am looking for.

Here's my java: http://pastie.org/private/psy2nnys8i0ajz4i8qfw

I know I am opening multiple instances of mp, so I try to detect if one is playing, and stop it on lines 34-39, but it still overlaps

please advise. I tried singleton's - but that didn't work, I also tried to use one mediaplayer instance and set the datasource, but couldnt figure out how to pass the R.raw.clipname to it.

Thanks!

Was it helpful?

Solution

It would be somehow hard to try and debug/trace your code. But I can give you a solution to open a raw resource in your MediaPlayer, which will also make your code more robust and simple :

MediaPlayer player=new MediaPlayer();
player.setDataSource(
    getResources().openRawResourceFd(R.raw.clip1).getFileDescriptor());

OTHER TIPS

USE THIS ONE:

@Override

public boolean onTouch(View v, MotionEvent event) {
     switch (event.getAction()) {
     case MotionEvent.ACTION_UP://int end
         pv.stop();
         pv.reset();
         pv=MediaPlayer.create(MainActivity.this,R.raw.slot);
         Toast.makeText(this,"stop",Toast.LENGTH_SHORT).show();
         break;
     case MotionEvent.ACTION_DOWN://in start
         pv.start();
         Toast.makeText(this,"play",Toast.LENGTH_SHORT).show();
         break;
     default:
         break;
     }
     return false;
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top