Play sound every 6-10 seconds

Play sound every 6-10 seconds

By : Waseem Samkari
Date : November 18 2020, 01:01 AM
should help you out You can use MediaPlayer.OnCompletionListener to accomplish this, whenever the playback completes get a random number between 6 and 10 and post a runnable to start playback again after the calculated random time.
Here is an example of doing this.
code :
public class MainActivity extends Activity {
Button button1;
MediaPlayer mediaPlayer = null;
private final Random mRandom = new Random();
int delayMillis;
Handler handler;
Runnable runnable;
protected void onCreate(Bundle savedInstanceState) {
    button1 = (Button) findViewById(R.id.button1);
    handler = new Handler();
    runnable = new Runnable() {

        public void run() {

    button1.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {


private void toggleMediaPlayer(){
    if(mediaPlayer != null){
        mediaPlayer = MediaPlayer.create(this, R.raw.hangouts_incoming_call);
        mediaPlayer.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {

        mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
                delayMillis = 1000 * mRandom.nextInt(5) + 6;


Share : facebook icon twitter icon
how to play a sound for 5 seconds

how to play a sound for 5 seconds

By : Logan Albright
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , i want to play a sound for 5 seconds but the code which i am using is playing the sound infinitely. , Try to remove this line from your code
code :
Play sound in Chronometer after 30 seconds has passed

Play sound in Chronometer after 30 seconds has passed

By : Ike Gentz
Date : March 29 2020, 07:55 AM
help you fix your problem You need to implement a OnChronometerTickListener on your chronometer.
Here is an example:
code :
chronometer.setOnChronometerTickListener(new OnChronometerTickListener()
    public void onChronometerTick(Chronometer chronometer)

How to play a beep sound when time is less than 10 seconds

How to play a beep sound when time is less than 10 seconds

By : user3152774
Date : March 29 2020, 07:55 AM
I wish this help you Thank you guys, the problem was solved! My browser was blocking websites from playing sounds. The code is working now with little modification:
code :
**// Not working!**
        if (--timer < 10) {
            var audio = new Audio('beep.mp3');

**// working!**
        if (timer < 10) {
            var audio = new Audio('beep.mp3');
Play sound every x seconds if selectbox is?

Play sound every x seconds if selectbox is?

By : danovalo
Date : March 29 2020, 07:55 AM
should help you out I want to play a sound if a selectbox value = 'x': , Change data-time value number in minutes:
code :
var loop;
$('#additiveSport').on('change', function() {

      var time = parseInt($(this).find(":selected").data("time")) * 1000;

      if ( this.value == 'Heimtrainer')
        loop = setInterval(function(){$.playSound("http://www.noiseaddicts.com/samples_1w72b820/3724.mp3")}, time);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src='https://cdn.rawgit.com/admsev/jquery-play-sound/master/jquery.playSound.js'></script>

<select name="additiveSport" id="additiveSport" class="form-control is-invalid" aria-describedby="additiveSport-error" aria-invalid="true">
  <option value="-" data-time="2">Bitte auswählen...</option>
  <option value="Fahrrad" data-time="1">Fahrrad</option>
  <option value="Heimtrainer" data-time="1">Heimtrainer</option>
  <option value="Spazieren" data-time="3">Spazieren</option>
How to play a sound every 2 seconds?

How to play a sound every 2 seconds?

By : JoshMoyer
Date : March 29 2020, 07:55 AM
it fixes the issue You can use a flash.utils.Timer object to fire TimerEvents at whatever interval you like. Another approach could be to add a 2 second gap to your mp3 and play it continuously.
Related Posts Related Posts :
  • Why is it mandatory for ternary operations to return a value?
  • How can I make my listview rows different heights
  • Array declaration trick : Is it bad to use it?
  • Calling different classes with if else statements
  • Free API for speech recognition system
  • Java: Objects in JFrame are messed up
  • Is there a similar of MessageBox of ExtJS in ADF Faces
  • Passing HttpServletResponse in Spring Boot controller method
  • Failed to load libraries: [netty_tcnative_linux_arm_32, netty_tcnative_linux_arm_32_fedora, netty_tcnative_arm_32, netty
  • How to build a small documents storage?
  • Getting pixel position of a text in an image
  • How do I get a list of Methods called from a Class in Eclipse IDE?
  • Convert string to day of week (not exact date)
  • Unable to understand how rounding is working for decimal digits (Java)
  • How to avoid java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.copy(Ljava/io/InputStream;Ljava/io/OutputStream;)
  • JTable Renderer not working with RowSorter?
  • From java.util.concurrent.Future<T> to play.libs.F.Promise<T>: How to do that in Java?
  • jUnit tests work in Eclipse, but fail in ant - java.lang.RuntimeException: Stub
  • How do i add a tooltip to existing gwt Textbox?
  • actor replying to non-actor
  • Google Cloud Messaging - server connection
  • Which classes are unmodifiable and cannot be intrumented and is there a way to bypass it?
  • Java & Jersey 1.17: Custom default response headers
  • Java rounding error
  • Setting custom RejectedExecutionHandler for ThreadPoolExecutor after executing some tasks?
  • Arquillian test class variables lose value
  • java.util.ConcurrentModificationException while inserting in ArrayList
  • How to write generic Java API without method Overloading
  • Java Serialization / Deserialization of an ArrayList works only on first program execution
  • Conway's Game of Life's rules dont apply properly
  • call a java method when Click on a html button without using javascript
  • Why does SSLSocketFactory.createSocket returns a Socket instead of SSLSocket?
  • How to schedule a task in Tomcat
  • compare two pdf files (approach) using java
  • What is the use of allowCoreThreadTimeout( ) in ThreadPoolExecutor?
  • Describe the Strategy Design Pattern in Java?
  • MongoDB too many open connections
  • Issue with generate JAXB classes with value constructors
  • Moving from one frame to another in java swing
  • Get a thread by Id
  • how to open front camera and back camera at same time?
  • Messed up with Java Declaration
  • Extracting chart in EXcel as image using java
  • How to get latitude and longitude in Android phone?
  • Do GC pauses and kill -STOP produce the same behavior?
  • Android HTML.ImageGetter Images resized
  • The way to instantiate map<String, List<String>> in Java
  • Java Making objects move while buttons held
  • Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work
  • after compiling code JFrame does not appear
  • Netbeans project, JFrames ran from the main JFrame close all JFrames in project
  • Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?
  • Java Circular Reference - Can’t Compile
  • Mouse click on specific time JAVA
  • android 4 onCreateDialog return type incompatible when overriding
  • Java Implementation of Oracle's DBMS_UTILITY.GET_HASH_VALUE Function
  • javac cannot be run, and furthermore does not seem installed
  • Function to obtain a thread given its ID
  • Java File path to Executable has spaces
  • Minimum Oracle Java VM heap memory setting?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org