Play two mp3 files simultaneously

This is a piece of code showing how to play multiple mp3 files using Player API. You just need to create as many player instances as many files you want to play at a time. 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 <player.h>
#include <dlog.h> //for logging purposes

player_h player1;
player_h player2;

// Preparing players:	
if (player_create(&player1) == PLAYER_ERROR_NONE
    && player_set_uri(player1, "/opt/usr/media/Music/Your_music_file_1.mp3") == PLAYER_ERROR_NONE
    && player_prepare(player1) == PLAYER_ERROR_NONE)
{
    LOGI("Player 1 prepared.");
}
else
{
    LOGE("Could not prepare player 1!");
}

if (player_create(&player2) == PLAYER_ERROR_NONE
    && player_set_uri(player2, "/opt/usr/media/Music/Your_music_file_2.mp3") == PLAYER_ERROR_NONE
    && player_prepare(player2) == PLAYER_ERROR_NONE)
{
    LOGI("Player 2 prepared.");
}
else
{
    LOGE("Could not prepare player 2!");
}

// Starting playback:
int err1 = PLAYER_ERROR_NONE, err2 = PLAYER_ERROR_NONE;
player_state_e state1, state2;

err1 = player_get_state(player1, &state1);
err2 = player_get_state(player2, &state2);
if (err1 == PLAYER_ERROR_NONE && err2 == PLAYER_ERROR_NONE
    && state1 == PLAYER_STATE_READY && state2 == PLAYER_STATE_READY)
{
    LOGI("All players are ready to be started.");
    if (player_start(player1)== PLAYER_ERROR_NONE)
    {
        LOGI("Player 1 started!");
    }
    else
    {
        LOGE("Player 1 failed to start!");
    }
    if (player_start(player2)== PLAYER_ERROR_NONE)
    {
        LOGI("Player 2 started!");
    }
    else
    {
        LOGE("Player 2 failed to start!");
    }
}
else
{
    LOGE("One or more players are not ready!");
}

// Stopping players:
if (player_stop(player1) == PLAYER_ERROR_NONE && player_stop(player2) == PLAYER_ERROR_NONE)
{
    LOGI("Players stopped!");
}
else
{
    LOGE("Error when stopping!");
}
	
// When you don't need your players anymore:	
if (player_unprepare(player1) == PLAYER_ERROR_NONE && player_unprepare(player2) == PLAYER_ERROR_NONE)
{
    LOGI("Players unprepared!");
}
else
{
    LOGE("Error when unpreparing!");
}
if (player_destroy(player1) == PLAYER_ERROR_NONE && player_destroy(player2) == PLAYER_ERROR_NONE)
{
    LOGI("Players destroyed!");
}
else
{
    LOGE("Error when destroying!");
}

Responses

0 Replies