From 3b52d3a3286c27c35605661453ac71dc8e8743cf Mon Sep 17 00:00:00 2001 From: Gennadiy Azarov Date: Fri, 26 Aug 2016 09:32:51 +0300 Subject: [PATCH] Revert of "Revert "TizenRefApp-6972 Adopting to new sound-manager adding listener API"" This reverts commit f7ac6e1a3a0adca8f2220c604d92ef3beec1a38c. Change-Id: I0ee1a4f2688665d36d55189d4a5f2a8124612a60 Signed-off-by: Gennadiy Azarov --- src/Viewer/Utils/inc/MediaPlayer.h | 4 +++- src/Viewer/Utils/src/MediaPlayer.cpp | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Viewer/Utils/inc/MediaPlayer.h b/src/Viewer/Utils/inc/MediaPlayer.h index e9397c9..3a856bb 100644 --- a/src/Viewer/Utils/inc/MediaPlayer.h +++ b/src/Viewer/Utils/inc/MediaPlayer.h @@ -52,7 +52,7 @@ namespace Msg static void on_seek_cb(void *user_data); // Cll from media internal thread: - static void on_sound_stream_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask, + static void on_sound_stream_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data); player_state_e getState() const; @@ -62,6 +62,8 @@ namespace Msg IMediaPlayerListener *m_pListener; bool m_Focus; bool m_FocusCallReason; + + int m_SoundManagerCallbackId; }; class IMediaPlayerListener diff --git a/src/Viewer/Utils/src/MediaPlayer.cpp b/src/Viewer/Utils/src/MediaPlayer.cpp index 6e20496..caad317 100644 --- a/src/Viewer/Utils/src/MediaPlayer.cpp +++ b/src/Viewer/Utils/src/MediaPlayer.cpp @@ -29,8 +29,12 @@ MediaPlayer::MediaPlayer() , m_pListener(nullptr) , m_Focus(false) , m_FocusCallReason(false) + , m_SoundManagerCallbackId(-1) { - sound_manager_set_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, on_sound_stream_focus_state_watch_cb, this); + sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, + on_sound_stream_focus_state_watch_cb, this, &m_SoundManagerCallbackId); + + MSG_LOG("callback-id = ", m_SoundManagerCallbackId); player_create(&m_Player); player_set_sound_type(m_Player, SOUND_TYPE_MEDIA); player_set_volume(m_Player, 1.0, 1.0); @@ -40,7 +44,7 @@ MediaPlayer::MediaPlayer() MediaPlayer::~MediaPlayer() { - sound_manager_unset_focus_state_watch_cb(); + sound_manager_remove_focus_state_watch_cb(m_SoundManagerCallbackId); m_pListener = nullptr; stop(); player_unprepare(m_Player); @@ -152,14 +156,20 @@ void MediaPlayer::on_seek_cb(void *user_data) MSG_LOG(""); } -void MediaPlayer::on_sound_stream_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask, - sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, - const char *extra_info, void *user_data) +void MediaPlayer::on_sound_stream_focus_state_watch_cb(int id, + sound_stream_focus_mask_e focus_mask, + sound_stream_focus_state_e focus_state, + sound_stream_focus_change_reason_e reason, + const char *extra_info, + void *user_data) { + MSG_LOG("callback-id = ", id); MSG_LOG("Interrupted focus state = ", focus_state); MSG_LOG("Interrupted focus change reason = ", reason); auto *self = static_cast(user_data); + if(id != self->m_SoundManagerCallbackId) + return; self->m_Focus = focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED; self->m_FocusCallReason = reason == SOUND_STREAM_FOCUS_CHANGED_BY_RINGTONE || reason == SOUND_STREAM_FOCUS_CHANGED_BY_VOIP || -- 2.7.4