Audio API
Important Please Read
To ensure the Skillz Audio API does not conflict with your current audio implementation please read carefully.
The Skillz SDK has an audio API that allows you to play custom background music for the Skillz UI, get/set your game's background music volume, and get/set your game's sound effects volume for consistent audio levels between Skillz and your game. Read more below for instructions on how to use this API.
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 configure this.
The Skillz UI will play an internal background music file if you do not specify your own for playback**
Ensure Your Music File Is in the Correct Location
First, make sure your music file is in the correct location of your project:
- Unity
- iOS
- Android
The file which contains the background music you’d like to play must be located in directly in the root of your Xcode project. An example is pictured below:
The file which contains the background music you’d like to play must be located in the app/src/main/assets
directory of your Android Studio project:
Call the API Method to Set the Music Source
Tell the SDK which background music file to play in the Skillz UI. This file name must match exactly with the file’s name from the previous step.
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
[[Skillz skillzInstance] setBackgroundMusicFile:@"music.mp3"];
[[Skillz skillzInstance] launchSkillz];
Skillz.skillzInstance().backgroundMusicFile = "music.mp3"
Skillz.skillzInstance().launchSkillz()
SkillzAudio.setSkillzBackgroundMusic("music.mp3");
Skillz.Launch(getActivity());
SkillzCrossPlatform.setSkillzBackgroundMusic("music.mp3");
SkillzCrossPlatform.LaunchSkillz(SkillzGameController());
You can set the background music for Skillz anywhere after the app launches, but it is recommended to do so before launching the Skillz UI.
Syncing Your In-Game Volume with the Skillz SDK Audio
Android Only: 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
.
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.
Synchronizing Your In-Game Volume with the Skillz SDK
Getting the Background Music Volume
For your game’s music, get the background music volume from the Skillz SDK 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:
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
[self.musicVolumeSlider setValue:[[Skillz skillzInstance] getBackgroundMusicVolume]];
musicVolumeSlider.value = Skillz.skillzInstance().getBackgroundMusicVolume()
myMusicSlider.setProgress((int) (SkillzAudio.getSkillzMusicVolume() * 100));
SkillzCrossPlatform.getSkillzMusicVolume(float volume);
Getting the Sound Effects Volume
For your game’s sound effects, get the sound effect volume from the Skillz SDK 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:
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
[[self.sfxVolumeSlider setValue:[[Skillz skillzInstance] getSFXVolume]];
self.sfxVolumeSlider.value = Skillz.skillzInstance().getSFXVolume()
mySfxSlider.setProgress((int) (SkillzAudio.getSFXVolume() * 100));
SkillzCrossPlatform.getSFXVolume();
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:
- Unity
- iOS
- Android
Synchronizing the Skillz SDK volume with your In-Game volume
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.
Setting the Background Music Volume
When a user changes your game’s music volume, set the background music volume in the SDK to keep the value in sync between your game and Skillz. Ensure the value is between 0 and 1.
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 above, our code would look like this:
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
Skillz.skillzInstance().setBackgroundMusicVolume(musicSlider.value)
SkillzAudio.setSkillzMusicVolume(volume);
SkillzCrossPlatform.setSkillzMusicVolume(float volume);
Setting the Sound Effects Volume
When a user changes your game’s sound effects volume, set the sound effects volume in the SDK to keep the value in sync between your game and Skillz. Ensure the value is between 0 and 1.
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 above, our code would look like this:
- Unity/C#
- iOS/Swift
- iOS/Objective-C
- Android
Skillz.skillzInstance().SFXVolume = sfxSlider.value
void SkillzAudio.setSFXVolume(volume);
void SkillzCrossPlatform.setSFXVolume(volume);