From f3502898cbbc23dbf1a7780d8dddb435e60f42e5 Mon Sep 17 00:00:00 2001 From: rahul varna Date: Tue, 16 Apr 2013 16:02:46 +0900 Subject: [PATCH] Resuming Playback when headset is removed while playing video:N_SE-34638 Signed-off-by: rahul varna --- project/src/MediaApp.cpp | 11 +++++---- project/src/Player/CameraPlayerForm.cpp | 31 +++++++++++++++++++++++++- project/src/Player/CameraPlayerForm.h | 2 ++ project/src/Player/VideoRecorderPlayerForm.cpp | 31 +++++++++++++++++++++++++- project/src/Player/VideoRecorderPlayerForm.h | 2 ++ 5 files changed, 71 insertions(+), 6 deletions(-) diff --git a/project/src/MediaApp.cpp b/project/src/MediaApp.cpp index 454836a..73c1f0b 100644 --- a/project/src/MediaApp.cpp +++ b/project/src/MediaApp.cpp @@ -43,7 +43,9 @@ MediaApp::CreateInstance(void) bool MediaApp::OnAppInitializing(AppRegistry& appRegistry) { - Tizen::System::DeviceManager::AddDeviceEventListener(Charger,*this); + Tizen::System::DeviceManager::AddDeviceEventListener(DEVICE_TYPE_WIRED_HEADSET,*this); + Tizen::System::DeviceManager::AddDeviceEventListener(DEVICE_TYPE_WIRED_HEADPHONE,*this); + Tizen::System::DeviceManager::AddDeviceEventListener(DEVICE_TYPE_CHARGER,*this); MediaAppFrame* pMediaAppFrame = new (std::nothrow) MediaAppFrame(); pMediaAppFrame->Construct(); @@ -72,19 +74,20 @@ MediaApp::IsBatteryLevelLow(void) { TryReturn( (isCharging == true), true,"Battery level is Low"); } - return false; } void MediaApp::OnDeviceStateChanged(DeviceType deviceType, const Tizen::Base::String &state) { - if(deviceType == Charger) + if(deviceType == DEVICE_TYPE_CHARGER || + deviceType == DEVICE_TYPE_WIRED_HEADSET || + deviceType == DEVICE_TYPE_WIRED_HEADPHONE) { AppLog("OnDeviceStateChanged"); bool batteryLow = false; batteryLow = IsBatteryLevelLow(); - TryReturnVoid(batteryLow == true, "Battery Low"); + TryReturnVoid(batteryLow == false, "Battery Low"); MultiForm* pForm = (MultiForm*)(SceneManager::GetInstance()->GetCurrentScene()->GetForm()); if (pForm != null) diff --git a/project/src/Player/CameraPlayerForm.cpp b/project/src/Player/CameraPlayerForm.cpp index b729586..0f17359 100644 --- a/project/src/Player/CameraPlayerForm.cpp +++ b/project/src/Player/CameraPlayerForm.cpp @@ -77,6 +77,7 @@ CameraPlayerForm::CameraPlayerForm(void) , __batteryLevelFlag(false) , __isCameraStartedFlag(false) , __startFlag(false) + , __isHeadSetRemoved(false) { } @@ -676,11 +677,24 @@ CameraPlayerForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel void CameraPlayerForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state) { - if (deviceType == Charger) + switch (deviceType) + { + case DEVICE_TYPE_CHARGER: { FreeResources(); Deactivate(); } + break; + case DEVICE_TYPE_WIRED_HEADSET: + //fall through + case DEVICE_TYPE_WIRED_HEADPHONE: + { + __isHeadSetRemoved = true; + } + break; + default: + break; + } } result @@ -859,3 +873,18 @@ CameraPlayerForm::OnPlayerSeekCompleted(result r) { } + +void +CameraPlayerForm::OnPlayerAudioFocusChanged(void) +{ + AppLog("[rr]OnPlayerAudioFocusChanged"); + TryReturnVoid(__pPlayer != null, "Player handle is null"); + if ( __isHeadSetRemoved == true && (__pPlayer->GetState() == PLAYER_STATE_PAUSED)) + { + AppLog("[rr]__isHeadSetRemoved is true"); + result r = E_SUCCESS; + r = __pPlayer->Play(); + TryReturnVoid(r == E_SUCCESS, "[%s] Player Play has failed", GetErrorMessage(r)); + __isHeadSetRemoved = false; + } +} diff --git a/project/src/Player/CameraPlayerForm.h b/project/src/Player/CameraPlayerForm.h index 6babc88..58ca8c8 100644 --- a/project/src/Player/CameraPlayerForm.h +++ b/project/src/Player/CameraPlayerForm.h @@ -60,6 +60,7 @@ protected: virtual void OnPlayerInterrupted(void); virtual void OnPlayerReleased(void); virtual void OnPlayerSeekCompleted(result r); + void OnPlayerAudioFocusChanged(void); virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel); @@ -128,6 +129,7 @@ private: bool __batteryLevelFlag; bool __isCameraStartedFlag; bool __startFlag; + bool __isHeadSetRemoved; }; diff --git a/project/src/Player/VideoRecorderPlayerForm.cpp b/project/src/Player/VideoRecorderPlayerForm.cpp index 9911682..97ba591 100644 --- a/project/src/Player/VideoRecorderPlayerForm.cpp +++ b/project/src/Player/VideoRecorderPlayerForm.cpp @@ -81,6 +81,7 @@ VideoRecorderPlayerForm::VideoRecorderPlayerForm(void) , __batteryLevelFlag(false) , __backGroundFlag(false) , __cameraErrorFlag(false) + , __isHeadSetRemoved(false) , __pVideoRecorder(null) , __pTimer(null) , __pConfig(null) @@ -1141,11 +1142,24 @@ VideoRecorderPlayerForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batte void VideoRecorderPlayerForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state) { - if (deviceType == Charger) + switch (deviceType) + { + case DEVICE_TYPE_CHARGER: { FreeResources(); Deactivate(); } + break; + case DEVICE_TYPE_WIRED_HEADSET: + //fall through + case DEVICE_TYPE_WIRED_HEADPHONE: + { + __isHeadSetRemoved = true; + } + break; + default: + break; + } } result @@ -1307,6 +1321,21 @@ VideoRecorderPlayerForm::OnPlayerSeekCompleted(result r) } void +VideoRecorderPlayerForm::OnPlayerAudioFocusChanged(void) +{ + AppLog("[rr]OnPlayerAudioFocusChanged"); + TryReturnVoid(__pPlayer != null, "Player handle is null"); + if ( __isHeadSetRemoved == true && (__pPlayer->GetState() == PLAYER_STATE_PAUSED)) + { + AppLog("[rr]__isHeadSetRemoved is true"); + result r = E_SUCCESS; + r = __pPlayer->Play(); + TryReturnVoid(r == E_SUCCESS, "[%s] Player Play has failed", GetErrorMessage(r)); + __isHeadSetRemoved = false; + } +} + +void VideoRecorderPlayerForm::OnVideoRecorderCanceled(result r) { AppLog("OnVideoRecorderCanceled"); diff --git a/project/src/Player/VideoRecorderPlayerForm.h b/project/src/Player/VideoRecorderPlayerForm.h index 897c4ed..df3345d 100644 --- a/project/src/Player/VideoRecorderPlayerForm.h +++ b/project/src/Player/VideoRecorderPlayerForm.h @@ -77,6 +77,7 @@ protected: virtual void OnPlayerInterrupted(void); virtual void OnPlayerReleased(void); virtual void OnPlayerSeekCompleted(result r); + void OnPlayerAudioFocusChanged(void); virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId); virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel); @@ -163,6 +164,7 @@ private: bool __batteryLevelFlag; bool __backGroundFlag; bool __cameraErrorFlag; + bool __isHeadSetRemoved; VideoRecorder* __pVideoRecorder; Tizen::Base::String __filePath; Tizen::Base::Runtime::Timer* __pTimer; -- 2.7.4