# No sound in exported java with Beads

**URL:** <https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532>\
**Category:** Libraries\
**Created:** [April 22, 2019, 3:17am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532 "2019-04-22T03:17:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 22, 2019, 3:17am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/1 "2019-04-22T03:17:17Z")

</div>

Hi,

I have been using the Beads library in my sketches in MacOS Mojave and Windows 10 with Processing 3.5.3. Everything works fine until I export the sketch to a Java applet. The Java applet no longer has audio ouput. In the particular example I’m working with the audio is played using the SamplePlayer object. Has anyone had issues with this?

Regards,  
Phillip

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 22, 2019, 3:29am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/2 "2019-04-22T03:29:55Z")

</div>

on  
win 7 / 64bit/  
processing 3.5.3  
install lib BEADS  
run example

> Lesson04\_SamplePlayer

save as own project  
export  
start /Lesson04\_SamplePlayer\application.windows64\Lesson04\_SamplePlayer.exe  
OK

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 22, 2019, 3:56am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/3 "2019-04-22T03:56:30Z")

</div>

Hmm,

I exported all the sampler examples and still no audio. I’m wondering if Windows 10 is the issue. I’ll test this on a Windows 7 machine later.

Thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 22, 2019, 4:30am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/4 "2019-04-22T04:30:51Z")

</div>

pls confirm that for export, you were using “embed JAVA”

 ![SNAG-0077](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cf047341d6378353ee705ccaa24a1f7cde3bdb6d.jpeg)

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 26, 2019, 12:53am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/5 "2019-04-26T00:53:31Z")

</div>

Yes, I was using the Embed Java. I tried playing the exported app on Windows 7 and still no sound.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 26, 2019, 1:00am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/6 "2019-04-26T01:00:41Z")

</div>

ok, no good idea,

well you might first confirm that there is nothing special about your code,  
by running/testing that mentioned example ONLY,

oh and verify that the sketch running in the IDE produce sound !!!  
( only the exported not ? ) hmmm

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 26, 2019, 1:36am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/7 "2019-04-26T01:36:46Z")

</div>

There’s no issue playing sound in the IDE. Exported code that has uses the WavePlayer object class have sound when exported, but not my code that uses the SamplePlayer object class. It may be how I’m loading the audio files. I will have to test a different method of constructing the path perhaps. In my setup block I have this code to load the sample file names into an array from a directory:

```auto
// this block of code counts the number of samples in the /DrumMachince subfolder
  File folder = new File(sketchPath("") + "DrumMachine/");
  File[] listOfFiles = folder.listFiles();
  for (int i = 0; i < listOfFiles.length; i++)
  {
    if (listOfFiles[i].isFile())
    {
      if (listOfFiles[i].getName().endsWith(".wav"))
      {
        numSamples++;
      }
    }
  }
  
  // if no samples are found, then end
  if (numSamples <= 0)
  {
    println("no samples found in " + sketchPath("") + "DrumMachine/");
    println("exiting...");
    exit();
  }
  
  // this block of code reads and stores the filename for each sample
  sampleSourceFile = new String[numSamples];
  int count = 0;
  for (int i = 0; i < listOfFiles.length; i++)
  {
    if (listOfFiles[i].isFile())
    {
      if (listOfFiles[i].getName().endsWith(".wav"))
      {
        sampleSourceFile[count] = listOfFiles[i].getName();
        //println(sampleSourceFile[count]);
        count++;
      }
    }
  }

```

This is the class I am using to load the sample files.

```auto
  // Connstructor for the MusicPlayer
  MusicPlayer(String tempSourceFile)
  {
    //sourceFile = sketchPath("") + "DrumMachine/Snaredrum 1.wav";
    sourceFile = tempSourceFile;
    
    try {
      // initialize SamplePlayer, loading the file indicated by the sourceFile string
      sp = new SamplePlayer(ac, new Sample(sketchPath("") + "DrumMachine/" + sourceFile));
    }
    catch(Exception e)
    {
      println("Exception while attempting to load sample!");
      e.printStackTrace();
      exit();
    }
   
    
    sp.setKillOnEnd(false);
  
    gainValue = new Glide(ac, 0.0, 20);
    g = new Gain(ac, 1, gainValue);
    g.addInput(sp);
    
    ac.out.addInput(g);
    ac.start();
    
  } // end of constructor MusicPlayer()
  
  void play()
  {
    gainValue.setValue(20);
    sp.setToLoopStart();
    sp.start();
    delay(125);
  }
  
} // end of class MusicPlayer

```

