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 <wav_player.h>
    #include <stdio.h>
    #include <sound_manager.h>
    

    In this use case, you also need the <stdio.h> and <sound_manager.h> header files to use standard file input and output functions and the Sound Manager API functions (in mobile and wearable applications).

  2. To start the WAV player, use the wav_player_start() function.

    The third parameter defines a callback that is invoked when the player finishes playback. Implement the callback and handle any post-playback actions in it.

    The final parameter returns the WAV player ID, which you need to stop the player.

    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 retrieve the default path for audio files. For more information, see the Storage Tutorial.

  3. To stop the WAV player, use the wav_player_stop() function with the ID of the WAV player:

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