MP_CHECK_FALSE(ad);
int err = -1;
int error = SOUND_MANAGER_ERROR_NONE;
+ sound_stream_focus_state_e state_for_playback;
+ sound_stream_focus_state_e state_for_recording;
+ int ret = -1;
mp_util_release_cpu();
PLAYER_ENTER_LOG("pause");
err = g_player_apis.pause(_player);
- if (ad->stream_info) {
+
+ ret =
+ sound_manager_get_focus_state(ad->stream_info,
+ &state_for_playback,
+ &state_for_recording);
+ if (ret != SOUND_MANAGER_ERROR_NONE) {
+ DEBUG_TRACE("failed to get focus state error[%x]", ret);
+ }
+
+ if (ad->stream_info && state_for_playback != SOUND_STREAM_FOCUS_STATE_RELEASED) {
error =
sound_manager_release_focus(ad->stream_info,
SOUND_STREAM_FOCUS_FOR_PLAYBACK,
ERROR_TRACE("failed to release focus error[%x]", error);
}
}
+
PLAYER_LEAVE_LOG("pause");
if (err != PLAYER_ERROR_NONE) {
return 0;
}
+static void mp_player_pause_main_thread_callback(void *user_data) {
+ DEBUG_TRACE("Main loop thread safe pause callback called");
+ mp_player_mgr_pause(user_data);
+}
+
+static void mp_player_control_play_pause_main_thread_callback(void *user_data) {
+ DEBUG_TRACE("Main loop thread safe control-play-pause callback called");
+ struct appdata *ad = user_data;
+ mp_play_control_play_pause(ad, true);
+}
+
void mp_player_focus_callback(sound_stream_info_h stream_info,
sound_stream_focus_mask_e focus_mask,
sound_stream_focus_state_e focus_state,
if (focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK
&& focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED) {
- mp_player_mgr_pause(ad);
-
+ // this callback is called from internal thread of sound manager not from main thread
+ // elementry api need to be called from main thread to work
+ // so we can't update ui in this thread.
+ // we need to add main loop callback to update ui.
+ ecore_main_loop_thread_safe_call_sync(mp_player_pause_main_thread_callback, ad);
sound_manager_get_focus_reacquisition(ad->stream_info,
&reacquire_state);
DEBUG_TRACE("reason for change is %d", reason_for_change);
EINA_TRUE);
}
} else {
- mp_play_control_play_pause(ad, true);
+ // this callback is called from internal thread of sound manager not from main thread
+ // elementry api need to be called from main thread to work
+ // so we can't update ui in this thread.
+ // we need to add main loop callback to update ui.
+ ecore_main_loop_thread_safe_call_sync(mp_player_control_play_pause_main_thread_callback, ad);
}
}