How to play a tone repeatedly every 2 seconds?

69 Views Asked by At

My Question is about how i can play tone named beep_e.mp3 repeatedly with delay of 2 seconds.I am playing tone when i get value below 100 or above 200.So when value is i get 250 every time i want to play tone regularly but with delay of 2seconds.I tried below code but it is not working.plz help me in this.

            `  Handler handler=new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if(mp.isPlaying())
                {
                    mp.stop();
                }
                try {
                    mp.reset();
                    AssetFileDescriptor afd;
                    afd = getAssets().openFd("beep_e.mp3");
                    mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
                    mp.prepare();
                    mp.start();
                 } catch (IllegalStateException | IOException e) {
                    e.printStackTrace();
                }`    }
                },2000);
0

There are 0 best solutions below