2

I am working on application when touch it, it plays audio. But after 10,14 times later it not working, any idea ?

// on touch method

   img.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                anim_value = true;
                handler.post(runnable);
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                anim_value = false;
                handler.post(runnable);
            }
            return true;
        }
    });

// play inside thread

   Runnable runnable = new Runnable() {
    @Override
    public void run() {
        if (anim_value) {
            mp = MediaPlayer.create(MainActivity.this,
                    R.raw.tasbi_tick_tick);
            mp.start();
            tasbiCounts = (1 + tasbiCounts);
            tasbeeh_count.setText(tasbiCounts);
            animationTasbeeh.start();
            Log.d("AUDIO", "CALL");
        } else {
            animationTasbeeh.stop();
            mp.stop();
            mp = MediaPlayer.create(MainActivity.this,
                    R.raw.tasbi_tick_tick);
        }
    }
};
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Mushtaq Rahim
  • 129
  • 1
  • 13

1 Answers1

0

Their have may solution according to your question

method-1 simply you can override on touch method by touching sound is started.

method-2 you can also use runnable tread or run method

method-3 here we run a thread whenever you touch view, it check isPress or not if view is touched then sound is repeated until unless when you release view from touch.

Your solution here

Community
  • 1
  • 1
Attaullah
  • 3,856
  • 3
  • 48
  • 63