question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Sound issue

See original GitHub issue

Issue details

On my Android 7.0 smartphone some sounds are gone at play mission time. Usually it happened on looped “engine” sound. But also gone other random sounds like shot, explosion, collision and so on. On Android 4.4 all works fine. I solved this problem by writing my own AndroidSound class that use new way to initialize SoundPool. And also increase priority for looping sounds. I think it should be applied for all, so I suggest you to fix this:

gdx.backends.android.AndroidAudio.java constructor must be updated by this way:

public AndroidAudio (Context context, AndroidApplicationConfiguration config) {
      if (!config.disableAudio) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            AudioAttributes audioAttrib = new AudioAttributes.Builder()
                  .setUsage(AudioAttributes.USAGE_GAME)
                  .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                  .build();
            soundPool = new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(config.maxSimultaneousSounds).build();
         }else {
            soundPool = new SoundPool(config.maxSimultaneousSounds, AudioManager.STREAM_MUSIC, 0);// srcQuality: the sample-rate converter quality. Currently has no effect. Use 0 for the default.
         }
         manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
         if (context instanceof Activity) {
            ((Activity)context).setVolumeControlStream(AudioManager.STREAM_MUSIC);
         }
      } else {
         soundPool = null;
         manager = null;
      }
   }

Also, I recommend increase sound priority in loop(…) methods. Right now it’s equal 1 and it’s the same as used in play(…) methods. But looped sound usually must play until game logic didn’t stop it. So, it can not be removed by SoundPool inner sound manager. Therefor priority in loop(…) method must be greater then used in play(…) gdx.backends.android.AndroidSound.java -public long loop (float volume) and -public long loop (float volume, float pitch, float pan) recommend to update priority from 1 to something greater, for example 3: int streamId = soundPool.play(soundId, leftVolume, rightVolume, 3, -1, pitch); // set priority greater(3) then used in play method(1)

Version of LibGDX and/or relevant dependencies

1.9.8

Please select the affected platforms

  • Android

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
obigucommented, Jan 23, 2018

Thanks! Will test it and create PR if it fixes it on my apps (which have “missing” sounds from time to time).

UPDATE It works on my projects, this is really great! I was not expecting to see a fix for these long standing sound/music issues on Android. I will create the PR for the first of your changes, a small problem is that it also requires updating the libGDX android compile sdk to 21 which is included as a local dependency inside /libs.

0reactions
obigucommented, Feb 13, 2018

@KristjanP94 No, that would need to be a different PR. Please feel free to create it if you have the means to reproduce the issue and test the fix or, alternatively, provide a minimal executable so that we can test it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is Your Android Phone Speaker Not Working? Try These Fixes
How to Fix It When the Speaker Is Not Working on Your Android Device · Navigate to Settings. · Tap Sounds and vibration....
Read more >
Fix Call or Audio Quality Android Phone or Tablet - Support.com
1. If your device has its own built-in speakers, try its audio without using a headset first. Set the volume to maximum by using...
Read more >
Android Phone Speakers Not Working? 7 Tips and Fixes to Try
Android Phone Speakers Not Working? 7 Tips and Fixes to Try ; Audio settings in Android Phone. Choose a ringtone in Android settings...
Read more >
Resolving Sound Issues (Android) - OTN
To check the speakers, go to Settings > Sound and drag the Media, Alarm, and Ring volume sliders to increase the volume. You...
Read more >
Fix sound problems - Pixel Phone Help - Google Help
I can't clearly hear sounds from my phone ; Step 1: Check the strength of your mobile data connection. ; Step 2: Turn...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found