0

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);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • See this post https://stackoverflow.com/questions/28191266/android-how-to-delay-an-audio-file-by-a-few-seconds – ShehrozEK Nov 24 '18 at 11:37
  • Thanks @Shehroz, sorry but the above code snippet is used inside other handler.means this handler is used inside other handler.so is it wrong way to use handler within handler?? – Mahesh Walke Nov 28 '18 at 05:36

0 Answers0