Pergunta

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?

Foi útil?

Solução 3

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.

Outras dicas

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.

Try this with Maven 3.0.3 or greater

cd funktest
mvn package
cd android
mvn android:deploy
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top