Audio Controls for Android

Configuring Background Music for the SDK

If you have music you’d like to play in the background for users when they are interacting with the SDK, you can use the Skillz Audio API to easily configure this.

Step 1: Ensure your music file is in the correct location

The file which contains the background music you’d like to play must be located in this directory:

“app/src/main/assets”

unnamed__1_.png

Step 2: Call the API method to set the music source

Use SkillzAudio.setSkillzBackgroundMusic to set the background music that will play in the Skillz SDK.  This file name must match exactly with what the file’s name is in Step 1.

SkillzAudio.setSkillzBackgroundMusic("music.mp3");
Skillz.Launch(getActivity());

This can be called anywhere after the app launches, but it is recommended to call this before launching the Skillz SDK.

Syncing Your In-Game volume with the Skillz SDK volume

Note: The functions in this section can only be used in-game after Skillz has launched.

Users can set volume settings from within the SDK via Accounts -> Audio Settings.

unnamed__2_.png

Each volume is represented as a range between 0 and 1, with 0 being muted and 1 being full volume.

If you would like your in-game volume to match with the values set by the user in the SDK (and vice-versa), use these instructions to synchronize the settings.

Step 1: Synchronizing your In-game audio with the Skillz SDK

For your game’s music, use SkillzAudio.getSkillzMusicVolume() when initially setting the music volume for your game to ensure that value matches the value set inside of the SDK.  In our example, we’re using a volume slider to control the in-game music volume, and to initialize its value we call the API like so:

 myMusicSlider.setProgress((int) (SkillzAudio.getSkillzMusicVolume() * 100));

For your game’s sound effects, use SkillzAudio.getSFXVolume() when initially setting the sound effects volume for your game to ensure that matches the value set inside of the SDK. In our example, we’re using a volume slider to control the in-game sound effects volume, and to initialize its value we call the API like so:

mySfxSlider.setProgress((int) (SkillzAudio.getSFXVolume() * 100));

Our end result when initializing the settings inside of a test app is similar to that pictured below. If a user adjusts their volume sliders in the Skillz menu, that change will reflect in these in-app sliders:

unnamed__3_.png

Step 2: Synchronizing the Skillz SDK with your In-Game audio

If you utilize an in-game menu which allows the user to change their volume settings, use these methods to ensure the Skillz SDK will play at the same volume.  

When a user changes your game’s music volume, use SkillzAudio.setSkillzMusicVolume(float) to synchronize that value with the SDK.  Ensure the value is a float between 0 and 1. (Note: Please make sure to sanitize your values; the API can take in values outside of the 0-1 range but this will cause problems). Using the example from Step 1 above, our code would look like this:

SkillzAudio.setSkillzMusicVolume(volume);

When a user changes your game’s sound effects volume, use SkillzAudio.setSFXVolume(float) to synchronize with the SDK.  Ensure the value is a float between 0 and 1. (Note: Please make sure to sanitize your values; the API can take in values outside of the 0-1 range but this will cause problems). Using the example from Step 1 above, our code would look like this:

SkillzAudio.setSFXVolume(volume);