语言

Menu
Sites
Language
Pause background music

Hi,

I want to pause backgruond music when my app/game is start or begin play music.

The background music was played by "Music"/"Sound Player" app.

("Music" and "Sound Player" app was embedded on phone)

for example:

You play music file "file_01.mp3" with "Music" app. then you press home key, play music file "file_02.mp3" with "Sound Player" app, vice versa.

The are only one music file is played. one is paused.

How can my app be pause the music like "Music"/"Sound Player" app does?

Please support me.

thanks a lot.

编辑者为: le nam 17 5月, 2016

响应

5 回复
Nafisul Islam Kiron

You can use "player_set_mute", here's the api link:

https://developer.tizen.org/dev-guide/2.3.1/org.tizen.native.mobile.apireference/group__CAPI__MEDIA__PLAYER__MODULE.html

le nam

Hello Kiron,

I'm sorry for my unclear question.

I was updated my question.

Please help.

Nafisul Islam Kiron

Hello, so you want to pause the music player's music when your app starts?

Have you tried the method I posted earlier?

le nam

Hi, 

Sorry,I'm don't get it.

Do you mean:

           player_h player = get_music_is_playing(); // (or just set it NULL, or something else). 

           player_set_mute(player,true);

         // play my mound here

           player_start(my_player);

 could you please explain clearly?.

thanks.

 

 

 

Nafisul Islam Kiron

Register a callback function using the "player_set_interrupted_cb" function

static void
_player_interrupted_cb(player_interrupted_coded_e code, void *data)
{
   appdata_s *ad = data;
   player_state_e state;

   player_get_state(ad->player, &state);
   log_print(DLOG_INFO, LOG_TAG, "current player state = %d", state);
   // If the state is PLAYER_STATE_PAUSED, update UI (for example, button)
}

static void
init_base_player(appdata_s *ad)
{
   // Set an interruption callback if the application wants to know the reason
   error_code = player_set_interrupted_cb(g_player, _player_interrupted_cb, ad);
   if (error_code != PLAYER_ERROR_NONE)
      dlog_print(DLOG_ERROR, LOG_TAG, "failed to create");
}

When playback is interrupted by another multimedia application the player state automatically changes to "PLAYER_STATE_PAUSED" or "PLAYER_STATE_IDLE" according to the session policy. To get the current state, use the "player_get_state" function. To receive a notification when the playback ends, register a callback function using the "player_set_completed_cb" function.

static void
_player_completed_cb(void *data)
{
   dlog_print(DLOG_INFO, "Player", "Playback End");
}

static void
init_base_player(appdata_s *ad)
{
   // Set a completed callback if the application wants to know when the playback ends
   error_code = player_set_completed_cb(g_player, _player_completed_cb, ad);

   if (error_code != PLAYER_ERROR_NONE)
      dlog_print(DLOG_ERROR, LOG_TAG, "failed to set completed cb");
}

To receive notifications about player errors during playback, register a callback function using the "player_set_error_cb" function.

static void
_player_error_cb(int error_code, void *user_data)
{
   dlog_print(DLOG_ERROR, LOG_TAG, "playback failed, error = %x", error_code);
}

static void
init_base_player(appdata_s *ad)
{
   error_code = player_set_error_cb(g_player, _player_error_cb, NULL);
   if (error_code != PLAYER_ERROR_NONE)
      dlog_print(DLOG_ERROR, LOG_TAG, "failed to set error cb");
}

The player error callback is triggered when the player stops working due to an error.

 

From here: https://developer.tizen.org/development/tutorials/native-application/multimedia/player