2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali/dali.h>
22 using namespace Toolkit;
26 const int SEEK_POS(5000);
27 const int INIT_WIDTH(600);
28 const int INIT_HEIGHT(400);
29 const int BUTTON_SIZE(80);
31 const char* const PLAY_FILE = DEMO_VIDEO_DIR "demoVideo.mp4";
32 const char* const PLAY_IMAGE = DEMO_IMAGE_DIR "icon-play.png";
33 const char* const PAUSE_IMAGE = DEMO_IMAGE_DIR "Pause.png";
34 const char* const CHANGE_IMAGE = DEMO_IMAGE_DIR "icon-change.png";
35 const char* const FORWARD_IMAGE = DEMO_IMAGE_DIR "Forward.png";
36 const char* const BACKWARD_IMAGE = DEMO_IMAGE_DIR "Backward.png";
40 class VideoViewController : public ConnectionTracker
43 VideoViewController(Application& application)
44 : mApplication(application),
48 mPinchStartScale(1.0f)
50 // Connect to the Application's Init signal
51 mApplication.InitSignal().Connect(this, &VideoViewController::Create);
54 ~VideoViewController()
59 void Create(Application& application)
61 Window window = application.GetWindow();
62 mWindowSize = window.GetSize();
64 mVideoView = Toolkit::VideoView::New();
65 window.Add(mVideoView);
66 mVideoView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
67 mVideoView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
68 mVideoView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
69 mVideoView.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, INIT_HEIGHT));
70 mVideoView.SetProperty(VideoView::Property::LOOPING, true);
71 mVideoView.SetProperty(VideoView::Property::MUTED, false);
72 mVideoView.SetProperty(VideoView::Property::VIDEO, PLAY_FILE);
75 mMenu.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT);
76 mMenu.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT);
77 mMenu.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
78 mMenu.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, 120));
79 mVideoView.Add(mMenu);
81 mPlayButton = PushButton::New();
82 mPlayButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
83 mPlayButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
84 mPlayButton.SetProperty(Dali::Actor::Property::NAME, "Play");
85 mPlayButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
86 mPlayButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE));
87 mPlayButton.SetProperty(Actor::Property::POSITION, Vector2(40, 10));
88 mPlayButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked);
90 mPauseButton = PushButton::New();
91 mPauseButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
92 mPauseButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
93 mPauseButton.SetProperty(Dali::Actor::Property::NAME, "Pause");
94 mPauseButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
95 mPauseButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE));
96 mPauseButton.SetProperty(Actor::Property::POSITION, Vector2(40, 10));
97 mPauseButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked);
99 mChangeButton = PushButton::New();
100 mChangeButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
101 mChangeButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
102 mChangeButton.SetProperty(Dali::Actor::Property::NAME, "Change");
103 mChangeButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
104 mChangeButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE));
105 mChangeButton.SetProperty(Actor::Property::POSITION, Vector2(140, 10));
106 mChangeButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked);
108 mBackwardButton = PushButton::New();
109 mBackwardButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
110 mBackwardButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
111 mBackwardButton.SetProperty(Dali::Actor::Property::NAME, "Backward");
112 mBackwardButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
113 mBackwardButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE));
114 mBackwardButton.SetProperty(Actor::Property::POSITION, Vector2(240, 10));
115 mBackwardButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked);
117 mForwardButton = PushButton::New();
118 mForwardButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
119 mForwardButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
120 mForwardButton.SetProperty(Dali::Actor::Property::NAME, "Forward");
121 mForwardButton.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
122 mForwardButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE, BUTTON_SIZE));
123 mForwardButton.SetProperty(Actor::Property::POSITION, Vector2(340, 10));
124 mForwardButton.ClickedSignal().Connect(this, &VideoViewController::OnButtonClicked);
126 mMenu.Add(mPlayButton);
127 mMenu.Add(mPauseButton);
128 mMenu.Add(mChangeButton);
129 mMenu.Add(mBackwardButton);
130 mMenu.Add(mForwardButton);
132 mPauseButton.SetProperty(Actor::Property::VISIBLE, false);
133 mPauseButton.SetProperty(Button::Property::DISABLED, true);
134 mPlayButton.SetProperty(Actor::Property::VISIBLE, true);
135 mPlayButton.SetProperty(Button::Property::DISABLED, false);
136 mChangeButton.SetProperty(Actor::Property::VISIBLE, true);
137 mChangeButton.SetProperty(Button::Property::DISABLED, false);
139 mPlayButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE);
140 mPlayButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE);
141 mPauseButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE);
142 mPauseButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE);
144 mChangeButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE);
145 mChangeButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE);
147 mBackwardButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE);
148 mBackwardButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE);
149 mForwardButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE);
150 mForwardButton.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE);
152 mPanGestureDetector = PanGestureDetector::New();
153 mPanGestureDetector.Attach(mVideoView);
154 mPanGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnPan);
156 mPinchGestureDetector = PinchGestureDetector::New();
157 mPinchGestureDetector.Attach(mVideoView);
158 mPinchGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnPinch);
160 mTapGestureDetector = TapGestureDetector::New();
161 mTapGestureDetector.Attach(mVideoView);
162 mTapGestureDetector.DetectedSignal().Connect(this, &VideoViewController::OnTap);
164 mRotationAnimation = Animation::New(2.f);
165 mRotationAnimation.AnimateBy(Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)));
166 mRotationAnimation.SetLooping(false);
168 window.KeyEventSignal().Connect(this, &VideoViewController::OnKeyEvent);
171 bool OnButtonClicked(Button button)
173 if(mPauseButton.GetProperty<int>(Actor::Property::ID) == button.GetProperty<int>(Actor::Property::ID))
177 mPauseButton.SetProperty(Actor::Property::VISIBLE, false);
178 mPauseButton.SetProperty(Button::Property::DISABLED, true);
179 mPlayButton.SetProperty(Actor::Property::VISIBLE, true);
180 mPlayButton.SetProperty(Button::Property::DISABLED, false);
186 else if(mPlayButton.GetProperty<int>(Actor::Property::ID) == button.GetProperty<int>(Actor::Property::ID))
188 mPauseButton.SetProperty(Actor::Property::VISIBLE, true);
189 mPauseButton.SetProperty(Button::Property::DISABLED, false);
190 mPlayButton.SetProperty(Actor::Property::VISIBLE, false);
191 mPlayButton.SetProperty(Button::Property::DISABLED, true);
196 else if(mChangeButton.GetProperty<int>(Actor::Property::ID) == button.GetProperty<int>(Actor::Property::ID))
198 bool underlay = false;
199 underlay = mVideoView.GetProperty(Toolkit::VideoView::Property::UNDERLAY).Get<bool>();
202 mVideoView.SetProperty(Toolkit::VideoView::Property::UNDERLAY, false);
206 mVideoView.SetProperty(Toolkit::VideoView::Property::UNDERLAY, true);
209 else if(mBackwardButton.GetProperty<int>(Actor::Property::ID) == button.GetProperty<int>(Actor::Property::ID))
211 mVideoView.Backward(SEEK_POS);
213 else if(mForwardButton.GetProperty<int>(Actor::Property::ID) == button.GetProperty<int>(Actor::Property::ID))
215 mVideoView.Forward(SEEK_POS);
221 void OnPan(Actor actor, const PanGesture& gesture)
223 if(!mIsFullScreen && gesture.GetState() == GestureState::CONTINUING)
225 mVideoView.TranslateBy(Vector3(gesture.GetDisplacement()));
229 void OnPinch(Actor actor, const PinchGesture& gesture)
231 GestureState state = gesture.GetState();
232 if(state == GestureState::STARTED)
234 mPinchStartScale = mScale;
237 if(state == GestureState::FINISHED)
239 mScale = mPinchStartScale * gesture.GetScale();
240 mVideoView.SetProperty(Actor::Property::SCALE, mScale);
244 void OnTap(Actor actor, const TapGesture& tapGesture)
248 mVideoView.SetProperty(Actor::Property::SIZE, mWindowSize);
249 mIsFullScreen = true;
253 mVideoView.SetProperty(Actor::Property::SIZE, Vector2(INIT_WIDTH, INIT_HEIGHT));
254 mIsFullScreen = false;
260 * Main key event handler
262 void OnKeyEvent(const KeyEvent& event)
264 if(event.GetState() == KeyEvent::DOWN)
266 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
274 Application& mApplication;
275 VideoView mVideoView;
282 PushButton mPlayButton;
283 PushButton mPauseButton;
284 PushButton mChangeButton;
285 PushButton mResetButton;
286 PushButton mBackwardButton;
287 PushButton mForwardButton;
289 PanGestureDetector mPanGestureDetector;
290 PinchGestureDetector mPinchGestureDetector;
291 TapGestureDetector mTapGestureDetector;
293 float mPinchStartScale;
295 Animation mRotationAnimation;
298 int DALI_EXPORT_API main(int argc, char** argv)
300 Application application = Application::New(&argc, &argv, DEMO_THEME_PATH);
301 VideoViewController test(application);
302 application.MainLoop();