Getting started

This section helps you get up and running with the Soundtrack SDK, guiding you through building a simple music player that connects to Soundtrack.

The SDK provides C header files, exposing a modular API known as the SPlayer API. It allows you to:

  • Play music from the Soundtrack service
  • Connect the player to a sound zone
  • Read track metadata (artist, album, track position)
  • Send audio to your platform's audio output
  • Control playback (play, pause, skip, volume, seek)
  • Browse the account's library of playlists and schedules, and play them
  • Retrieve troubles (failed diagnostic checks)

At its core, the SDK delivers raw PCM audio samples, but audio output implementations for common platforms (e.g., ALSA, Darwin) are included to help you connect to your platform's audio backend. To implement your own audio output, see the Audio callbacks section.

The player logic is implemented in the Player Library, a shared library that Soundtrack builds with your toolchain. You link against it from your application, so Player Library updates don't require recompiling your application. See Release management for how the Player Library and the SDK API are versioned.

SDK overview

Once you've unpacked the SDK we send you, you'll see the following structure:

splayerapi-v5/
├── include/                            # C header files for API modules
│   ├── audio_output_callbacks.h        # Allocates platform audio callbacks struct
│   └── splayerapi/
│       ├── splayer_audio_api-3.h       # Audio output API
│       ├── splayer_auth_api-1.h        # Authentication API
│       ├── splayer_controls_api-3.h    # Playback control API
│       ├── splayer_library_api-1.h     # Account music library API
│       ├── splayer_metadata_api-4.h    # Track metadata API
│       ├── splayer_options_api-1.h     # Player options, such as brand and model
│       ├── splayer_troubles_api-2.h    # Troubleshooting & diagnostics API
│       └── splayerapi-5.h              # Core SDK entry point
├── lib/                                # Precompiled Player Library
├── reference-app/                      # Reference app source, see the Reference app page
├── src/                                # Audio output implementations, mock libraries and a local provisioning server
├── CMakeLists.txt                      # CMake configuration for building the mock libraries
└── changelist.md                       # SDK changelog

Environment setup

This guide uses CMake to build a minimal example; any build system works. Create a workspace directory (e.g., example-player/) and place the unpacked splayerapi-v5/ SDK inside it. Create a CMakeLists.txt file with the following content:

cmake_minimum_required(VERSION 3.8)
project(example-player C)

include_directories(${CMAKE_SOURCE_DIR}/splayerapi-v5/include)

add_executable(
    example-player
    main.c
    splayerapi-v5/src/audio_output_dummy.c # This is a dummy audio output example and will not produce sound.
)

target_link_libraries(example-player
        ${CMAKE_SOURCE_DIR}/splayerapi-v5/lib/libsplayer-1.so # Replace with the actual library name for your platform if needed.
)

Example player

With the CMakeLists.txt from the previous step, the following example shows the basic structure required to create and configure a player instance using the SDK. It covers how to:

  • Set up basic configuration with the struct splayer_config_t
  • Report the device brand and model with splayer_options_api-1.h
  • Use splayerapi-5.h for core API functions
  • Handle the player lifecycle: create, exit and free

The example doesn't connect to a sound zone or play music. Playback and connecting are essential for a complete player implementation. For a complete player, including audio output, connecting, playback control and the automatic updater, see the reference app.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "audio_output_callbacks.h"
#include "splayerapi/splayerapi-5.h"
#include "splayerapi/splayer_options_api-1.h"

// Basic configuration
splayer_config_t config = {
    .sdk_version = SPLAYER_SDK_VERSION,
    .diskcache_dir = "cache",
    .diskcache_max_mb = 5120,
    .diskcache_remain_mb = 320,
    .vendor_device_name = "hello-world-player",
    .app_version = "1.0",
    .output_sample_channels = 2,
    .output_sample_rate = 44100,
};

int main() {
    config.audio_api_callbacks = audio_api_allocate();
    const struct splayer_api* api = &SPLAYER_API;
    const struct splayer_options_api* options_api = api->get_options_api();
    splayer_t* splayer = NULL;

    // The brand is the value Soundtrack gave you, the model is the name printed on the product.
    splayer_options_t* options = options_api->create();
    options_api->set_device_info(options, "unknown-company", "Unknown Model");
    api->create_with_options(config, &splayer, options);
    options_api->free(options);

    if(!splayer){
        printf("Failed to create splayer instance.\n");
        free(config.audio_api_callbacks);
        return 1;
    }

    // Before actual playback loop, the player needs to be connected to a sound zone
    // See the connecting documentation for more information

    // Simple demonstration loop
    while(api->should_exit(splayer) == 0) {

        // In this example, we request an exit immediately since we're not connected
        api->request_exit(splayer, SPLAYER_EXIT_NORMAL);

        usleep(500000);
    }

    // Cleanup of allocated resources
    api->free(splayer);
    free(config.audio_api_callbacks);
    return 0;
}

The brand and model set with set_device_info are required: the player isn't created without them. See Requirements for their format. vendor_device_name is a free name for the unit.

Save the example above as main.c in your workspace directory (e.g., example-player/). To build it in a separate build/ directory and run it, execute the following commands from your workspace directory:

cmake -B build
cmake --build build
./build/example-player

The program creates a player, requests an exit straight away because the player isn't connected, waits until should_exit reports that the player is ready to exit, and frees it. No audio is played.

Next steps

  • Reference app – Build and run our complete reference player to see how we use the C APIs, and experiment with it.
  • Connecting – Learn about the authentication API and connecting your player to a sound zone.
  • SPlayer lifecycle – Learn how to manage the player lifecycle.
  • Audio callbacks – Learn how audio callbacks work. You can use our provided ALSA or Darwin audio output implementations, or plug in your own.