Mobile native Wearable native

Tone Player: Playing Tones

This tutorial demonstrates how you can play audio tones.

Warm-up

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

Initializing the Tone Player

Initialize the tone player:

  1. To use the functions and data types of the Tone Player API (in mobile and wearable applications), include the <tone_player.h> and <sound_manager.h> header files in your application:
    #include <tone_player.h>
    #include <sound_manager.h>
    
  2. To start using the tone player, declare a variable which identifies the tone player:
    int tone_player_id;

Playing a Tone

To start and stop playing a tone:

  1. To start playback, use the tone_player_start() function. The player ID is assigned if the function succeeds. The function takes the following parameters:
    • Tone type, selected from the tone_type_e enum, defines which tone type to use (such as DTMF0 or DTMF1).
    • Media sound type, from the sound_type_e enum, defines which sound type is used (such as NOTIFICATION, ALARM, or RINGTONE).
    • Tone duration in milliseconds. If the duration is set to -1, the playback continues infinitely.
    • Player ID is an output parameter, and its value is set by the function. The ID of the tone player that started first is 0, the ID of the second is 1, and so on. If you determine the value to be NULL, the ID is not returned.
    tone_player_start(TONE_TYPE_DEFAULT, SOUND_TYPE_MEDIA, -1, &tone_player_id);
  2. To stop the playback, use the tone_player_stop() function with the ID of the player which you want to stop:
    tone_player_stop(tone_player_id);

Playing a Tone for a Specified Duration

To start playing a tone, use the tone_player_start() function with the tone type, sound type, and duration time as parameters. In this example, a congestion tone is played as a call sound for 1 second (1000 milliseconds):

tone_player_start(TONE_TYPE_SUP_CONGESTION, SOUND_TYPE_CALL, 1000, &tone_player_id);

When the duration is set to a specified time, playing is stopped automatically. You can also use the tone_player_stop() function to stop the playback manually.

Go to top