Play a wav file from the phone storage

This is a piece of code showing how to play a wav file using WAV Player API. You start wav playback, stop it and set callback to be executed when playback finished. To access a media file from the phone storage you need to request privilege. PRIVILEGE: http://tizen.org/privilege/mediastorage
//    PRIVILEGE needed to be set in tizen-manifest.xml:
//    http://tizen.org/privilege/mediastorage

#include <wav_player.h>
#include <dlog.h> //for logging purposes

//callback performed when wav playback is completed.
void on_playback_completed(int id, void *user_data)
{
    LOGI("Playback completed for player no. %d!", id);
}

//when you want to play a sound
int id;
if (wav_player_start("/opt/usr/media/Music/sound_file.wav", SOUND_TYPE_MEDIA, on_playback_completed, NULL, &id) == WAV_PLAYER_ERROR_NONE)
{
    LOGI("Playback started for player no. %d!", id);
}
else
{
    LOGE("Error occurred when trying to play a sound!");
}

//when you want to stop the player
if (wav_player_stop(id)== WAV_PLAYER_ERROR_NONE)
{
    LOGI("Playback stopped for player no. %d!", id);
}
else
{
    LOGE("Error!");
}

Responses

0 Replies