Mobile native Wearable native

WAV Player: Playing Waveform Audio Files

This tutorial demonstrates how you can play Waveform Audio File Format (WAV) files.

Warm-up

Become familiar with the WAV Player API basics by learning about:

Starting and Stopping the WAV Player

To start and stop the WAV player:

  1. To use the functions and data types of the WAV Player API (in mobile and wearable applications), include the <wav_player.h> header file in your application:

    #include <stdio.h>
    #include <wav_player.h>
    #include <sound_manager.h>
    
  2. Start the WAV player.

    Implement a callback function that is called when the WAV file is no longer being played.

    Declare a variable which keeps the return value of the function. Invoke the wav_player_start() function to play the WAV file:

    static void _playback_completed_cb(int id, void *user_data) 
    {
       const char* path = (const char*)user_data;
       dlog_print(DLOG_INFO, "WAV Player", "Completed! [id:%d, path:%s]", id, path);
    }
    
    void main() 
    {
       int wav_player_id;
       wav_player_error_e ret;
       const char* wav_path = "PATH OF YOUR WAV FILE";
    
       ret = wav_player_start(wav_path, SOUND_TYPE_MEDIA, _playback_completed_cb, (void*)wav_path, &wav_player_id);
    }
    

    To set the path of your WAV file, you may need to get the default path. For more information, see the Storage Tutorial.

  3. Stop the WAV player.

    To stop the WAV player, use the wav_player_stop() function with the ID of a given WAV player as an argument:

    void my_stop()
    {
       wav_player_error_e ret;
       ret = wav_player_stop(wav_player_id);
    }
    
Go to top