2 * Copyright (c) 2019 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 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
64 mStageSize = Stage::GetCurrent().GetSize();
66 mVideoView = Toolkit::VideoView::New();
67 Stage::GetCurrent().Add( mVideoView );
68 mVideoView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
69 mVideoView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
70 mVideoView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
71 mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) );
72 mVideoView.SetProperty( VideoView::Property::LOOPING, true );
73 mVideoView.SetProperty( VideoView::Property::MUTED, false );
74 mVideoView.SetProperty( VideoView::Property::VIDEO, PLAY_FILE );
77 mMenu.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
78 mMenu.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
79 mMenu.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
80 mMenu.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, 120 ) );
81 mVideoView.Add( mMenu );
83 mPlayButton = PushButton::New();
84 mPlayButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
85 mPlayButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
86 mPlayButton.SetProperty( Dali::Actor::Property::NAME, "Play" );
87 mPlayButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
88 mPlayButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
89 mPlayButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 ));
90 mPlayButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
92 mPauseButton = PushButton::New();
93 mPauseButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
94 mPauseButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
95 mPauseButton.SetProperty( Dali::Actor::Property::NAME, "Pause" );
96 mPauseButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
97 mPauseButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
98 mPauseButton.SetProperty( Actor::Property::POSITION, Vector2( 40, 10 ));
99 mPauseButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
101 mChangeButton = PushButton::New();
102 mChangeButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
103 mChangeButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
104 mChangeButton.SetProperty( Dali::Actor::Property::NAME, "Change" );
105 mChangeButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
106 mChangeButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
107 mChangeButton.SetProperty( Actor::Property::POSITION, Vector2( 140, 10 ));
108 mChangeButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
110 mBackwardButton = PushButton::New();
111 mBackwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
112 mBackwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
113 mBackwardButton.SetProperty( Dali::Actor::Property::NAME, "Backward" );
114 mBackwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
115 mBackwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
116 mBackwardButton.SetProperty( Actor::Property::POSITION, Vector2( 240, 10 ));
117 mBackwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
119 mForwardButton = PushButton::New();
120 mForwardButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
121 mForwardButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
122 mForwardButton.SetProperty( Dali::Actor::Property::NAME, "Forward" );
123 mForwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
124 mForwardButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE, BUTTON_SIZE ) );
125 mForwardButton.SetProperty( Actor::Property::POSITION, Vector2( 340, 10 ));
126 mForwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
128 mMenu.Add( mPlayButton );
129 mMenu.Add( mPauseButton );
130 mMenu.Add( mChangeButton );
131 mMenu.Add( mBackwardButton );
132 mMenu.Add( mForwardButton );
134 mPauseButton.SetProperty( Actor::Property::VISIBLE, false );
135 mPauseButton.SetProperty( Button::Property::DISABLED, true );
136 mPlayButton.SetProperty( Actor::Property::VISIBLE, true );
137 mPlayButton.SetProperty( Button::Property::DISABLED, false );
138 mChangeButton.SetProperty( Actor::Property::VISIBLE, true );
139 mChangeButton.SetProperty( Button::Property::DISABLED, false );
141 mPlayButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
142 mPlayButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
143 mPauseButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
144 mPauseButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
146 mChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
147 mChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
149 mBackwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
150 mBackwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
151 mForwardButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
152 mForwardButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
154 mPanGestureDetector = PanGestureDetector::New();
155 mPanGestureDetector.Attach( mVideoView );
156 mPanGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPan );
158 mPinchGestureDetector = PinchGestureDetector::New();
159 mPinchGestureDetector.Attach( mVideoView );
160 mPinchGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPinch );
162 mTapGestureDetector = TapGestureDetector::New();
163 mTapGestureDetector.Attach( mVideoView );
164 mTapGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnTap );
166 mRotationAnimation = Animation::New(2.f);
167 mRotationAnimation.AnimateBy( Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)) );
168 mRotationAnimation.SetLooping(false);
170 Stage::GetCurrent().KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent );
174 bool OnButtonClicked( Button button )
176 if( mPauseButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
180 mPauseButton.SetProperty( Actor::Property::VISIBLE, false );
181 mPauseButton.SetProperty( Button::Property::DISABLED, true );
182 mPlayButton.SetProperty( Actor::Property::VISIBLE, true );
183 mPlayButton.SetProperty( Button::Property::DISABLED, false );
189 else if( mPlayButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
191 mPauseButton.SetProperty( Actor::Property::VISIBLE, true );
192 mPauseButton.SetProperty( Button::Property::DISABLED, false );
193 mPlayButton.SetProperty( Actor::Property::VISIBLE, false );
194 mPlayButton.SetProperty( Button::Property::DISABLED, true );
199 else if( mChangeButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
201 bool underlay = false;
202 underlay = mVideoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
205 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
209 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
212 else if( mBackwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
214 mVideoView.Backward( SEEK_POS );
216 else if( mForwardButton.GetProperty< int >( Actor::Property::ID ) == button.GetProperty< int >( Actor::Property::ID ))
218 mVideoView.Forward( SEEK_POS );
224 void OnPan( Actor actor, const PanGesture& gesture )
226 if( !mIsFullScreen && gesture.state == Gesture::Continuing )
228 mVideoView.TranslateBy( Vector3( gesture.displacement ) );
232 void OnPinch( Actor actor, const PinchGesture& gesture )
234 if( gesture.state == Gesture::Started )
236 mPinchStartScale = mScale;
239 if( gesture.state == Gesture::Finished )
241 mScale = mPinchStartScale * gesture.scale;
242 mVideoView.SetProperty( Actor::Property::SCALE, mScale );
246 void OnTap( Actor actor, const TapGesture& tapGesture )
250 mVideoView.SetProperty( Actor::Property::SIZE, mStageSize );
251 mIsFullScreen = true;
255 mVideoView.SetProperty( Actor::Property::SIZE, Vector2( INIT_WIDTH, INIT_HEIGHT ) );
256 mIsFullScreen = false;
263 * Main key event handler
265 void OnKeyEvent(const KeyEvent& event)
267 if(event.state == KeyEvent::Down)
269 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
277 Application& mApplication;
278 VideoView mVideoView;
285 PushButton mPlayButton;
286 PushButton mPauseButton;
287 PushButton mChangeButton;
288 PushButton mResetButton;
289 PushButton mBackwardButton;
290 PushButton mForwardButton;
292 PanGestureDetector mPanGestureDetector;
293 PinchGestureDetector mPinchGestureDetector;
294 TapGestureDetector mTapGestureDetector;
296 float mPinchStartScale;
298 Animation mRotationAnimation;
301 int DALI_EXPORT_API main( int argc, char **argv )
303 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
304 VideoViewController test( application );
305 application.MainLoop();