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/dali.h>
19 #include <dali-toolkit/dali-toolkit.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
44 VideoViewController( Application& application )
45 : mApplication( application ),
47 mIsFullScreen( false ),
49 mPinchStartScale( 1.0f )
51 // Connect to the Application's Init signal
52 mApplication.InitSignal().Connect( this, &VideoViewController::Create );
55 ~VideoViewController()
60 void Create( Application& application )
62 mStageSize = Stage::GetCurrent().GetSize();
64 mVideoView = Toolkit::VideoView::New();
65 Stage::GetCurrent().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 Stage::GetCurrent().KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent );
172 bool OnButtonClicked( Button button )
174 if( mPauseButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
178 mPauseButton.SetProperty( Actor::Property::VISIBLE, false );
179 mPauseButton.SetProperty( Button::Property::DISABLED, true );
180 mPlayButton.SetProperty( Actor::Property::VISIBLE, true );
181 mPlayButton.SetProperty( Button::Property::DISABLED, false );
187 else if( mPlayButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
189 mPauseButton.SetProperty( Actor::Property::VISIBLE, true );
190 mPauseButton.SetProperty( Button::Property::DISABLED, false );
191 mPlayButton.SetProperty( Actor::Property::VISIBLE, false );
192 mPlayButton.SetProperty( Button::Property::DISABLED, true );
197 else if( mChangeButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
199 bool underlay = false;
200 underlay = mVideoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
203 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
207 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
210 else if( mBackwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
212 mVideoView.Backward( SEEK_POS );
214 else if( mForwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
216 mVideoView.Forward( SEEK_POS );
222 void OnPan( Actor actor, const PanGesture& gesture )
224 if( !mIsFullScreen && gesture.state == Gesture::Continuing )
226 mVideoView.TranslateBy( Vector3( gesture.displacement ) );
230 void OnPinch( Actor actor, const PinchGesture& gesture )
232 if( gesture.state == Gesture::Started )
234 mPinchStartScale = mScale;
237 if( gesture.state == Gesture::Finished )
239 mScale = mPinchStartScale * gesture.scale;
240 mVideoView.SetProperty( Actor::Property::SCALE, mScale );
244 void OnTap( Actor actor, const TapGesture& tapGesture )
248 mVideoView.SetProperty( Actor::Property::SIZE, mStageSize );
249 mIsFullScreen = true;
253 mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) );
254 mIsFullScreen = false;
261 * Main key event handler
263 void OnKeyEvent(const KeyEvent& event)
265 if(event.state == KeyEvent::Down)
267 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
275 Application& mApplication;
276 VideoView mVideoView;
283 PushButton mPlayButton;
284 PushButton mPauseButton;
285 PushButton mChangeButton;
286 PushButton mResetButton;
287 PushButton mBackwardButton;
288 PushButton mForwardButton;
290 PanGestureDetector mPanGestureDetector;
291 PinchGestureDetector mPinchGestureDetector;
292 TapGestureDetector mTapGestureDetector;
294 float mPinchStartScale;
296 Animation mRotationAnimation;
299 int DALI_EXPORT_API main( int argc, char **argv )
301 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
302 VideoViewController test( application );
303 application.MainLoop();