PlayN - no sound on Android
Asked Answered
K

3

10

I'm having a problem playing sounds on Android. I've added the following code to my project:

import playn.core.Sound;
...
@Override
public void init() {

    Sound bg = assets().getSound("bg");
    bg.play();
    ...
}

The code works as intended when I run mvn test -Pjava. The sound plays without a problem. However, when I run mvn -Pandroid install the sound doesn't play. I don't get any errors in logcat or anything, the game is just silent.

I've tried:

  • Using different sound formats (wav, mp3)
  • Loading a sound file that isn't in the assets folder - in this case I get an error notifying me that the sound file was not found. But I get no such error when loading an actual sound file
  • Using different mvn versions
  • Made sure the device is not set to silent
  • Using multiple devices (Nexus 7, older Android phone)
  • Reproducing this issue in the Showcase example (it's the same as in my project)
  • Upgrading PlayN from 1.7 to 1.7.2, no change.

I've found that running mvn install instead of mvn test -Pjava loads up the desktop version without sound as well. This makes me think there might be an issue with the install command, but I'm just guessing here.

Any ideas on how to make sound work on Android?

Kendakendal answered 28/10, 2013 at 20:24 Comment(0)
K
0

I was able to get the sound working by using an mp3 file (not wav) and using the setLooping(true) call only on files loaded with getMusic(). GetSound() throws a "Heap size overflow! req size: 1052672, max size: 1048576" error.

For more details see the same question on the PlayN mailing list.

Kendakendal answered 6/11, 2013 at 22:56 Comment(0)
A
0

I'm using this code in my activity

MediaPlayer player = MediaPlayer.create (getApplicationContext(), R.raw.beep);
player.start();

to play a beep sound. I have my beep.mp3 file inside res/raw folder.

Aphesis answered 31/10, 2013 at 10:21 Comment(1)
I've found that using assets().getMusic() works with mp3 files. But now wav. See my answer for details.Kendakendal
S
0

Try this with Maven 3.0.3 or greater

cd funktest
mvn package
cd android
mvn android:deploy
Sorrow answered 6/11, 2013 at 4:33 Comment(1)
Nope, it's the same as with mvn -Pandroid installKendakendal
K
0

I was able to get the sound working by using an mp3 file (not wav) and using the setLooping(true) call only on files loaded with getMusic(). GetSound() throws a "Heap size overflow! req size: 1052672, max size: 1048576" error.

For more details see the same question on the PlayN mailing list.

Kendakendal answered 6/11, 2013 at 22:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.