From: Igor Nazarov Date: Thu, 18 May 2017 17:19:37 +0000 (+0300) Subject: TizenRefApp-8518 [Gallery] Implement Volume button in VideoPlayerPage X-Git-Tag: submit/tizen/20170531.142232~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ccd95fe9cad1d448cef957d675e044743256ae8c;p=profile%2Fwearable%2Fapps%2Fnative%2Fgallery.git TizenRefApp-8518 [Gallery] Implement Volume button in VideoPlayerPage - Implemented Volume button functionality in VideoPlayerPage; - Disabled SCAN_MEDIA_ON_RESUME feature; - Added AutoHandle class to UCL. Change-Id: Ib99fbc3a48b15d067d120c5f4cb01ef8bf9bf7ae --- diff --git a/inc/config.h b/inc/config.h index 9272103..debdc9a 100644 --- a/inc/config.h +++ b/inc/config.h @@ -26,7 +26,7 @@ namespace gallery { constexpr auto BASE_SCALE = 1.3; // TODO Temporary feature while support only offline mode - constexpr auto SCAN_MEDIA_ON_RESUME = true; + constexpr auto SCAN_MEDIA_ON_RESUME = false; } #endif // __GALLERY_CONFIG_H__ diff --git a/inc/presenters/VideoPlayerPage.h b/inc/presenters/VideoPlayerPage.h index 97ea5c7..e3b5fc8 100644 --- a/inc/presenters/VideoPlayerPage.h +++ b/inc/presenters/VideoPlayerPage.h @@ -23,6 +23,8 @@ #include "Page.h" +#include "model/SoundManager.h" + namespace gallery { class VideoPlayerPage final : public Page { @@ -49,6 +51,8 @@ namespace gallery { ucl::Result prepare(); + ucl::Result prepareSoundManager(); + void createImage(); ucl::Result preparePlayer(); ucl::Result seekToStart(); @@ -66,6 +70,7 @@ namespace gallery { void showControls(); void hideControls(); + void showVolumeBtn(); bool updatePlayTimeText(); void updatePlayTimeText(int timeMs); @@ -76,6 +81,11 @@ namespace gallery { void setScreenOlwaysOn(bool isAlwaysOn); + ucl::Result launchVolumeSettings(); + + void onMediaDeviceStateChanged(); + void onMediaVolumeChanged(); + void onPlaybackComplete(); void onPlaybackInterrupted(player_interrupted_code_e code); void onSeekComplete(); @@ -84,8 +94,7 @@ namespace gallery { Eina_Bool onControlsHideTimer(); Eina_Bool onTickTimer(); - void onVolumeOnBtnClick(ucl::Widget &sender, void *eventInfo); - void onVolumeMuteBtnClick(ucl::Widget &sender, void *eventInfo); + void onVolumeBtnClick(ucl::Widget &sender, void *eventInfo); void onPlayBtnClick(ucl::Widget &sender, void *eventInfo); void onPauseBtnClick(ucl::Widget &sender, void *eventInfo); void onTap(int x, int y); @@ -102,6 +111,7 @@ namespace gallery { private: const MediaItemSRef m_media; + SoundManagerSRef m_soundMgr; ucl::LayoutSRef m_content; ucl::WidgetSRef m_image; TouchParserSRef m_touchParser; diff --git a/src/internal.hpp b/src/internal.hpp index 343f37c..1ed8f2b 100644 --- a/src/internal.hpp +++ b/src/internal.hpp @@ -44,7 +44,8 @@ namespace gallery { namespace util { namespace himpl { inline ucl::Result get(GETTER &&getter, bool optional, V &result, ARGS &&...args) { - V value = {}; + typename std::remove_pointer::type value = {}; + const int ret = getter(std::forward(args)..., &value); if ((ret != 0) || (!optional && !value)) { UCL_ELOG("get() failed: %d", ret); diff --git a/src/presenters/Instance.cpp b/src/presenters/Instance.cpp index f4c7ce9..137e4e6 100644 --- a/src/presenters/Instance.cpp +++ b/src/presenters/Instance.cpp @@ -112,7 +112,7 @@ namespace gallery { setInstancePaused(*m_win, false); - if (SCAN_MEDIA_ON_RESUME) { + if (m_gallery && SCAN_MEDIA_ON_RESUME) { rescanMediaContent(); } diff --git a/src/presenters/VideoPlayerPage.cpp b/src/presenters/VideoPlayerPage.cpp index b286ec9..63eba93 100644 --- a/src/presenters/VideoPlayerPage.cpp +++ b/src/presenters/VideoPlayerPage.cpp @@ -18,6 +18,8 @@ #include +#include "ucl/appfw/types.h" + #include "model/MediaItem.h" #include "view/TouchParser.h" @@ -170,6 +172,8 @@ namespace gallery { Result VideoPlayerPage::prepare() { + FAIL_LOG(prepareSoundManager(), "prepareSoundManager() failed!"); + m_content = Layout::Builder(). setTheme(impl::LAYOUT_VIDEO_PLAYER). setIsOwner(true). @@ -209,6 +213,22 @@ namespace gallery { return RES_OK; } + Result VideoPlayerPage::prepareSoundManager() + { + m_soundMgr = SoundManager::newInstance(); + if (!m_soundMgr) { + LOG_RETURN(RES_FAIL, "SoundManager::newInstance() failed!"); + } + + m_soundMgr->addMediaDeviceStateChangeHandler(WEAK_DELEGATE( + VideoPlayerPage::onMediaDeviceStateChanged, asWeak(*this))); + + m_soundMgr->addMediaVolumeChangeHandler(WEAK_DELEGATE( + VideoPlayerPage::onMediaVolumeChanged, asWeak(*this))); + + return RES_OK; + } + void VideoPlayerPage::createImage() { m_image = makeShared( @@ -265,11 +285,11 @@ namespace gallery { void VideoPlayerPage::createControls() { createButton(impl::STYLE_VOLUME_ON_BTN, impl::PART_VOLUME_ON_BTN, - WEAK_DELEGATE(VideoPlayerPage::onVolumeOnBtnClick, + WEAK_DELEGATE(VideoPlayerPage::onVolumeBtnClick, asWeak(*this))); createButton(impl::STYLE_VOLUME_MUTE_BTN, impl::PART_VOLUME_MUTE_BTN, - WEAK_DELEGATE(VideoPlayerPage::onVolumeMuteBtnClick, + WEAK_DELEGATE(VideoPlayerPage::onVolumeBtnClick, asWeak(*this))); createButton(impl::STYLE_PLAY_BTN, impl::PART_PLAY_BTN, @@ -345,6 +365,10 @@ namespace gallery { if (!m_isControlsVisible) { m_isControlsVisible = true; + if (m_soundMgr && m_soundMgr->isMediaDeviceReady()) { + showVolumeBtn(); + } + if (m_state == State::PLAYING) { m_content->emit(impl::SHOW_PAUSE_BTN); resetTickTimer(); @@ -373,6 +397,15 @@ namespace gallery { } } + void VideoPlayerPage::showVolumeBtn() + { + if (m_soundMgr->getCurrentMediaVolume() > 0) { + m_content->emit(impl::SHOW_VOLUME_ON_BTN); + } else { + m_content->emit(impl::SHOW_VOLUME_MUTE_BTN); + } + } + bool VideoPlayerPage::updatePlayTimeText() { int playPosition = 0; @@ -485,6 +518,48 @@ namespace gallery { EFL_UTIL_SCREEN_MODE_DEFAULT)); } + Result VideoPlayerPage::launchVolumeSettings() + { + AutoAppCtrl appCtrl; + + FAIL_RETURN(util::getNz(app_control_create, appCtrl), + "app_control_create() failed!"); + + FAIL_RETURN(util::call(app_control_set_app_id, + appCtrl, "org.tizen.watch-setting"), + "app_control_set_app_id() failed!"); + + FAIL_RETURN(util::call(app_control_add_extra_data, + appCtrl, "launch-type", "volume"), + "app_control_add_extra_data() failed!"); + + FAIL_RETURN(util::call(app_control_send_launch_request, + appCtrl, nullptr, nullptr), + "app_control_send_launch_request() failed!"); + + return RES_OK; + } + + void VideoPlayerPage::onMediaDeviceStateChanged() + { + if (m_isControlsVisible) { + if (m_soundMgr->isMediaDeviceReady()) { + showVolumeBtn(); + } else { + m_content->emit(impl::HIDE_VOLUME_BTN); + } + } + } + + void VideoPlayerPage::onMediaVolumeChanged() + { + if (m_isControlsVisible) { + if (m_soundMgr->isMediaDeviceReady()) { + showVolumeBtn(); + } + } + } + void VideoPlayerPage::onPlaybackComplete() { m_isPlaybackCompleted = true; @@ -536,12 +611,9 @@ namespace gallery { return ECORE_CALLBACK_RENEW; } - void VideoPlayerPage::onVolumeOnBtnClick(Widget &sender, void *eventInfo) - { - } - - void VideoPlayerPage::onVolumeMuteBtnClick(Widget &sender, void *eventInfo) + void VideoPlayerPage::onVolumeBtnClick(Widget &sender, void *eventInfo) { + FAIL_LOG(launchVolumeSettings(), "launchVolumeSettings() failed!"); } void VideoPlayerPage::onPlayBtnClick(Widget &sender, void *eventInfo) diff --git a/tizen-manifest.xml b/tizen-manifest.xml index 3f676f5..816fce7 100644 --- a/tizen-manifest.xml +++ b/tizen-manifest.xml @@ -12,6 +12,7 @@ http://tizen.org/privilege/mediastorage + http://tizen.org/privilege/appmanager.launch http://tizen.org/privilege/externalstorage http://tizen.org/privilege/content.write diff --git a/ucl/inc/ucl/appfw/types.h b/ucl/inc/ucl/appfw/types.h index bb7c740..afe1f1d 100644 --- a/ucl/inc/ucl/appfw/types.h +++ b/ucl/inc/ucl/appfw/types.h @@ -25,6 +25,7 @@ #include "ucl/misc/HashMap.h" #include "ucl/misc/Event.h" +#include "ucl/misc/AutoHandle.h" namespace ucl { @@ -57,6 +58,8 @@ namespace ucl { }; using SysEventHandler = Delegate; + + using AutoAppCtrl = AutoHandle; } #endif // __UCL_APPFW_TYPES_H__ diff --git a/ucl/inc/ucl/misc/AutoHandle.h b/ucl/inc/ucl/misc/AutoHandle.h new file mode 100644 index 0000000..27c19f4 --- /dev/null +++ b/ucl/inc/ucl/misc/AutoHandle.h @@ -0,0 +1,92 @@ +/* + * Copyright 2017 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UCL_MISC_AUTO_HANDLE_H__ +#define __UCL_MISC_AUTO_HANDLE_H__ + +#include "ucl/util/types.h" + +namespace ucl { + + template + struct AutoHandle final : ucl::NonCopyable { + using Handle = HANDLE; + + HANDLE value; + + AutoHandle() : + value() + { + } + + AutoHandle(std::nullptr_t) : + AutoHandle() + { + } + + AutoHandle(HANDLE value) : + value(value) + { + } + + ~AutoHandle() + { + if (value) { + DEL_FUNC(value); + } + } + + AutoHandle(AutoHandle &&src) : + value(src.value) + { + src.value = nullptr; + } + + AutoHandle &operator=(AutoHandle src) + { + swap(*this, src); + return *this; + } + + AutoHandle &operator=(HANDLE value) + { + AutoHandle src{value}; + swap(*this, src); + return *this; + } + + HANDLE *operator&() + { + return &value; + } + + operator HANDLE() + { + return value; + } + }; + + // Non-member functions // + + template + inline void swap(AutoHandle &x, + AutoHandle &y) noexcept + { + std::swap(x.value, y.value); + } +} + +#endif // __UCL_MISC_AUTO_HANDLE_H__