Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Stopping the minim library / audio players only if it is running already.

$
0
0

Ok I edited my original post:

TLDR: The .mute() function does not seem to work nor does the .isPlaying() command. "By does not seem to" I mean it results in a null pointer error which basically means that it does not work at all..

My solution to stop playing all running sounds Bit of a cheat to be honest:

     String SilentSound = "silence.mp3";

     // Using the close function results in a null error so I simply play a blank audio file that lasts a sec
      SFXPlayer(SilentSound, false);

My solution - function to load an optionally mute sounds:

`void SFXPlayer(String Input_File_Name, boolean Input_Mute_Sounds_Setting){
  // SFX playing
  if(IsSFXPlaying == true){
    // Print message to console
    println("Stop playing SFX");

    // Stop the audio player
    SFX.close();

    // Change the setting
    IsSFXPlaying = false;
  }
  // SFX not playing
  else if(IsSFXPlaying == false){

    if(Input_Mute_Sounds_Setting == false){
    // Print message to console
    println("Start playing SFX");

    // Load the audio player with the inputted file name if sound is allowed
    SFX = minim.loadFile(Input_File_Name);

    // Play the sound inputted
    SFX.play();
    }
    else if(Input_Mute_Sounds_Setting == true){
      // Do nothing at all. I could alternatively just load the "silence.mp3" file for the same effect.

    }

    // Change the setting
    IsSFXPlaying = false;
  }
}`

Viewing all articles
Browse latest Browse all 2896

Trending Articles