From b8d0759ac92f12a0db872d752d69b5a96e4fc272 Mon Sep 17 00:00:00 2001 From: Denis Dolzhenko Date: Mon, 6 Jun 2016 14:33:25 +0300 Subject: [PATCH] Update: MediaPlayer class Change-Id: Ib5a234d3ce19bf719fb7f6f9500d04e2d88feb88 Signed-off-by: Denis Dolzhenko --- src/Viewer/Controller/src/SmilPlayer.cpp | 5 +--- src/Viewer/Utils/inc/MediaPlayer.h | 4 ++-- src/Viewer/Utils/src/MediaPlayer.cpp | 41 +++++++++++++++----------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Viewer/Controller/src/SmilPlayer.cpp b/src/Viewer/Controller/src/SmilPlayer.cpp index f2295b3..da4510c 100644 --- a/src/Viewer/Controller/src/SmilPlayer.cpp +++ b/src/Viewer/Controller/src/SmilPlayer.cpp @@ -277,13 +277,11 @@ unsigned SmilPlayer::getCurrentPageIndex() const void SmilPlayer::showUnableToPlayVideoNotif() { - // TODO: localization "Video" word notification_status_message_post(msg("IDS_MSG_POP_UNABLE_TO_PLAY_DURING_CALL").cStr()); } void SmilPlayer::showUnableToPlayAudioNotif() { - // TODO: localization "Audo" word notification_status_message_post(msg("IDS_MSG_POP_UNABLE_TO_PLAY_DURING_CALL").cStr()); } @@ -308,8 +306,7 @@ void SmilPlayer::onBeforeDelete(View &view) void SmilPlayer::onMediaPlayerSoundFocusChanged() { - MSG_LOG(""); - if(m_MediaPlayer.isPlaying()) + if(m_MediaPlayer.isPlaying() && !m_MediaPlayer.getFocus()) { SmilPage *page = getCurrentPage(); if(page) diff --git a/src/Viewer/Utils/inc/MediaPlayer.h b/src/Viewer/Utils/inc/MediaPlayer.h index 1cce421..7ff07d3 100644 --- a/src/Viewer/Utils/inc/MediaPlayer.h +++ b/src/Viewer/Utils/inc/MediaPlayer.h @@ -44,7 +44,7 @@ namespace Msg int getDuration() const; // msec void setPosition(int msec); static int getDuration(const std::string &uri); - bool isSoundFocusAcquired() const; + bool getFocus() const; private: static void on_completed_cb(void *user_data); @@ -59,7 +59,7 @@ namespace Msg private: player_h m_Player; IMediaPlayerListener *m_pListener; - bool m_IsSoundFocusAcquired; + bool m_Focus; }; class IMediaPlayerListener diff --git a/src/Viewer/Utils/src/MediaPlayer.cpp b/src/Viewer/Utils/src/MediaPlayer.cpp index 45e3922..abd766f 100644 --- a/src/Viewer/Utils/src/MediaPlayer.cpp +++ b/src/Viewer/Utils/src/MediaPlayer.cpp @@ -27,15 +27,14 @@ using namespace Msg; MediaPlayer::MediaPlayer() : m_Player() , m_pListener(nullptr) - , m_IsSoundFocusAcquired(false) + , m_Focus(false) { + sound_manager_set_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, on_sound_stream_focus_state_watch_cb, this); player_create(&m_Player); player_set_sound_type(m_Player, SOUND_TYPE_MEDIA); player_set_volume(m_Player, 1.0, 1.0); player_set_looping(m_Player, false); player_set_completed_cb(m_Player, on_completed_cb, this); - - sound_manager_set_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, on_sound_stream_focus_state_watch_cb, this); } MediaPlayer::~MediaPlayer() @@ -61,9 +60,9 @@ player_state_e MediaPlayer::getState() const return state; } -bool MediaPlayer::isSoundFocusAcquired() const +bool MediaPlayer::getFocus() const { - return m_IsSoundFocusAcquired; + return m_Focus; } void MediaPlayer::start() @@ -154,21 +153,19 @@ void MediaPlayer::on_sound_stream_focus_state_watch_cb(sound_stream_focus_mask_e MSG_LOG("Interrupted focus state = ", focus_state); MSG_LOG("Interrupted focus change reason = ", reason); - if(reason == SOUND_STREAM_FOCUS_CHANGED_BY_CALL) - { - MediaPlayer *self = static_cast(user_data); - self->m_IsSoundFocusAcquired = focus_state == SOUND_STREAM_FOCUS_STATE_ACQUIRED; - ecore_main_loop_thread_safe_call_sync - ( - [](void *data)->void* - { - MSG_LOG(""); - auto *self = (MediaPlayer*)data; - if(self->m_pListener) - self->m_pListener->onMediaPlayerSoundFocusChanged(); - return nullptr; - }, - self - ); - } + auto *self = static_cast(user_data); + self->m_Focus = focus_state == SOUND_STREAM_FOCUS_STATE_RELEASED; + + ecore_main_loop_thread_safe_call_sync + ( + [](void *data)->void* + { + auto *self = (MediaPlayer*)data; + if(self->m_pListener) + self->m_pListener->onMediaPlayerSoundFocusChanged(); + return nullptr; + }, + self + ); + } -- 2.7.4