# Minim setting volume of an audioPlayer

**URL:** <https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596>\
**Category:** Libraries\
**Created:** [September 17, 2018, 9:48am UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596 "2018-09-17T09:48:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/colin/32/230_2.png) [@colin](https://discourse.processing.org/u/colin)\
**Post date:** [September 17, 2018, 9:48am UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/1 "2018-09-17T09:48:58Z")

</div>

Hi,

Quick question

It’s been a long time I didn’t use sound with processing. I wanted to play a file and setting his volume, and I discovered the Sound libraries aren’t working with windows anymore. So I decided to go back to Minim, but I can’t manage to set the volume or the gain.

What can I do ? 🤔

Here is the message I get :

> === Minim Error ===  
> === Volume is not supported.

and here is a sample of my code :

```auto
import ddf.minim.*;
 
Minim minim;
AudioPlayer player;

void setup() {
  
  minim = new Minim(this);
   
  player = minim.loadFile("walk.wav");
  player.play();
  player.setVolume(0); 
  
}

```

---

<div class="post-metadata">

**Author:** ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)\
**Post date:** [September 17, 2018, 7:42pm UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/2 "2018-09-17T19:42:07Z")

</div>

I looked online and found this:

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/13521/minim-help-with-volume-control)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

Setting the volume with gain, instead of with the `setVolume()` function which I hear has some issues with some versions of Processing. [Read about that here.](https://github.com/ddf/Minim/issues/52)

Gain should be able to work though. Hopefully this helps,

EnhancedLoop7

---

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/colin/32/230_2.png) [@colin](https://discourse.processing.org/u/colin)\
**Post date:** [September 17, 2018, 8:01pm UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/3 "2018-09-17T20:01:21Z")

</div>

Hi @EnhancedLoop7, thanks for your answer.  
On my mac os 10.13.4 the setGain fonction is not working either since I can still hear the sound, but the error message has changed

> ==== JavaSound Minim Error ====  
> ==== Error reading from the file - Stream closed

Here is the code

```auto
import ddf.minim.*;
 
Minim minim;
AudioPlayer player;

void setup() {
  
  minim = new Minim(this);
  player = minim.loadFile("walk.wav");
  player.setGain(0); 
  player.play();
  
}

```

---

<div class="post-metadata">

**Author:** ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)\
**Post date:** [September 17, 2018, 8:14pm UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/4 "2018-09-17T20:14:18Z")

</div>

Is there a `setGain()` function? Forgive me if I’m mistaken but I haven’t really heard of it. Maybe you can try shifting the gain like shown in the link I sent? Hopefully that works,

EnhancedLoop7

---

<div class="post-metadata">

**Author:** ![colin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/colin/32/230_2.png) [@colin](https://discourse.processing.org/u/colin)\
**Post date:** [September 17, 2018, 8:22pm UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/5 "2018-09-17T20:22:11Z")

</div>

I’m using this doc [http://code.compartmental.net/minim/](http://code.compartmental.net/minim/)  
Is it outdated ?

Anyway the following works. The second error was due to the play() function called in the setup().

```auto
Minim minim;
AudioPlayer player;
static final int FADE = 2500;

void setup() {
  
  minim = new Minim(this);
  player = minim.loadFile("walk.wav");

}

void draw() {
  
  player.play();
  player.shiftGain(player.getGain(),-80,FADE);
  
}

```

---

<div class="post-metadata">

**Author:** ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)\
**Post date:** [September 18, 2018, 1:16am UTC](https://discourse.processing.org/t/minim-setting-volume-of-an-audioplayer/3596/6 "2018-09-18T01:16:43Z")

</div>

Glad that that got taken care of 😃

EnhancedLoop7
