TizenRefApp-8518 [Gallery] Implement Volume button in VideoPlayerPage 84/129984/2
authorIgor Nazarov <i.nazarov@samsung.com>
Thu, 18 May 2017 17:19:37 +0000 (20:19 +0300)
committerIgor Nazarov <i.nazarov@samsung.com>
Fri, 19 May 2017 09:08:13 +0000 (12:08 +0300)
- Implemented Volume button functionality in VideoPlayerPage;
- Disabled SCAN_MEDIA_ON_RESUME feature;
- Added AutoHandle class to UCL.

Change-Id: Ib99fbc3a48b15d067d120c5f4cb01ef8bf9bf7ae

inc/config.h
inc/presenters/VideoPlayerPage.h
src/internal.hpp
src/presenters/Instance.cpp
src/presenters/VideoPlayerPage.cpp
tizen-manifest.xml
ucl/inc/ucl/appfw/types.h
ucl/inc/ucl/misc/AutoHandle.h [new file with mode: 0644]

index 927210340327f992bfab2e7f1c90ad1fd066122d..debdc9a3c0a89969559853f646761b2dedb3b5b6 100644 (file)
@@ -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__
index 97ea5c7c498a2d839db32343d3d6ac34deefb844..e3b5fc8ff4cc856704059a7a8899a7054a0b3b3a 100644 (file)
@@ -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;
index 343f37cb61de557113ca205a0516fbe85a7bab52..1ed8f2bb457aba51468cbc4e6984798ee6d87e2c 100644 (file)
@@ -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<decltype(&result)>::type value = {};
+
                const int ret = getter(std::forward<ARGS>(args)..., &value);
                if ((ret != 0) || (!optional && !value)) {
                        UCL_ELOG("get() failed: %d", ret);
index f4c7ce91a58c548794273c191b318fdd8b7de671..137e4e6c928c84870f9cf90b0e1ff1f4e0fba2ef 100644 (file)
@@ -112,7 +112,7 @@ namespace gallery {
 
                setInstancePaused(*m_win, false);
 
-               if (SCAN_MEDIA_ON_RESUME) {
+               if (m_gallery && SCAN_MEDIA_ON_RESUME) {
                        rescanMediaContent();
                }
 
index b286ec967ab7a7d0633685f664cd8df2907f816c..63eba9360eb52d63afc41946c424c37515c5e595 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <efl_util.h>
 
+#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<Widget>(
@@ -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)
index 3f676f566595a83da0378dcbce7ef47b73de073d..816fce797e51681d7236831db68eb35953694767 100644 (file)
@@ -12,6 +12,7 @@
        </ui-application>\r
        <privileges>\r
                <privilege>http://tizen.org/privilege/mediastorage</privilege>\r
+               <privilege>http://tizen.org/privilege/appmanager.launch</privilege>\r
                <privilege>http://tizen.org/privilege/externalstorage</privilege>\r
                <privilege>http://tizen.org/privilege/content.write</privilege>\r
        </privileges>\r
index bb7c740af19aa1c6d82f14762fceedb5fb257d15..afe1f1d98180e8b187ccfb6f13ca54dd402ec00c 100644 (file)
@@ -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<void(SysEvent)>;
+
+       using AutoAppCtrl = AutoHandle<app_control_h, int, app_control_destroy>;
 }
 
 #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 (file)
index 0000000..27c19f4
--- /dev/null
@@ -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 <class HANDLE, class DEL_RET, DEL_RET(*DEL_FUNC)(HANDLE)>
+       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 <class HANDLE, class DEL_RET, DEL_RET(*DEL_FUNC)(HANDLE)>
+       inline void swap(AutoHandle<HANDLE, DEL_RET, DEL_FUNC> &x,
+                       AutoHandle<HANDLE, DEL_RET, DEL_FUNC> &y) noexcept
+       {
+               std::swap(x.value, y.value);
+       }
+}
+
+#endif // __UCL_MISC_AUTO_HANDLE_H__