I then construct the object with this within the draw block:

```auto
myMusicPlayer = new MusicPlayer(sampleSourceFile[int(note)]);
    myMusicPlayer.play();

```

```auto
int(note)

```

is a variable to index the array of sample file names.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 26, 2019, 1:43am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/8 "2019-04-26T01:43:51Z")

</div>

sorry,  
you test sound from IDE run / good but what code?

- your code
- the example

you not answer the question if the export of that BEADS example  
produce sound ( on any of your computers ).

-a- above i show that it works here from WIN7  
-b- just now do same procedure from Raspian OS, also works

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 26, 2019, 2:06am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/9 "2019-04-26T02:06:02Z")

</div>

Actually, both the example code and my code play audio fine in the IDE, but when I export to Java in MacOS and Windows 7 and 10 both code samples don’t play. In fact, it never seems to complete the draw block as I have other graphic elements in my code that is synchronized with the sampler. Anyhow, I am going to test it on my Raspberry Pi to see if it works in Linux.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 26, 2019, 2:33am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/10 "2019-04-26T02:33:41Z")

</div>

> [@Peachy](#):
>
> Actually, both the example code and my code play audio fine in the IDE, but when I export to Java in MacOS and Windows 7 and 10 both code samples don’t play

-a- pls lets put your code aside ( i understand that you already doubt it,  
but also that makes no sense, as long the  
Lesson04\_SamplePlayer.pde export not even run  
( not open the canvas or not open the file manager?)

-b- now i must doubt your procedure:  
i described in detail how i did it, try again:  
-1- load and run example  
-2- save as an own project  
( for better identification i called it here BEADS\_Lesson04\_SamplePlayer )  
-3- export ( with embed JAVA enabled )  
-4- automatically get the file explorer open that directory  
-5- double click on the path like  
/application.windows64/  
-6- double click on BEADS\_Lesson04\_SamplePlayer.exe  
-7- the canvas show and is then behind  
the file open menu  
-8- walk to a sound file ( i use untitled.mp3 from the minim examples ) and double click it  
-9- the file manager closes and the canvas show  
make sound and show graph.  
( and just play the song one time, so it should not be a too short one )  
-10- now song finished and still see the canvas, but can not do anything as close it.

* * *

i repeat that it works here on Win7 && Raspbian

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [April 26, 2019, 2:57am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/11 "2019-04-26T02:57:16Z")

</div>

Ah, I misunderstood which Beads example sample player to test. I was looking in the beads library folder for the example sample player. It’s the one where I specify the file interactively. Okay, that one works as an exported Java app in Windows and Raspian.

So, I can rule out any issues with the operating system sound subsystem. Thus it looks like it is a problem within my code. I suspect it has something to do with the way the path to the sample files is coded. But it seems the try and catch method is not executing if that is the case, so perhaps that is not it. I will need to re-think how the samples are loaded into the program.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 26, 2019, 8:31am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/12 "2019-04-26T08:31:36Z")

</div>

> [@kll](#):
>
> i described in detail how i did it

Great walkthrough of a debugging test, @kll. Thanks for all you do on the forum.

@Peachy – glad you are narrowing the problem down. If you need to check a path or file, keep in mind `.exists()` on File objects, and that all Processing API load functions return null if the path is not found:

- [https://forum.processing.org/two/discussion/23031/determining-file-existance-in-the-specified-directory](https://forum.processing.org/two/discussion/23031/determining-file-existance-in-the-specified-directory)

---

<div class="post-metadata">

**Author:** ![Peachy](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Peachy](https://discourse.processing.org/u/Peachy)\
**Post date:** [May 10, 2019, 3:51am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/13 "2019-05-10T03:51:20Z")

</div>

I’m not sure it’s a file loading problem. I made other sketches with the Sound library and a simple SinOsc, TriOsc and none of them produced sound when exported. In each case the draw window just freezes at a grey screen. Would installing a Java SDK help? I only have the JRE installed in each OS.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [May 10, 2019, 4:52am UTC](https://discourse.processing.org/t/no-sound-in-exported-java-with-beads/10532/14 "2019-05-10T04:52:47Z")

</div>

> [@Peachy](#):
>
> Would installing a Java SDK help

probably not, if you are using the embed java feature on export. You can have you sketch print its java version / location to test – it is almost certainly using the java you embedded…
