2 * Copyright (c) 2017 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>
20 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
23 using namespace Toolkit;
27 const int SEEK_POS( 5000 );
28 const int INIT_WIDTH( 600 );
29 const int INIT_HEIGHT( 400 );
30 const int BUTTON_SIZE( 80 );
32 const char* const PLAY_FILE = DEMO_VIDEO_DIR "demoVideo.mp4";
33 const char* const PLAY_IMAGE = DEMO_IMAGE_DIR "icon-play.png";
34 const char* const PAUSE_IMAGE = DEMO_IMAGE_DIR "Pause.png";
35 const char* const CHANGE_IMAGE = DEMO_IMAGE_DIR "icon-change.png";
36 const char* const FORWARD_IMAGE = DEMO_IMAGE_DIR "Forward.png";
37 const char* const BACKWARD_IMAGE = DEMO_IMAGE_DIR "Backward.png";
41 class VideoViewController: public ConnectionTracker
45 VideoViewController( Application& application )
46 : mApplication( application ),
48 mIsFullScreen( false ),
50 mPinchStartScale( 1.0f )
52 // Connect to the Application's Init signal
53 mApplication.InitSignal().Connect( this, &VideoViewController::Create );
56 ~VideoViewController()
61 void Create( Application& application )
63 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
65 mStageSize = Stage::GetCurrent().GetSize();
67 mVideoView = Toolkit::VideoView::New();
68 Stage::GetCurrent().Add( mVideoView );
69 mVideoView.SetParentOrigin( ParentOrigin::CENTER );
70 mVideoView.SetAnchorPoint( AnchorPoint::CENTER );
71 mVideoView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
72 mVideoView.SetSize( INIT_WIDTH, INIT_HEIGHT );
73 mVideoView.SetProperty( VideoView::Property::LOOPING, true );
74 mVideoView.SetProperty( VideoView::Property::MUTED, false );
75 mVideoView.SetProperty( VideoView::Property::VIDEO, PLAY_FILE );
78 mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
79 mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
80 mMenu.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
81 mMenu.SetSize( INIT_WIDTH, 120 );
82 mVideoView.Add( mMenu );
84 mPlayButton = PushButton::New();
85 mPlayButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
86 mPlayButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
87 mPlayButton.SetName( "Play" );
88 mPlayButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
89 mPlayButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
90 mPlayButton.SetPosition( 40, 10 );
91 mPlayButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
93 mPauseButton = PushButton::New();
94 mPauseButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
95 mPauseButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
96 mPauseButton.SetName( "Pause" );
97 mPauseButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
98 mPauseButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
99 mPauseButton.SetPosition( 40, 10 );
100 mPauseButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
102 mChangeButton = PushButton::New();
103 mChangeButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
104 mChangeButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
105 mChangeButton.SetName( "Change" );
106 mChangeButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
107 mChangeButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
108 mChangeButton.SetPosition( 140, 10 );
109 mChangeButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
111 mBackwardButton = PushButton::New();
112 mBackwardButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
113 mBackwardButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
114 mBackwardButton.SetName( "Backward" );
115 mBackwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
116 mBackwardButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
117 mBackwardButton.SetPosition( 240, 10 );
118 mBackwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
120 mForwardButton = PushButton::New();
121 mForwardButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
122 mForwardButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
123 mForwardButton.SetName( "Forward" );
124 mForwardButton.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
125 mForwardButton.SetSize( BUTTON_SIZE, BUTTON_SIZE );
126 mForwardButton.SetPosition( 340, 10 );
127 mForwardButton.ClickedSignal().Connect( this, &VideoViewController::OnButtonClicked );
129 mMenu.Add( mPlayButton );
130 mMenu.Add( mPauseButton );
131 mMenu.Add( mChangeButton );
132 mMenu.Add( mBackwardButton );
133 mMenu.Add( mForwardButton );
135 mPauseButton.SetVisible( false );
136 mPauseButton.SetProperty( Button::Property::DISABLED, true );
137 mPlayButton.SetVisible( true );
138 mPlayButton.SetProperty( Button::Property::DISABLED, false );
139 mChangeButton.SetVisible( true );
140 mChangeButton.SetProperty( Button::Property::DISABLED, false );
142 mPlayButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
143 mPlayButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, PLAY_IMAGE );
144 mPauseButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
145 mPauseButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, PAUSE_IMAGE );
147 mChangeButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
148 mChangeButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CHANGE_IMAGE );
150 mBackwardButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
151 mBackwardButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, BACKWARD_IMAGE );
152 mForwardButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
153 mForwardButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, FORWARD_IMAGE );
155 mPanGestureDetector = PanGestureDetector::New();
156 mPanGestureDetector.Attach( mVideoView );
157 mPanGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPan );
159 mPinchGestureDetector = PinchGestureDetector::New();
160 mPinchGestureDetector.Attach( mVideoView );
161 mPinchGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnPinch );
163 mTapGestureDetector = TapGestureDetector::New();
164 mTapGestureDetector.Attach( mVideoView );
165 mTapGestureDetector.DetectedSignal().Connect( this, &VideoViewController::OnTap );
167 mRotationAnimation = Animation::New(2.f);
168 mRotationAnimation.AnimateBy( Property(mVideoView, Actor::Property::ORIENTATION), Quaternion(Degree(0.f), Degree(360.f), Degree(0.f)) );
169 mRotationAnimation.SetLooping(false);
171 Stage::GetCurrent().KeyEventSignal().Connect( this, &VideoViewController::OnKeyEvent );
175 bool OnButtonClicked( Button button )
177 if( mPauseButton.GetId() == button.GetId())
181 mPauseButton.SetVisible( false );
182 mPauseButton.SetProperty( Button::Property::DISABLED, true );
183 mPlayButton.SetVisible( true );
184 mPlayButton.SetProperty( Button::Property::DISABLED, false );
190 else if( mPlayButton.GetId() == button.GetId())
192 mPauseButton.SetVisible( true );
193 mPauseButton.SetProperty( Button::Property::DISABLED, false );
194 mPlayButton.SetVisible( false );
195 mPlayButton.SetProperty( Button::Property::DISABLED, true );
200 else if( mChangeButton.GetId() == button.GetId())
202 bool underlay = false;
203 underlay = mVideoView.GetProperty( Toolkit::VideoView::Property::UNDERLAY ).Get< bool >();
206 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, false );
210 mVideoView.SetProperty( Toolkit::VideoView::Property::UNDERLAY, true );
213 else if( mBackwardButton.GetId() == button.GetId())
215 mVideoView.Backward( SEEK_POS );
217 else if( mForwardButton.GetId() == button.GetId())
219 mVideoView.Forward( SEEK_POS );
225 void OnPan( Actor actor, const PanGesture& gesture )
227 if( !mIsFullScreen && gesture.state == Gesture::Continuing )
229 mVideoView.TranslateBy( Vector3( gesture.displacement ) );
233 void OnPinch( Actor actor, const PinchGesture& gesture )
235 if( gesture.state == Gesture::Started )
237 mPinchStartScale = mScale;
240 if( gesture.state == Gesture::Finished )
242 mScale = mPinchStartScale * gesture.scale;
243 mVideoView.SetScale( mScale );
247 void OnTap( Actor actor, const TapGesture& tapGesture )
251 mVideoView.SetSize( mStageSize.x, mStageSize.y );
252 mIsFullScreen = true;
256 mVideoView.SetSize( INIT_WIDTH, INIT_HEIGHT );
257 mIsFullScreen = false;
264 * Main key event handler
266 void OnKeyEvent(const KeyEvent& event)
268 if(event.state == KeyEvent::Down)
270 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
278 Application& mApplication;
279 VideoView mVideoView;
286 PushButton mPlayButton;
287 PushButton mPauseButton;
288 PushButton mChangeButton;
289 PushButton mResetButton;
290 PushButton mBackwardButton;
291 PushButton mForwardButton;
293 PanGestureDetector mPanGestureDetector;
294 PinchGestureDetector mPinchGestureDetector;
295 TapGestureDetector mTapGestureDetector;
297 float mPinchStartScale;
299 Animation mRotationAnimation;
302 int DALI_EXPORT_API main( int argc, char **argv )
304 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
305 VideoViewController test( application );
306 application.MainLoop();