Merge with master
[apps/osp/VideoPlayer.git] / src / VpVideoPlayerForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                VpVideoPlayerForm.cpp
19  * @brief               This is the implementation file for VideoPlayerForm class.
20  */
21
22 #include <FSystem.h>
23 #include <FTelephony.h>
24 #include "VpSoundPathPopup.h"
25 #include "VpVideoPlayerApp.h"
26 #include "VpVideoPlayerForm.h"
27 #include "VpVideoPlayerPresentationModel.h"
28 #include "VpTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Base::Utility;
35 using namespace Tizen::Content;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::System;
39 using namespace Tizen::Telephony;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
43
44 static const int MIN_PROGRESS_RANGE = 0;
45 static const int MAX_PROGRESS_RANGE = 100;
46
47 static const int SHOW_CONTROL_DURATION = 5000;
48
49 static const int MILLISECOND = 1000;
50 static const int START_TIME = 0;
51
52 static const int X_BASE = 0;
53 static const int Y_BASE = 0;
54 static const int DIVIDE_BY_TWO = 2;
55
56 static const int X_NORMAL = 0;
57 static const int Y_NORMAL = 310;
58 static const int W_NORMAL = 720;
59 static const int H_NORMAL = 432;
60
61 static const int W_WVGA_PORTRAIT_HEIGHT = 1200;
62 static const int W_WVGA_LANDSCAPE_WIDTH = 1200;
63
64 static const int X_WVGA_PORTRAIT_CONTROLLER = 0;
65 static const int Y_WVGA_PORTRAIT_CONTROLLER = 974;
66 static const int W_WVGA_PORTRAIT_CONTROLLER = 720;
67 static const int H_WVGA_PORTRAIT_CONTROLLER = 226;
68 static const int X_WVGA_PORTRAIT_FIRST_LINE = 0;
69 static const int Y_WVGA_PORTRAIT_FIRST_LINE = 973;
70 static const int W_WVGA_PORTRAIT_FIRST_LINE = 720;
71 static const int H_WVGA_PORTRAIT_FIRST_LINE = 1;
72 static const int X_WVGA_PORTRAIT_CURRENT_TIME = 10;
73 static const int Y_WVGA_PORTRAIT_CURRENT_TIME = 1016;
74 static const int W_WVGA_PORTRAIT_CURRENT_TIME = 130;
75 static const int H_WVGA_PORTRAIT_CURRENT_TIME = 28;
76 static const int X_WVGA_PORTRAIT_SLIDER = 136;
77 static const int Y_WVGA_PORTRAIT_SLIDER = 974;
78 static const int W_WVGA_PORTRAIT_SLIDER = 460;
79 static const int H_WVGA_PORTRAIT_SLIDER = 112;
80 static const int X_WVGA_PORTRAIT_TOTAL_TIME = 580;
81 static const int Y_WVGA_PORTRAIT_TOTAL_TIME = 1016;
82 static const int W_WVGA_PORTRAIT_TOTAL_TIME = 130;
83 static const int H_WVGA_PORTRAIT_TOTAL_TIME = 28;
84 static const int X_WVGA_PORTRAIT_VERTICAL_LEFT_LINE = 136;
85 static const int Y_WVGA_PORTRAIT_VERTICAL_LEFT_LINE = 1086;
86 static const int W_WVGA_PORTRAIT_VERTICAL_LEFT_LINE = 1;
87 static const int H_WVGA_PORTRAIT_VERTICAL_LEFT_LINE = 114;
88 static const int X_WVGA_PORTRAIT_FASTREWIND_BTN = 148;
89 static const int Y_WVGA_PORTRAIT_FASTREWIND_BTN = 1086;
90 static const int W_WVGA_PORTRAIT_FASTREWIND_BTN = 136;
91 static const int H_WVGA_PORTRAIT_FASTREWIND_BTN = 114;
92 static const int X_WVGA_PORTRAIT_PLAYPAUSE_BTN = 292;
93 static const int Y_WVGA_PORTRAIT_PLAYPAUSE_BTN = 1086;
94 static const int W_WVGA_PORTRAIT_PLAYPAUSE_BTN = 136;
95 static const int H_WVGA_PORTRAIT_PLAYPAUSE_BTN = 114;
96 static const int X_WVGA_PORTRAIT_FASTFORWARD_BTN = 436;
97 static const int Y_WVGA_PORTRAIT_FASTFORWARD_BTN = 1086;
98 static const int W_WVGA_PORTRAIT_FASTFORWARD_BTN = 136;
99 static const int H_WVGA_PORTRAIT_FASTFORWARD_BTN = 114;
100 static const int X_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 584;
101 static const int Y_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 1086;
102 static const int W_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 1;
103 static const int H_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 114;
104 static const int X_WVGA_PORTRAIT_BACK_BTN = 584;
105 static const int Y_WVGA_PORTRAIT_BACK_BTN = 1086;
106 static const int W_WVGA_PORTRAIT_BACK_BTN = 136;
107 static const int H_WVGA_PORTRAIT_BACK_BTN = 114;
108
109 static const int X_WVGA_LANDSCAPE_CONTROLLER = 0;
110 static const int Y_WVGA_LANDSCAPE_CONTROLLER = 494;
111 static const int W_WVGA_LANDSCAPE_CONTROLLER = 1200;
112 static const int H_WVGA_LANDSCAPE_CONTROLLER = 226;
113 static const int X_WVGA_LANDSCAPE_FIRST_LINE = 0;
114 static const int Y_WVGA_LANDSCAPE_FIRST_LINE = 493;
115 static const int W_WVGA_LANDSCAPE_FIRST_LINE = 1200;
116 static const int H_WVGA_LANDSCAPE_FIRST_LINE = 1;
117 static const int X_WVGA_LANDSCAPE_CURRENT_TIME = 20;
118 static const int Y_WVGA_LANDSCAPE_CURRENT_TIME = 537;
119 static const int W_WVGA_LANDSCAPE_CURRENT_TIME = 130;
120 static const int H_WVGA_LANDSCAPE_CURRENT_TIME = 26;
121 static const int X_WVGA_LANDSCAPE_SLIDER = 140;
122 static const int Y_WVGA_LANDSCAPE_SLIDER = 494;
123 static const int W_WVGA_LANDSCAPE_SLIDER = 940;
124 static const int H_WVGA_LANDSCAPE_SLIDER = 112;
125 static const int X_WVGA_LANDSCAPE_TOTAL_TIME = 1060;
126 static const int Y_WVGA_LANDSCAPE_TOTAL_TIME = 537;
127 static const int W_WVGA_LANDSCAPE_TOTAL_TIME = 130;
128 static const int H_WVGA_LANDSCAPE_TOTAL_TIME = 26;
129 static const int X_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 212;
130 static const int Y_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 606;
131 static const int W_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 2;
132 static const int H_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 114;
133 static const int X_WVGA_LANDSCAPE_FASTREWIND_BTN = 236;
134 static const int Y_WVGA_LANDSCAPE_FASTREWIND_BTN = 606;
135 static const int W_WVGA_LANDSCAPE_FASTREWIND_BTN = 136;
136 static const int H_WVGA_LANDSCAPE_FASTREWIND_BTN = 114;
137 static const int X_WVGA_LANDSCAPE_PLAYPAUSE_BTN = 552;
138 static const int Y_WVGA_LANDSCAPE_PLAYPAUSE_BTN = 606;
139 static const int W_WVGA_LANDSCAPE_PLAYPAUSE_BTN = 136;
140 static const int H_WVGA_LANDSCAPE_PLAYPAUSE_BTN = 114;
141 static const int X_WVGA_LANDSCAPE_FASTFORWARD_BTN = 858;
142 static const int Y_WVGA_LANDSCAPE_FASTFORWARD_BTN = 606;
143 static const int W_WVGA_LANDSCAPE_FASTFORWARD_BTN = 136;
144 static const int H_WVGA_LANDSCAPE_FASTFORWARD_BTN = 114;
145 static const int X_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 1016;
146 static const int Y_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 606;
147 static const int W_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 2;
148 static const int H_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 114;
149 static const int X_WVGA_LANDSCAPE_BACK_BTN = 1064;
150 static const int Y_WVGA_LANDSCAPE_BACK_BTN = 606;
151 static const int W_WVGA_LANDSCAPE_BACK_BTN = 136;
152 static const int H_WVGA_LANDSCAPE_BACK_BTN = 114;
153
154 static const int X_HVGA_PORTRAIT_CONTROLLER = 0;
155 static const int Y_HVGA_PORTRAIT_CONTROLLER = 1054;
156 static const int W_HVGA_PORTRAIT_CONTROLLER = 720;
157 static const int H_HVGA_PORTRAIT_CONTROLLER = 226;
158 static const int X_HVGA_PORTRAIT_FIRST_LINE = 0;
159 static const int Y_HVGA_PORTRAIT_FIRST_LINE = 1053;
160 static const int W_HVGA_PORTRAIT_FIRST_LINE = 720;
161 static const int H_HVGA_PORTRAIT_FIRST_LINE = 1;
162 static const int X_HVGA_PORTRAIT_CURRENT_TIME = 10;
163 static const int Y_HVGA_PORTRAIT_CURRENT_TIME = 1096;
164 static const int W_HVGA_PORTRAIT_CURRENT_TIME = 130;
165 static const int H_HVGA_PORTRAIT_CURRENT_TIME = 28;
166 static const int X_HVGA_PORTRAIT_SLIDER = 136;
167 static const int Y_HVGA_PORTRAIT_SLIDER = 1054;
168 static const int W_HVGA_PORTRAIT_SLIDER = 460;
169 static const int H_HVGA_PORTRAIT_SLIDER = 112;
170 static const int X_HVGA_PORTRAIT_TOTAL_TIME = 580;
171 static const int Y_HVGA_PORTRAIT_TOTAL_TIME = 1096;
172 static const int W_HVGA_PORTRAIT_TOTAL_TIME = 130;
173 static const int H_HVGA_PORTRAIT_TOTAL_TIME = 28;
174 static const int X_HVGA_PORTRAIT_VERTICAL_LEFT_LINE = 136;
175 static const int Y_HVGA_PORTRAIT_VERTICAL_LEFT_LINE = 1166;
176 static const int W_HVGA_PORTRAIT_VERTICAL_LEFT_LINE = 1;
177 static const int H_HVGA_PORTRAIT_VERTICAL_LEFT_LINE = 114;
178 static const int X_HVGA_PORTRAIT_FASTREWIND_BTN = 148;
179 static const int Y_HVGA_PORTRAIT_FASTREWIND_BTN = 1166;
180 static const int W_HVGA_PORTRAIT_FASTREWIND_BTN = 136;
181 static const int H_HVGA_PORTRAIT_FASTREWIND_BTN = 114;
182 static const int X_HVGA_PORTRAIT_PLAYPAUSE_BTN = 292;
183 static const int Y_HVGA_PORTRAIT_PLAYPAUSE_BTN = 1166;
184 static const int W_HVGA_PORTRAIT_PLAYPAUSE_BTN = 136;
185 static const int H_HVGA_PORTRAIT_PLAYPAUSE_BTN = 114;
186 static const int X_HVGA_PORTRAIT_FASTFORWARD_BTN = 436;
187 static const int Y_HVGA_PORTRAIT_FASTFORWARD_BTN = 1166;
188 static const int W_HVGA_PORTRAIT_FASTFORWARD_BTN = 136;
189 static const int H_HVGA_PORTRAIT_FASTFORWARD_BTN = 114;
190 static const int X_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 584;
191 static const int Y_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 1166;
192 static const int W_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 1;
193 static const int H_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE = 114;
194 static const int X_HVGA_PORTRAIT_BACK_BTN = 584;
195 static const int Y_HVGA_PORTRAIT_BACK_BTN = 1166;
196 static const int W_HVGA_PORTRAIT_BACK_BTN = 136;
197 static const int H_HVGA_PORTRAIT_BACK_BTN = 114;
198
199 static const int X_HVGA_LANDSCAPE_CONTROLLER = 0;
200 static const int Y_HVGA_LANDSCAPE_CONTROLLER = 494;
201 static const int W_HVGA_LANDSCAPE_CONTROLLER = 1280;
202 static const int H_HVGA_LANDSCAPE_CONTROLLER = 226;
203 static const int X_HVGA_LANDSCAPE_FIRST_LINE = 0;
204 static const int Y_HVGA_LANDSCAPE_FIRST_LINE = 493;
205 static const int W_HVGA_LANDSCAPE_FIRST_LINE = 1280;
206 static const int H_HVGA_LANDSCAPE_FIRST_LINE = 1;
207 static const int X_HVGA_LANDSCAPE_CURRENT_TIME = 20;
208 static const int Y_HVGA_LANDSCAPE_CURRENT_TIME = 537;
209 static const int W_HVGA_LANDSCAPE_CURRENT_TIME = 130;
210 static const int H_HVGA_LANDSCAPE_CURRENT_TIME = 26;
211 static const int X_HVGA_LANDSCAPE_SLIDER = 160;
212 static const int Y_HVGA_LANDSCAPE_SLIDER = 494;
213 static const int W_HVGA_LANDSCAPE_SLIDER = 960;
214 static const int H_HVGA_LANDSCAPE_SLIDER = 112;
215 static const int X_HVGA_LANDSCAPE_TOTAL_TIME = 1130;
216 static const int Y_HVGA_LANDSCAPE_TOTAL_TIME = 537;
217 static const int W_HVGA_LANDSCAPE_TOTAL_TIME = 130;
218 static const int H_HVGA_LANDSCAPE_TOTAL_TIME = 26;
219 static const int X_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 212;
220 static const int Y_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 606;
221 static const int W_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 2;
222 static const int H_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE = 114;
223 static const int X_HVGA_LANDSCAPE_FASTREWIND_BTN = 286;
224 static const int Y_HVGA_LANDSCAPE_FASTREWIND_BTN = 606;
225 static const int W_HVGA_LANDSCAPE_FASTREWIND_BTN = 136;
226 static const int H_HVGA_LANDSCAPE_FASTREWIND_BTN = 114;
227 static const int X_HVGA_LANDSCAPE_PLAYPAUSE_BTN = 572;
228 static const int Y_HVGA_LANDSCAPE_PLAYPAUSE_BTN = 606;
229 static const int W_HVGA_LANDSCAPE_PLAYPAUSE_BTN = 136;
230 static const int H_HVGA_LANDSCAPE_PLAYPAUSE_BTN = 114;
231 static const int X_HVGA_LANDSCAPE_FASTFORWARD_BTN = 858;
232 static const int Y_HVGA_LANDSCAPE_FASTFORWARD_BTN = 606;
233 static const int W_HVGA_LANDSCAPE_FASTFORWARD_BTN = 136;
234 static const int H_HVGA_LANDSCAPE_FASTFORWARD_BTN = 114;
235 static const int X_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 1066;
236 static const int Y_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 606;
237 static const int W_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 2;
238 static const int H_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE = 114;
239 static const int X_HVGA_LANDSCAPE_BACK_BTN = 1144;
240 static const int Y_HVGA_LANDSCAPE_BACK_BTN = 606;
241 static const int W_HVGA_LANDSCAPE_BACK_BTN = 136;
242 static const int H_HVGA_LANDSCAPE_BACK_BTN = 114;
243
244 static const int COLOR_THUMB_RED = 0;
245 static const int COLOR_THUMB_GREEN = 0;
246 static const int COLOR_THUMB_BLUE = 0;
247 static const int COLOR_THUMB_ALPHA = 0;
248
249 static const int MESSAGEBOX_DISPLAY_TIME_3_SEC = 3000;
250
251 static const wchar_t* INIT_TIME = L"00:00:00";
252
253 static const RequestId REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU = 111;
254 static const RequestId REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU = 112;
255 static const RequestId REQUEST_UPDATE_BLUETOOTHA2DP_AND_WIRED_ACCESSORY_MENU = 113;
256 static const RequestId REQUEST_VIDEO_EVENT_BATTERY_LEVEL_CHANGED = 114;
257
258 void DestroyPresentationModelInstance(void)
259 {
260         delete VideoPlayerPresentationModel::GetInstance();
261 }
262
263 VideoPlayerForm::VideoPlayerForm(void)
264         : __pOverlayPanel(null)
265         , __screenMode(SCREEN_MODE_NORMAL)
266         , __pSoundPathPopup(null)
267         , __pUiControlTimer(null)
268         , __pAudioRouteManager(null)
269         , __pPlayPauseButton(null)
270         , __pFastForwardButton(null)
271         , __pFastRewindButton(null)
272         , __pBackButton(null)
273         , __pButtonLeftItem(null)
274         , __pButtonRightItem(null)
275         , __pHeader(null)
276         , __pControlLabel(null)
277         , __pCurrenTimeLabel(null)
278         , __pFirstLineLabel(null)
279         , __pTotalTimeLabel(null)
280         , __pVerticalLeftLine(null)
281         , __pVerticalRightLine(null)
282         , __pSlider(null)
283         , __actionTouchLongPressed(false)
284         , __setPauseState(false)
285         , __isControlVisibleState(true)
286         , __audioRouteMode(0)
287         , __pVideoPlayerPresentationModel(null)
288 {
289         for (int count = 0; count < OUTPUT_AUDIO_ROUTE_MAX; ++count)
290         {
291                 __availableAudioRoute[count] = false;
292         }
293 }
294
295 VideoPlayerForm::~VideoPlayerForm(void)
296 {
297 }
298
299 void
300 VideoPlayerForm::Initialize(void)
301 {
302         AppLogDebug("Initialize");
303         Construct(L"IDL_MAIN_FORM");
304 }
305
306 result
307 VideoPlayerForm::SetScreenMode(const ScreenMode mode, bool destroyOverlay)
308 {
309         result r = E_SUCCESS;
310
311         Rectangle clientRect = GetClientAreaBounds();
312
313         switch (mode)
314         {
315         case SCREEN_MODE_NORMAL:
316                 {
317                         bool modified = false;
318
319                         Rectangle rect = Rectangle(X_NORMAL, Y_NORMAL, W_NORMAL, H_NORMAL);
320
321                         if ((clientRect.width - rect.width) <= X_BASE)
322                         {
323                                 rect.x = X_BASE;
324                         }
325                         else
326                         {
327                                 rect.x = (clientRect.width - rect.width) / DIVIDE_BY_TWO;
328                         }
329
330                         if ((clientRect.height - rect.height) <= Y_BASE)
331                         {
332                                 rect.y = Y_BASE;
333                         }
334                         else
335                         {
336                                 rect.y = (clientRect.height - rect.height) / DIVIDE_BY_TWO;
337                         }
338
339                         if (destroyOverlay == true)
340                         {
341                                 if (__pOverlayPanel != null)
342                                 {
343                                         __pOverlayPanel->RemoveTouchEventListener(*this);
344                                         RemoveControl(*__pOverlayPanel);
345                                         __pOverlayPanel = null;
346                                 }
347
348                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
349                                 r = __pOverlayPanel->Construct(rect);
350                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
351
352                                 r = AddControl(*__pOverlayPanel);
353                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
354
355                                 __pOverlayPanel->AddTouchEventListener(*this);
356                         }
357                         else
358                         {
359                                 __pOverlayPanel->SetBounds(rect);
360                         }
361
362                         OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_GREATER_THAN, rect, modified);
363                         AppLogDebug("SCREEN_MODE_NORMAL : [%d][%d][%d][%d]", rect.x, rect.y, rect.width, rect.height);
364
365                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
366
367                         __screenMode = SCREEN_MODE_NORMAL;
368                 }
369                 break;
370
371         case SCREEN_MODE_FULL:
372                 {
373                         bool modified = false;
374
375                         Rectangle rect = Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
376                         AppLogDebug("SetScreenMode [%d] [%d]", rect.height, rect.width);
377
378                         if (destroyOverlay == true)
379                         {
380                                 if (__pOverlayPanel != null)
381                                 {
382                                         __pOverlayPanel->RemoveTouchEventListener(*this);
383                                         RemoveControl(*__pOverlayPanel);
384                                         __pOverlayPanel = null;
385                                 }
386
387                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
388                                 r = __pOverlayPanel->Construct(rect);
389                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
390
391                                 r = AddControl(*__pOverlayPanel);
392                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
393
394                                 __pOverlayPanel->AddTouchEventListener(*this);
395                         }
396                         else
397                         {
398                                 __pOverlayPanel->SetBounds(rect);
399                         }
400
401                         OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_GREATER_THAN, rect, modified);
402                         AppLogDebug("SCREEN_MODE_FULL : [%d][%d][%d][%d]", rect.x, rect.y, rect.width, rect.height);
403
404                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
405
406                         __screenMode = SCREEN_MODE_FULL;
407                 }
408                 break;
409
410         case SCREEN_MODE_FIT:
411                 {
412                         bool modified = false;
413
414                         Rectangle rect = __pVideoPlayerPresentationModel->GetVideoInfoN(
415                                         __pVideoPlayerPresentationModel->GetMediaPathName());
416
417                         if ((clientRect.width - rect.width) <= X_BASE)
418                         {
419                                 rect.x = X_BASE;
420                         }
421                         else
422                         {
423                                 rect.x = (clientRect.width - rect.width) / DIVIDE_BY_TWO;
424                         }
425
426                         if ((clientRect.height - rect.height) <= Y_BASE)
427                         {
428                                 rect.y = Y_BASE;
429                         }
430                         else
431                         {
432                                 rect.y = (clientRect.height - rect.height) / DIVIDE_BY_TWO;
433                         }
434
435                         if (destroyOverlay == true)
436                         {
437                                 if (__pOverlayPanel != null)
438                                 {
439                                         __pOverlayPanel->RemoveTouchEventListener(*this);
440                                         RemoveControl(*__pOverlayPanel);
441                                         __pOverlayPanel = null;
442                                 }
443
444                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
445                                 r = __pOverlayPanel->Construct(rect);
446                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
447
448                                 r = AddControl(*__pOverlayPanel);
449                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
450
451                                 __pOverlayPanel->AddTouchEventListener(*this);
452                         }
453                         else
454                         {
455                                 __pOverlayPanel->SetBounds(rect);
456                         }
457
458                         OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_GREATER_THAN, rect, modified);
459                         AppLogDebug("SCREEN_MODE_FULL : [%d][%d][%d][%d]", rect.x, rect.y, rect.width, rect.height);
460
461                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
462
463                         __screenMode = SCREEN_MODE_FIT;
464                 }
465                 break;
466
467         default:
468                 break;
469         }
470
471         return r;
472
473 CATCH:
474         RemoveControl(*__pOverlayPanel);
475         __pOverlayPanel = null;
476         __screenMode = SCREEN_MODE_NORMAL;
477
478         return r;
479 }
480
481 result
482 VideoPlayerForm::OnInitializing(void)
483 {
484         result r = E_FAILURE;
485
486         Bitmap* pBitmapScreenMode = null;
487         Bitmap* pBitmapSoundPath = null;
488         Bitmap* pSliderThumbNormalBitmap = null;
489         Bitmap* pSliderThumbPressedBitmap = null;
490         Bitmap* pSliderThumbDisableBitmap = null;
491
492         AppLogDebug("OnInitializing");
493
494         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
495
496         AddOrientationEventListener(*this);
497         AddKeyEventListener(*this);
498         AddTouchEventListener(*this);
499
500         r = SetActionBarsTranslucent(FORM_ACTION_BAR_INDICATOR | FORM_ACTION_BAR_HEADER, true);
501         TryCatch(r == E_SUCCESS, , "SetActionBarsTranslucent() failed:%s", GetErrorMessage(r));
502
503         __pAudioRouteManager = AudioRouteManager::GetInstance();
504         __pAudioRouteManager->SetAudioRouteEventListener(this);
505
506         SetScreenMode(SCREEN_MODE_NORMAL, true);
507
508         __pVideoPlayerPresentationModel = VideoPlayerPresentationModel::GetInstance();
509         TryCatch(__pVideoPlayerPresentationModel != null, r = E_SYSTEM, "__pVideoPlayerPresentationModel is null");
510
511         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
512         __pVideoPlayerPresentationModel->InitializePlayer();
513
514         __pVideoPlayerPresentationModel->SetVideoPlayerEventListener(this);
515
516         InitTimer();
517
518         InitAudioRouteList();
519
520         __pHeader = GetHeader();
521
522         __pButtonLeftItem = new (std::nothrow) ButtonItem();
523         __pButtonRightItem = new (std::nothrow) ButtonItem();
524
525         r = __pButtonLeftItem->Construct(BUTTON_ITEM_STYLE_ICON, IDA_BUTTON_FULLSCREEN);
526         TryCatch(r == E_SUCCESS, , "buttonLeftItem->Construct() Failed:%s", GetErrorMessage(r));
527
528         r = __pButtonRightItem->Construct(BUTTON_ITEM_STYLE_ICON, IDA_BUTTON_SOUNDPATH);
529         TryCatch(r == E_SUCCESS, , "buttonRightItem->Construct() Failed:%s", GetErrorMessage(r));
530
531         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
532         {
533                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
534                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
535                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
536
537                 __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
538
539                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
540                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
541                 __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
542         }
543         else
544         {
545                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
546                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
547                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
548
549                 __pButtonLeftItem->SetActionId(IDA_BUTTON_FULLSCREEN);
550                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
551
552                 pBitmapSoundPath = pAppResource->GetBitmapN(L"T01_icon_title_soundpath.png");
553                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapSoundPath);
554                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
555
556                 __pButtonRightItem->SetActionId(IDA_BUTTON_SOUNDPATH);
557                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
558         }
559
560         __pHeader->AddActionEventListener(*this);
561         __pHeader->AddTouchEventListener(*this);
562
563         __pPlayPauseButton = static_cast<Button*>(GetControl("IDC_BUTTON_PLAY"));
564         TryCatch(__pPlayPauseButton != null, r = E_SYSTEM, "__pPlayPauseButton is null");
565         __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
566         __pPlayPauseButton->AddActionEventListener(*this);
567         __pPlayPauseButton->AddTouchEventListener(*this);
568
569         __pFastRewindButton = static_cast<Button*>(GetControl("IDC_BUTTON_FASTREWIND"));
570         TryCatch(__pFastRewindButton != null, r = E_SYSTEM, "__pFastRewindButton is null");
571         __pFastRewindButton->SetActionId(IDA_BUTTON_FASTREWIND);
572         __pFastRewindButton->AddActionEventListener(*this);
573         __pFastRewindButton->AddTouchEventListener(*this);
574
575         __pFastForwardButton = static_cast<Button*>(GetControl("IDC_BUTTON_FASTFORWARD"));
576         TryCatch(__pFastForwardButton != null, r = E_SYSTEM, "__pFastForwardButton is null");
577         __pFastForwardButton->SetActionId(IDA_BUTTON_FASTFORWARD);
578         __pFastForwardButton->AddActionEventListener(*this);
579         __pFastForwardButton->AddTouchEventListener(*this);
580
581         __pBackButton = static_cast<Button*>(GetControl("IDC_BUTTON_BACK"));
582         TryCatch(__pBackButton != null, r = E_SYSTEM, "__pBackButton is null");
583         __pBackButton->SetActionId(IDA_BUTTON_BACK);
584         __pBackButton->AddActionEventListener(*this);
585         __pBackButton->AddTouchEventListener(*this);
586
587         __pSlider = static_cast<Slider*>(GetControl("IDC_SLIDER"));
588         TryCatch(__pSlider != null, r = E_SYSTEM, "__pSlider is null");
589         __pSlider->SetEnabled(true);
590         __pSlider->SetRange(MIN_PROGRESS_RANGE, MAX_PROGRESS_RANGE);
591         __pSlider->SetValue(MIN_PROGRESS_RANGE);
592         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_NORMAL,
593                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
594         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_PRESSED,
595                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
596         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_DISABLED,
597                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
598
599         pSliderThumbNormalBitmap = pAppResource->GetBitmapN(L"T01_controller_progress_handle.png");
600         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_NORMAL, *pSliderThumbNormalBitmap);
601         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
602
603         pSliderThumbPressedBitmap = pAppResource->GetBitmapN(L"T01_controller_progress_handle_press.png");
604         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_PRESSED, *pSliderThumbPressedBitmap);
605         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
606
607         pSliderThumbDisableBitmap = pAppResource->GetBitmapN(L"T01_controller_progress_handle.png");
608         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_DISABLED, *pSliderThumbDisableBitmap);
609         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
610
611         __pSlider->AddAdjustmentEventListener(*this);
612         __pSlider->AddTouchEventListener(*this);
613
614         __pCurrenTimeLabel = static_cast<Label*>(GetControl("IDC_LABEL_CURRENTTIME"));
615         TryCatch(__pCurrenTimeLabel != null, r = E_SYSTEM, "__pCurrenTimeLabel is null");
616         __pCurrenTimeLabel->AddTouchEventListener(*this);
617
618         __pCurrenTimeLabel->SetText(INIT_TIME);
619
620         __pTotalTimeLabel = static_cast<Label*>(GetControl("IDC_LABEL_FULLTIME"));
621         TryCatch(__pTotalTimeLabel != null, r = E_SYSTEM, "__pTotalTimeLabel is null");
622         __pTotalTimeLabel->AddTouchEventListener(*this);
623
624         __pTotalTimeLabel->SetText(INIT_TIME);
625
626         __pControlLabel = static_cast<Label*>(GetControl("IDC_LABEL_BOTTOM_CONTROL_PANEL"));
627         TryCatch(__pControlLabel != null, r = E_SYSTEM, "__pControlLabel is null");
628
629         __pFirstLineLabel = static_cast<Label*>(GetControl("IDC_LABEL_LINE1"));
630         TryCatch(__pFirstLineLabel != null, r = E_SYSTEM, "__pFirstLineLabel is null");
631
632         __pVerticalLeftLine = static_cast<Label*>(GetControl("IDC_LABEL_VERTICAL_LINE_LEFT"));
633         TryCatch(__pVerticalLeftLine != null, r = E_SYSTEM, "__pVerticalLeftLine is null");
634
635         __pVerticalRightLine = static_cast<Label*>(GetControl("IDC_LABEL_VERTICAL_LINE_RIGHT"));
636         TryCatch(__pVerticalRightLine != null, r = E_SYSTEM, "__pVerticalRightLine is null");
637
638         ChangedControlPos();
639
640         delete pBitmapScreenMode;
641         delete pBitmapSoundPath;
642         delete pSliderThumbNormalBitmap;
643         delete pSliderThumbPressedBitmap;
644         delete pSliderThumbDisableBitmap;
645
646         return r;
647
648 CATCH:
649         delete pBitmapScreenMode;
650         delete pBitmapSoundPath;
651         delete pSliderThumbNormalBitmap;
652         delete pSliderThumbPressedBitmap;
653         delete pSliderThumbDisableBitmap;
654
655         DestroyPresentationModelInstance();
656
657         return r;
658 }
659
660 result
661 VideoPlayerForm::OnTerminating(void)
662 {
663         AppLogDebug("OnTerminating");
664         DeleteTimer();
665         DestroyPresentationModelInstance();
666
667         delete __pButtonLeftItem;
668         __pButtonLeftItem = null;
669
670         delete __pButtonRightItem;
671         __pButtonRightItem = null;
672
673         RemoveControl(*__pOverlayPanel);
674         __pOverlayPanel = null;
675
676         delete __pSoundPathPopup;
677         __pSoundPathPopup = null;
678
679         return E_SUCCESS;
680 }
681
682 void
683 VideoPlayerForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
684 {
685         result r = E_FAILURE;
686         AppLogDebug("OnSceneActivatedN");
687
688         String totalTime;
689         Bitmap* pBitmapScreenMode = null;
690
691         Rectangle rect(0, 0, 0, 0);
692
693         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
694
695         CheckCallStatus();
696         CheckLowBatteryStatus();
697
698         r = __pVideoPlayerPresentationModel->StartPlay();
699         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->StartPlay() failed:%s", GetErrorMessage(r));
700
701         GetTotalTime(totalTime);
702
703         AppLogDebug("totalTime [%ls]", totalTime.GetPointer());
704
705         __pTotalTimeLabel->SetText(totalTime);
706         __pTotalTimeLabel->Invalidate(true);
707
708         String mediaPathName = __pVideoPlayerPresentationModel->GetMediaPathName();
709         rect = __pVideoPlayerPresentationModel->GetVideoInfoN(mediaPathName);
710
711         if (rect.width > W_NORMAL || rect.height > W_NORMAL)
712         {
713                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
714
715                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
716                 {
717                         __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
718                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
719                 }
720                 else
721                 {
722                         __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
723                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
724                 }
725         }
726
727         r = PowerManager::KeepScreenOnState(true, false);
728         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
729
730         delete pBitmapScreenMode;
731         pBitmapScreenMode = null;
732 }
733
734 void
735 VideoPlayerForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
736 {
737         result r = E_FAILURE;
738
739         AppLogDebug("OnSceneDeactivated");
740
741         r = __pVideoPlayerPresentationModel->PausePlay();
742         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->PausePlay() failed:%s", GetErrorMessage(r));
743
744         r = PowerManager::KeepScreenOnState(false);
745         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
746 }
747
748 void
749 VideoPlayerForm::OnPlayOpened(result r)
750 {
751         AppLogDebug("OnPlayOpened");
752 }
753
754 void
755 VideoPlayerForm::OnPlayEndOfClip(bool playNextContent)
756 {
757         result r = E_FAILURE;
758
759         Bitmap* pPlayBitmap = null;
760         Bitmap* pBitmapScreenMode = null;
761         Bitmap* pBitmapSoundPath = null;
762
763         AppLogDebug("OnPlayEndOfClip : %d", playNextContent);
764
765         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
766
767         if (__pSoundPathPopup != null)
768         {
769                 if (__pSoundPathPopup->GetShowState() == true)
770                 {
771                         __pSoundPathPopup->SetShowState(false);
772                 }
773         }
774
775         __pUiControlTimer->Cancel();
776         ShowControl(true);
777         UpdateProgressBar(START_TIME);
778
779         __pCurrenTimeLabel->SetText(INIT_TIME);
780         __pCurrenTimeLabel->Invalidate(true);
781
782         pPlayBitmap = pAppResource->GetBitmapN(L"T01_icon_toolbar_play.png");
783         TryCatch(pPlayBitmap != null, r = E_SYSTEM, "pPlayBitmap is null");
784         __pPlayPauseButton->SetNormalBackgroundBitmap(*pPlayBitmap);
785
786         Invalidate(true);
787
788         __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
789
790         __pSlider->SetEnabled(false);
791
792         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
793         {
794                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
795                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
796
797                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
798         }
799         else
800         {
801                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
802                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
803
804                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
805         }
806
807         if (playNextContent == true)
808         {
809                 SetScreenMode(SCREEN_MODE_NORMAL, true);
810                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
811                 __pVideoPlayerPresentationModel->InitializePlayer();
812
813                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
814                 {
815                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
816                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
817                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
818
819                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
820
821                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
822                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
823                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
824                 }
825                 else
826                 {
827                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
828                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
829                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
830
831                         __pButtonLeftItem->SetActionId(IDA_BUTTON_FULLSCREEN);
832                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
833
834                         pBitmapSoundPath = pAppResource->GetBitmapN(L"T01_icon_title_soundpath.png");
835                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapSoundPath);
836                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
837
838                         __pButtonRightItem->SetActionId(IDA_BUTTON_SOUNDPATH);
839                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
840                 }
841
842                 __pSlider->SetEnabled(true);
843
844                 r = __pVideoPlayerPresentationModel->StartPlay();
845                 TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() Failed:%s", GetErrorMessage(r));
846
847                 r = PowerManager::KeepScreenOnState(true, false);
848                 TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
849         }
850         else
851         {
852                 r = PowerManager::KeepScreenOnState(false);
853                 TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
854         }
855
856 CATCH:
857         delete pPlayBitmap;
858         pPlayBitmap = null;
859 }
860
861 void
862 VideoPlayerForm::OnPlayBuffering(int percent)
863 {
864         AppLogDebug("OnPlayBuffering");
865 }
866
867 void
868 VideoPlayerForm::OnPlayErrorOccurred(PlayerErrorReason r)
869 {
870         MessageBox messageBox;
871         String messageBoxString;
872         int modalResult = 0;
873         AppResource* pAppResource = null;
874
875         AppLogDebug("OnPlayErrorOccurred [%d]", r);
876
877         switch (r)
878         {
879         case PLAYER_ERROR_INVALID_DATA:
880                 {
881                         if ((__pVideoPlayerPresentationModel->GetMediaPathName().EndsWith(L"flv") == true)
882                                 || (__pVideoPlayerPresentationModel->GetMediaPathName().EndsWith(L"FLV") == true))
883                         {
884                                 pAppResource = Application::GetInstance()->GetAppResource();
885                                 pAppResource->GetString(IDS_COM_POP_UNSUPPORTED_FILE_TYPE, messageBoxString);
886
887                                 messageBox.Construct(L"", messageBoxString, MSGBOX_STYLE_OK, MESSAGEBOX_DISPLAY_TIME_3_SEC);
888                                 messageBox.ShowAndWait(modalResult);
889
890                                 AppLogDebug("OnPlayErrorOccurred : pApp->Terminate");
891                                 UiApp* pApp = UiApp::GetInstance();
892                                 pApp->Terminate();
893                         }
894                 }
895                 break;
896
897         case PLAYER_ERROR_DEVICE_FAILED:
898                 {
899                         pAppResource = Application::GetInstance()->GetAppResource();
900                         pAppResource->GetString(IDS_VPL_POP_UNABLE_TO_PLAY_VIDEO_ERROR_OCCURRED, messageBoxString);
901
902                         messageBox.Construct(L"", messageBoxString, MSGBOX_STYLE_OK, MESSAGEBOX_DISPLAY_TIME_3_SEC);
903                         messageBox.ShowAndWait(modalResult);
904
905                         AppLogDebug("OnPlayErrorOccurred : pApp->Terminate");
906                         UiApp* pApp = UiApp::GetInstance();
907                         pApp->Terminate();
908                 }
909                 break;
910
911         default:
912                 break;
913         }
914 }
915
916 void
917 VideoPlayerForm::OnPlayInterrupted(void)
918 {
919         AppLogDebug("OnPlayInterrupted");
920 }
921
922 void
923 VideoPlayerForm::OnPlayReleased(void)
924 {
925         AppLogDebug("OnPlayReleased");
926 }
927
928 void
929 VideoPlayerForm::OnActionPerformed(const Control& source, int actionId)
930 {
931         result r = E_FAILURE;
932
933         String currentTime;
934         String totalTime;
935         Rectangle rect;
936         Bitmap* pBitmapScreenMode = null;
937
938         PlayerState playState = PLAYER_STATE_ERROR;
939         AppLogDebug("OnActionPerformed : %d", actionId);
940
941         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
942
943         playState = __pVideoPlayerPresentationModel->GetState();
944
945         Rectangle clientRect = GetClientAreaBounds();
946
947         switch (actionId)
948         {
949         case IDA_BUTTON_PLAY:
950                 {
951                         __setPauseState = false;
952
953                         if ((__pVideoPlayerPresentationModel->GetState() == PLAYER_STATE_ENDOFCLIP))
954                         {
955                                 if (__pVideoPlayerPresentationModel->GetCurrentMediaIndex() != __pVideoPlayerPresentationModel->GetPreviousMediaIndex())
956                                 {
957                                         SetScreenMode(SCREEN_MODE_NORMAL, true);
958                                         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
959                                 }
960                                 __pVideoPlayerPresentationModel->InitializePlayer();
961                         }
962
963                         r = __pVideoPlayerPresentationModel->StartPlay();
964                         TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() failed:%s",
965                                         GetErrorMessage(r));
966
967                         __pSlider->SetEnabled(true);
968
969                         rect = __pVideoPlayerPresentationModel->GetVideoInfoN(
970                                         __pVideoPlayerPresentationModel->GetMediaPathName());
971
972                         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
973                         {
974                                 if (rect.width > W_NORMAL || rect.height > W_NORMAL)
975                                 {
976                                         if (__screenMode == SCREEN_MODE_NORMAL)
977                                         {
978                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
979                                         }
980                                         else if (__screenMode == SCREEN_MODE_FULL)
981                                         {
982                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
983                                         }
984                                 }
985                                 else
986                                 {
987                                         if (__screenMode == SCREEN_MODE_FIT)
988                                         {
989                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
990                                         }
991                                         else if (__screenMode == SCREEN_MODE_NORMAL)
992                                         {
993                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
994                                         }
995                                         else
996                                         {
997                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
998                                         }
999                                 }
1000
1001                                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1002                                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
1003
1004                                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1005                         }
1006                         else
1007                         {
1008                                 if (rect.width > W_NORMAL || rect.height > W_NORMAL)
1009                                 {
1010                                         if (__screenMode == SCREEN_MODE_NORMAL)
1011                                         {
1012                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
1013                                         }
1014                                         else if (__screenMode == SCREEN_MODE_FULL)
1015                                         {
1016                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
1017                                         }
1018                                 }
1019                                 else
1020                                 {
1021                                         if (__screenMode == SCREEN_MODE_FIT)
1022                                         {
1023                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
1024                                         }
1025                                         else if (__screenMode == SCREEN_MODE_NORMAL)
1026                                         {
1027                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
1028                                         }
1029                                         else
1030                                         {
1031                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
1032                                         }
1033                                 }
1034
1035                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1036                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
1037
1038                                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1039                         }
1040
1041                         r = PowerManager::KeepScreenOnState(true, false);
1042                         TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
1043
1044                         delete pBitmapScreenMode;
1045                         pBitmapScreenMode = null;
1046                 }
1047                 break;
1048
1049         case IDA_BUTTON_PAUSE:
1050                 {
1051                         __setPauseState = true;
1052
1053                         r = __pVideoPlayerPresentationModel->PausePlay();
1054                         TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->PausePlay() failed:%s",
1055                                         GetErrorMessage(r));
1056
1057                         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1058                         {
1059                                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
1060                                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
1061
1062                                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1063                         }
1064                         else
1065                         {
1066                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
1067                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
1068
1069                                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1070                         }
1071
1072                         r = PowerManager::KeepScreenOnState(false);
1073                         TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
1074                 }
1075                 break;
1076
1077         case IDA_BUTTON_FULLSCREEN:
1078                 {
1079                         if (playState == PLAYER_STATE_PLAYING)
1080                         {
1081                                 __pUiControlTimer->Cancel();
1082                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1083                         }
1084                         else
1085                         {
1086                                 return;
1087                         }
1088
1089                         rect = __pVideoPlayerPresentationModel->GetVideoInfoN(
1090                                         __pVideoPlayerPresentationModel->GetMediaPathName());
1091
1092                         switch (__screenMode)
1093                         {
1094                         case SCREEN_MODE_FIT:
1095                                 {
1096                                         r = SetScreenMode(SCREEN_MODE_FULL, true);
1097                                         TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
1098
1099                                         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
1100                                         __pVideoPlayerPresentationModel->SetRenderingBuffer();
1101
1102                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
1103
1104                                         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1105                                         {
1106                                                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1107                                                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon failed:%s", GetErrorMessage(r));
1108
1109                                                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1110                                         }
1111                                         else
1112                                         {
1113                                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1114                                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon failed:%s", GetErrorMessage(r));
1115
1116                                                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1117                                         }
1118
1119                                         delete pBitmapScreenMode;
1120                                         pBitmapScreenMode = null;
1121                                 }
1122                                 break;
1123
1124                         case SCREEN_MODE_FULL:
1125                                 {
1126                                         if (rect.width > W_NORMAL || rect.height > W_NORMAL)
1127                                         {
1128                                                 r = SetScreenMode(SCREEN_MODE_NORMAL, true);
1129                                                 TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
1130
1131                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
1132                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
1133
1134                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
1135
1136                                                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1137                                                 {
1138                                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1139                                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon failed:%s",
1140                                                                         GetErrorMessage(r));
1141
1142                                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1143                                                 }
1144                                                 else
1145                                                 {
1146                                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1147                                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon failed:%s",
1148                                                                         GetErrorMessage(r));
1149
1150                                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1151                                                 }
1152                                         }
1153                                         else
1154                                         {
1155                                                 r = SetScreenMode(SCREEN_MODE_NORMAL, true);
1156                                                 TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
1157
1158                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
1159                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
1160
1161                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
1162
1163                                                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1164                                                 {
1165                                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1166                                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon failed:%s",
1167                                                                         GetErrorMessage(r));
1168
1169                                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1170                                                 }
1171                                                 else
1172                                                 {
1173                                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1174                                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon failed:%s",
1175                                                                         GetErrorMessage(r));
1176
1177                                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1178                                                 }
1179                                         }
1180
1181                                         delete pBitmapScreenMode;
1182                                         pBitmapScreenMode = null;
1183                                 }
1184                                 break;
1185
1186                         case SCREEN_MODE_NORMAL:
1187                                 {
1188                                         if (rect.width > W_NORMAL || rect.height > W_NORMAL)
1189                                         {
1190                                                 r = SetScreenMode(SCREEN_MODE_FULL, true);
1191                                                 TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
1192
1193                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
1194                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
1195
1196                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
1197
1198                                                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1199                                                 {
1200                                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1201                                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon failed:%s",
1202                                                                         GetErrorMessage(r));
1203
1204                                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1205                                                 }
1206                                                 else
1207                                                 {
1208                                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1209                                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon failed:%s",
1210                                                                         GetErrorMessage(r));
1211
1212                                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1213                                                 }
1214                                         }
1215                                         else
1216                                         {
1217                                                 r = SetScreenMode(SCREEN_MODE_FIT, true);
1218                                                 TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
1219
1220                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
1221                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
1222
1223                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
1224
1225                                                 if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1226                                                 {
1227                                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1228                                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon failed:%s",
1229                                                                         GetErrorMessage(r));
1230
1231                                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1232                                                 }
1233                                                 else
1234                                                 {
1235                                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
1236                                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon failed:%s",
1237                                                                         GetErrorMessage(r));
1238
1239                                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1240                                                 }
1241                                         }
1242
1243                                         delete pBitmapScreenMode;
1244                                         pBitmapScreenMode = null;
1245                                 }
1246                                 break;
1247
1248                         default:
1249                                 break;
1250                         }
1251                 }
1252                 break;
1253
1254         case IDA_BUTTON_SOUNDPATH:
1255                 {
1256                         if (__pSoundPathPopup == null)
1257                         {
1258                                 PlayerSoundPathPopupInit();
1259                         }
1260
1261                         if (playState == PLAYER_STATE_PLAYING)
1262                         {
1263                                 __pUiControlTimer->Cancel();
1264                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1265                         }
1266                         __pSoundPathPopup->ShowPopup(true);
1267                 }
1268                 break;
1269
1270         case IDA_BUTTON_FASTFORWARD:
1271                 {
1272                         if (__actionTouchLongPressed == true)
1273                         {
1274                                 __actionTouchLongPressed = false;
1275                                 break;
1276                         }
1277
1278                         if (playState == PLAYER_STATE_PLAYING)
1279                         {
1280                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1281                         }
1282
1283                         __pVideoPlayerPresentationModel->Forward();
1284                 }
1285                 break;
1286
1287         case IDA_BUTTON_FASTREWIND:
1288                 {
1289                         if (__actionTouchLongPressed == true)
1290                         {
1291                                 __actionTouchLongPressed = false;
1292                                 break;
1293                         }
1294
1295                         if (playState == PLAYER_STATE_PLAYING)
1296                         {
1297                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1298                         }
1299
1300                         __pVideoPlayerPresentationModel->Rewind();
1301                 }
1302                 break;
1303
1304         case IDA_BUTTON_BACK:
1305                 {
1306                         Application::GetInstance()->Terminate();
1307                 }
1308                 break;
1309
1310         default:
1311                 break;
1312         }
1313
1314 CATCH:
1315         delete pBitmapScreenMode;
1316         pBitmapScreenMode = null;
1317 }
1318
1319 void
1320 VideoPlayerForm::OnTouchPressed(const Control& source, const Point& currentPosition,
1321                 const TouchEventInfo& touchInfo)
1322 {
1323         AppLogDebug("OnTouchPressed");
1324         __pUiControlTimer->Cancel();
1325 }
1326
1327 void
1328 VideoPlayerForm::OnTouchReleased(const Control& source, const Point& currentPosition,
1329                 const TouchEventInfo& touchInfo)
1330 {
1331         result r = E_FAILURE;
1332
1333         PlayerState playState = PLAYER_STATE_ERROR;
1334
1335         AppLogDebug("OnTouchReleased");
1336
1337         ChangedControlPos();
1338
1339         if ((&source == __pFastForwardButton
1340                 || &source == __pFastRewindButton)
1341                 && __actionTouchLongPressed == true)
1342         {
1343                 __pVideoPlayerPresentationModel->StopFastForwardRewind();
1344         }
1345
1346         playState = __pVideoPlayerPresentationModel->GetState();
1347
1348         if (playState != PLAYER_STATE_PAUSED)
1349         {
1350                 if ((source.GetName() == L"IDL_MAIN_FORM" || source.GetHashCode() == __pOverlayPanel->GetHashCode())
1351                         && playState == PLAYER_STATE_PLAYING)
1352                 {
1353                         if (__isControlVisibleState == true)
1354                         {
1355                                 ShowControl(false);
1356                         }
1357                         else
1358                         {
1359                                 ShowControl(true);
1360
1361                                 r = __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1362                                 TryReturnVoid(r == E_SUCCESS, "__pUiControlTimer->Start() failed:%s", GetErrorMessage(r));
1363                         }
1364                 }
1365         }
1366 }
1367
1368 void
1369 VideoPlayerForm::OnTouchLongPressed(const Control& source, const Point& currentPosition,
1370                 const TouchEventInfo& touchInfo)
1371 {
1372         AppLogDebug("OnTouchLongPressed");
1373
1374         if (&source == __pFastForwardButton)
1375         {
1376                 __actionTouchLongPressed = true;
1377
1378                 if (__setPauseState == true)
1379                 {
1380                         __pVideoPlayerPresentationModel->FastForward(false);
1381                 }
1382                 else
1383                 {
1384                         __pVideoPlayerPresentationModel->FastForward(true);
1385                 }
1386         }
1387         else if (&source == __pFastRewindButton)
1388         {
1389                 __actionTouchLongPressed = true;
1390
1391                 if (__setPauseState == true)
1392                 {
1393                         __pVideoPlayerPresentationModel->FastRewind(false);
1394                 }
1395                 else
1396                 {
1397                         __pVideoPlayerPresentationModel->FastRewind(true);
1398                 }
1399         }
1400 }
1401
1402 void
1403 VideoPlayerForm::OnTouchMoved(const Control& source, const Point& currentPosition,
1404                 const TouchEventInfo& touchInfo)
1405 {
1406 }
1407
1408 void
1409 VideoPlayerForm::OnTouchFocusIn(const Control& source, const Point& currentPosition,
1410                 const TouchEventInfo& touchInfo)
1411 {
1412 }
1413
1414 void
1415 VideoPlayerForm::OnTouchFocusOut(const Control& source, const Point& currentPosition,
1416                 const TouchEventInfo& touchInfo)
1417 {
1418 }
1419
1420 void
1421 VideoPlayerForm::OnTimerExpired(Timer& timer)
1422 {
1423         if (timer.GetHashCode() == __pUiControlTimer->GetHashCode())
1424         {
1425                 if (__pVideoPlayerPresentationModel->GetState() == PLAYER_STATE_PLAYING)
1426                 {
1427                         ShowControl(false);
1428                 }
1429         }
1430 }
1431
1432 void
1433 VideoPlayerForm::OnAdjustmentValueChanged(const Control& source, int adjustment)
1434 {
1435         result r = E_FAILURE;
1436         long seekTime = 0;
1437
1438         AppLogDebug("OnAdjustmentValueChanged : %d", adjustment);
1439
1440         if (adjustment >= MIN_PROGRESS_RANGE && adjustment < MAX_PROGRESS_RANGE)
1441         {
1442                 seekTime = adjustment * (__pVideoPlayerPresentationModel->GetDuration() / MAX_PROGRESS_RANGE);
1443
1444                 r = __pVideoPlayerPresentationModel->SeekTo(seekTime);
1445                 TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->SeekTo() failed:%s", GetErrorMessage(r));
1446
1447                 UpdateProgressBar(adjustment);
1448         }
1449
1450         if (__pVideoPlayerPresentationModel->GetState() == PLAYER_STATE_PLAYING)
1451         {
1452                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1453         }
1454 }
1455
1456 void
1457 VideoPlayerForm::OnKeyPressed(const Control& source, KeyCode keyCode)
1458 {
1459         AppLogDebug("OnKeyPressed Control : %ls, KeyCode : %d", source.GetName().GetPointer(), keyCode);
1460
1461         if (keyCode == KEY_SIDE_UP || keyCode == KEY_SIDE_DOWN)
1462         {
1463                 // Empty statement
1464         }
1465 }
1466
1467 void
1468 VideoPlayerForm::OnKeyReleased(const Control& source, KeyCode keyCode)
1469 {
1470 }
1471
1472 void
1473 VideoPlayerForm::OnKeyLongPressed(const Control& source, KeyCode keyCode)
1474 {
1475 }
1476
1477 void
1478 VideoPlayerForm::UpdateProgressBar(const int currentPlayTime)
1479 {
1480         TryReturnVoid(__pSlider, "__pSlider is null");
1481
1482         __pSlider->SetValue(currentPlayTime);
1483         __pSlider->Invalidate(true);
1484 }
1485
1486 void
1487 VideoPlayerForm::InitTimer(void)
1488 {
1489         __pUiControlTimer = new (std::nothrow) Timer();
1490         __pUiControlTimer->Construct(*this);
1491 }
1492
1493 void
1494 VideoPlayerForm::DeleteTimer(void)
1495 {
1496         if (__pUiControlTimer != null)
1497         {
1498                 __pUiControlTimer->Cancel();
1499                 delete __pUiControlTimer;
1500                 __pUiControlTimer = null;
1501         }
1502 }
1503
1504 result
1505 VideoPlayerForm::SetPlayPauseButtonImage(PlayerState playState)
1506 {
1507         result r = E_SUCCESS;
1508
1509         Bitmap* pPlayBitmap = null;
1510         Bitmap* pPauseBitmap = null;
1511
1512         AppLogDebug("SetPlayPauseButtonImage : %d", playState);
1513
1514         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1515
1516         __pPlayPauseButton = static_cast<Button*>(GetControl("IDC_BUTTON_PLAY"));
1517         TryCatch(__pPlayPauseButton != null, r = E_SYSTEM, "__pPlayPauseButton is null");
1518
1519         if (playState == PLAYER_STATE_PLAYING)
1520         {
1521                 pPauseBitmap = pAppResource->GetBitmapN(L"T01_icon_toolbar_pause.png");
1522                 TryCatch(pPauseBitmap != null, r = E_SYSTEM, "pPauseBitmap is null");
1523
1524                 __pPlayPauseButton->SetNormalBackgroundBitmap(*pPauseBitmap);
1525
1526                 __pPlayPauseButton->SetActionId(IDA_BUTTON_PAUSE);
1527                 __pPlayPauseButton->Invalidate(true);
1528
1529                 delete pPauseBitmap;
1530         }
1531         else
1532         {
1533                 pPlayBitmap = pAppResource->GetBitmapN(L"T01_icon_toolbar_play.png");
1534                 TryCatch(pPlayBitmap != null, r = E_SYSTEM, "pPlayBitmap is null");
1535
1536                 __pPlayPauseButton->SetNormalBackgroundBitmap(*pPlayBitmap);
1537
1538                 __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
1539                 __pPlayPauseButton->Invalidate(true);
1540
1541                 delete pPlayBitmap;
1542         }
1543
1544         return r;
1545
1546 CATCH:
1547         return r;
1548 }
1549
1550 void
1551 VideoPlayerForm::GetTotalTime(String& totalTime)
1552 {
1553         result r = E_FAILURE;
1554         DateTime dateTime;
1555
1556         dateTime.AddSeconds(__pVideoPlayerPresentationModel->GetDuration() / MILLISECOND);
1557         r = totalTime.Format(20, L"%02d:%02d:%02d", dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1558         TryReturnVoid(r == E_SUCCESS, "totalTime.Format() failed:%s", GetErrorMessage(r));
1559 }
1560
1561 void
1562 VideoPlayerForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1563 {
1564         AppLogDebug("OnOrientationChanged");
1565
1566         SetScreenMode(__screenMode, false);
1567
1568         switch (orientationStatus)
1569         {
1570         case ORIENTATION_STATUS_PORTRAIT:
1571                 {
1572                         ChangedControlPos();
1573                 }
1574                 break;
1575
1576         case ORIENTATION_STATUS_LANDSCAPE:
1577                 // fall through
1578         case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
1579                 {
1580                         ChangedControlPos();
1581                 }
1582                 break;
1583
1584         default:
1585                 break;
1586         }
1587 }
1588
1589 void
1590 VideoPlayerForm::PlayerSoundPathPopupInit(void)
1591 {
1592         int tempAudioRouteMode = 0;
1593         int currentOutputDevice = 0;
1594         tempAudioRouteMode = __audioRouteMode;
1595         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1596
1597         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1598         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1599
1600         __pSoundPathPopup = new (std::nothrow) SoundPathPopup();
1601         result r = __pSoundPathPopup->Construct(currentOutputDevice,
1602                         __pAudioRouteManager->GetActiveBluetoothA2dpName(), tempAudioRouteMode);
1603         TryReturnVoid(r == E_SUCCESS, "__pSoundPathPopup->Construct() failed:%s", GetErrorMessage(r));
1604 }
1605
1606 void
1607 VideoPlayerForm::CreateMessageBox(const String& title, const String& message, MessageBoxStyle style,
1608                 unsigned long timeout)
1609 {
1610 }
1611
1612 void
1613 VideoPlayerForm::ShowControl(bool setShow)
1614 {
1615         AppLogDebug("ShowControl");
1616
1617         if (setShow == true)
1618         {
1619                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR|FORM_ACTION_BAR_HEADER, true);
1620
1621                 __pPlayPauseButton->SetShowState(true);
1622                 __pFastForwardButton->SetShowState(true);
1623                 __pFastRewindButton->SetShowState(true);
1624                 __pBackButton->SetShowState(true);
1625                 __pCurrenTimeLabel->SetShowState(true);
1626                 __pTotalTimeLabel->SetShowState(true);
1627                 __pSlider->SetShowState(true);
1628                 __pControlLabel->SetShowState(true);
1629                 __pFirstLineLabel->SetShowState(true);
1630                 __pVerticalLeftLine->SetShowState(true);
1631                 __pVerticalRightLine->SetShowState(true);
1632
1633                 __isControlVisibleState = true;
1634
1635                 Invalidate(true);
1636         }
1637         else
1638         {
1639                 SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR|FORM_ACTION_BAR_HEADER, false);
1640
1641                 __pPlayPauseButton->SetShowState(false);
1642                 __pFastForwardButton->SetShowState(false);
1643                 __pFastRewindButton->SetShowState(false);
1644                 __pBackButton->SetShowState(false);
1645                 __pCurrenTimeLabel->SetShowState(false);
1646                 __pTotalTimeLabel->SetShowState(false);
1647                 __pSlider->SetShowState(false);
1648                 __pControlLabel->SetShowState(false);
1649                 __pFirstLineLabel->SetShowState(false);
1650                 __pVerticalLeftLine->SetShowState(false);
1651                 __pVerticalRightLine->SetShowState(false);
1652
1653                 __isControlVisibleState = false;
1654         }
1655 }
1656
1657 void
1658 VideoPlayerForm::ChangedControlPos(void)
1659 {
1660         AppLogDebug("ChangedControlPos");
1661
1662         switch (GetOrientationStatus())
1663         {
1664         case ORIENTATION_STATUS_PORTRAIT:
1665                 {
1666                         if (GetClientAreaBounds().height <= W_WVGA_PORTRAIT_HEIGHT)
1667                         {
1668                                 __pControlLabel->SetBounds(X_WVGA_PORTRAIT_CONTROLLER, Y_WVGA_PORTRAIT_CONTROLLER, W_WVGA_PORTRAIT_CONTROLLER, H_WVGA_PORTRAIT_CONTROLLER);
1669                                 __pFirstLineLabel->SetBounds(X_WVGA_PORTRAIT_FIRST_LINE, Y_WVGA_PORTRAIT_FIRST_LINE, W_WVGA_PORTRAIT_FIRST_LINE, H_WVGA_PORTRAIT_FIRST_LINE);
1670
1671                                 __pCurrenTimeLabel->SetBounds(X_WVGA_PORTRAIT_CURRENT_TIME, Y_WVGA_PORTRAIT_CURRENT_TIME, W_WVGA_PORTRAIT_CURRENT_TIME, H_WVGA_PORTRAIT_CURRENT_TIME);
1672                                 __pSlider->SetBounds(X_WVGA_PORTRAIT_SLIDER, Y_WVGA_PORTRAIT_SLIDER, W_WVGA_PORTRAIT_SLIDER, H_WVGA_PORTRAIT_SLIDER);
1673                                 __pTotalTimeLabel->SetBounds(X_WVGA_PORTRAIT_TOTAL_TIME, Y_WVGA_PORTRAIT_TOTAL_TIME, W_WVGA_PORTRAIT_TOTAL_TIME, H_WVGA_PORTRAIT_TOTAL_TIME);
1674
1675                                 __pVerticalLeftLine->SetBounds(X_WVGA_PORTRAIT_VERTICAL_LEFT_LINE, Y_WVGA_PORTRAIT_VERTICAL_LEFT_LINE, W_WVGA_PORTRAIT_VERTICAL_LEFT_LINE,H_WVGA_PORTRAIT_VERTICAL_LEFT_LINE);
1676                                 __pFastRewindButton->SetBounds(X_WVGA_PORTRAIT_FASTREWIND_BTN, Y_WVGA_PORTRAIT_FASTREWIND_BTN, W_WVGA_PORTRAIT_FASTREWIND_BTN, H_WVGA_PORTRAIT_FASTREWIND_BTN);
1677                                 __pPlayPauseButton->SetBounds(X_WVGA_PORTRAIT_PLAYPAUSE_BTN, Y_WVGA_PORTRAIT_PLAYPAUSE_BTN, W_WVGA_PORTRAIT_PLAYPAUSE_BTN, H_WVGA_PORTRAIT_PLAYPAUSE_BTN);
1678                                 __pFastForwardButton->SetBounds(X_WVGA_PORTRAIT_FASTFORWARD_BTN, Y_WVGA_PORTRAIT_FASTFORWARD_BTN, W_WVGA_PORTRAIT_FASTFORWARD_BTN, H_WVGA_PORTRAIT_FASTFORWARD_BTN);
1679                                 __pVerticalRightLine->SetBounds(X_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE, Y_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE, W_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE, H_WVGA_PORTRAIT_VERTICAL_RIGHT_LINE);
1680                                 __pBackButton->SetBounds(X_WVGA_PORTRAIT_BACK_BTN, Y_WVGA_PORTRAIT_BACK_BTN, W_WVGA_PORTRAIT_BACK_BTN, H_WVGA_PORTRAIT_BACK_BTN);
1681                         }
1682                         else
1683                         {
1684                                 __pControlLabel->SetBounds(X_HVGA_PORTRAIT_CONTROLLER, Y_HVGA_PORTRAIT_CONTROLLER, W_HVGA_PORTRAIT_CONTROLLER, H_HVGA_PORTRAIT_CONTROLLER);
1685                                 __pFirstLineLabel->SetBounds(X_HVGA_PORTRAIT_FIRST_LINE, Y_HVGA_PORTRAIT_FIRST_LINE, W_HVGA_PORTRAIT_FIRST_LINE, H_HVGA_PORTRAIT_FIRST_LINE);
1686
1687                                 __pCurrenTimeLabel->SetBounds(X_HVGA_PORTRAIT_CURRENT_TIME, Y_HVGA_PORTRAIT_CURRENT_TIME, W_HVGA_PORTRAIT_CURRENT_TIME, H_HVGA_PORTRAIT_CURRENT_TIME);
1688                                 __pSlider->SetBounds(X_HVGA_PORTRAIT_SLIDER, Y_HVGA_PORTRAIT_SLIDER, W_HVGA_PORTRAIT_SLIDER, H_HVGA_PORTRAIT_SLIDER);
1689                                 __pTotalTimeLabel->SetBounds(X_HVGA_PORTRAIT_TOTAL_TIME, Y_HVGA_PORTRAIT_TOTAL_TIME, W_HVGA_PORTRAIT_TOTAL_TIME, H_HVGA_PORTRAIT_TOTAL_TIME);
1690
1691                                 __pVerticalLeftLine->SetBounds(X_HVGA_PORTRAIT_VERTICAL_LEFT_LINE, Y_HVGA_PORTRAIT_VERTICAL_LEFT_LINE, W_HVGA_PORTRAIT_VERTICAL_LEFT_LINE, H_HVGA_PORTRAIT_VERTICAL_LEFT_LINE);
1692                                 __pFastRewindButton->SetBounds(X_HVGA_PORTRAIT_FASTREWIND_BTN, Y_HVGA_PORTRAIT_FASTREWIND_BTN, W_HVGA_PORTRAIT_FASTREWIND_BTN, H_HVGA_PORTRAIT_FASTREWIND_BTN);
1693                                 __pPlayPauseButton->SetBounds(X_HVGA_PORTRAIT_PLAYPAUSE_BTN, Y_HVGA_PORTRAIT_PLAYPAUSE_BTN, W_HVGA_PORTRAIT_PLAYPAUSE_BTN, H_HVGA_PORTRAIT_PLAYPAUSE_BTN);
1694                                 __pFastForwardButton->SetBounds(X_HVGA_PORTRAIT_FASTFORWARD_BTN, Y_HVGA_PORTRAIT_FASTFORWARD_BTN, W_HVGA_PORTRAIT_FASTFORWARD_BTN, H_HVGA_PORTRAIT_FASTFORWARD_BTN);
1695                                 __pVerticalRightLine->SetBounds(X_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE, Y_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE, W_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE, H_HVGA_PORTRAIT_VERTICAL_RIGHT_LINE);
1696                                 __pBackButton->SetBounds(X_HVGA_PORTRAIT_BACK_BTN, Y_HVGA_PORTRAIT_BACK_BTN, W_HVGA_PORTRAIT_BACK_BTN, H_HVGA_PORTRAIT_BACK_BTN);
1697                         }
1698                 }
1699                 break;
1700
1701         case ORIENTATION_STATUS_LANDSCAPE:
1702                 // fall throuth
1703         case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
1704                 {
1705                         if (GetClientAreaBounds().width <= W_WVGA_LANDSCAPE_WIDTH)
1706                         {
1707                                 __pControlLabel->SetBounds(X_WVGA_LANDSCAPE_CONTROLLER, Y_WVGA_LANDSCAPE_CONTROLLER, W_WVGA_LANDSCAPE_CONTROLLER, H_WVGA_LANDSCAPE_CONTROLLER);
1708                                 __pFirstLineLabel->SetBounds(X_WVGA_LANDSCAPE_FIRST_LINE, Y_WVGA_LANDSCAPE_FIRST_LINE, W_WVGA_LANDSCAPE_FIRST_LINE, H_WVGA_LANDSCAPE_FIRST_LINE);
1709
1710                                 __pCurrenTimeLabel->SetBounds(X_WVGA_LANDSCAPE_CURRENT_TIME, Y_WVGA_LANDSCAPE_CURRENT_TIME, W_WVGA_LANDSCAPE_CURRENT_TIME, H_WVGA_LANDSCAPE_CURRENT_TIME);
1711                                 __pSlider->SetBounds(X_WVGA_LANDSCAPE_SLIDER, Y_WVGA_LANDSCAPE_SLIDER, W_WVGA_LANDSCAPE_SLIDER, H_WVGA_LANDSCAPE_SLIDER);
1712                                 __pTotalTimeLabel->SetBounds(X_WVGA_LANDSCAPE_TOTAL_TIME, Y_WVGA_LANDSCAPE_TOTAL_TIME, W_WVGA_LANDSCAPE_TOTAL_TIME, H_WVGA_LANDSCAPE_TOTAL_TIME);
1713
1714                                 __pVerticalLeftLine->SetBounds(X_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE, Y_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE, W_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE, H_WVGA_LANDSCAPE_VERTICAL_LEFT_LINE);
1715                                 __pFastRewindButton->SetBounds(X_WVGA_LANDSCAPE_FASTREWIND_BTN, Y_WVGA_LANDSCAPE_FASTREWIND_BTN, W_WVGA_LANDSCAPE_FASTREWIND_BTN, H_WVGA_LANDSCAPE_FASTREWIND_BTN);
1716                                 __pPlayPauseButton->SetBounds(X_WVGA_LANDSCAPE_PLAYPAUSE_BTN, Y_WVGA_LANDSCAPE_PLAYPAUSE_BTN, W_WVGA_LANDSCAPE_PLAYPAUSE_BTN, H_WVGA_LANDSCAPE_PLAYPAUSE_BTN);
1717                                 __pFastForwardButton->SetBounds(X_WVGA_LANDSCAPE_FASTFORWARD_BTN, Y_WVGA_LANDSCAPE_FASTFORWARD_BTN, W_WVGA_LANDSCAPE_FASTFORWARD_BTN, H_WVGA_LANDSCAPE_FASTFORWARD_BTN);
1718                                 __pVerticalRightLine->SetBounds(X_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, Y_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, W_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, H_WVGA_LANDSCAPE_VERTICAL_RIGHT_LINE);
1719                                 __pBackButton->SetBounds(X_WVGA_LANDSCAPE_BACK_BTN, Y_WVGA_LANDSCAPE_BACK_BTN, W_WVGA_LANDSCAPE_BACK_BTN, H_WVGA_LANDSCAPE_BACK_BTN);
1720                         }
1721                         else
1722                         {
1723                                 __pControlLabel->SetBounds(X_HVGA_LANDSCAPE_CONTROLLER, Y_HVGA_LANDSCAPE_CONTROLLER, W_HVGA_LANDSCAPE_CONTROLLER, H_HVGA_LANDSCAPE_CONTROLLER);
1724                                 __pFirstLineLabel->SetBounds(X_HVGA_LANDSCAPE_FIRST_LINE, Y_HVGA_LANDSCAPE_FIRST_LINE, W_HVGA_LANDSCAPE_FIRST_LINE, H_HVGA_LANDSCAPE_FIRST_LINE);
1725
1726                                 __pCurrenTimeLabel->SetBounds(X_HVGA_LANDSCAPE_CURRENT_TIME, Y_HVGA_LANDSCAPE_CURRENT_TIME, W_HVGA_LANDSCAPE_CURRENT_TIME, H_HVGA_LANDSCAPE_CURRENT_TIME);
1727                                 __pSlider->SetBounds(X_HVGA_LANDSCAPE_SLIDER, Y_HVGA_LANDSCAPE_SLIDER, W_HVGA_LANDSCAPE_SLIDER, H_HVGA_LANDSCAPE_SLIDER);
1728                                 __pTotalTimeLabel->SetBounds(X_HVGA_LANDSCAPE_TOTAL_TIME, Y_HVGA_LANDSCAPE_TOTAL_TIME, W_HVGA_LANDSCAPE_TOTAL_TIME, H_HVGA_LANDSCAPE_TOTAL_TIME);
1729
1730                                 __pVerticalLeftLine->SetBounds(X_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE, Y_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE, W_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE, H_HVGA_LANDSCAPE_VERTICAL_LEFT_LINE);
1731                                 __pFastRewindButton->SetBounds(X_HVGA_LANDSCAPE_FASTREWIND_BTN, Y_HVGA_LANDSCAPE_FASTREWIND_BTN, W_HVGA_LANDSCAPE_FASTREWIND_BTN, H_HVGA_LANDSCAPE_FASTREWIND_BTN);
1732                                 __pPlayPauseButton->SetBounds(X_HVGA_LANDSCAPE_PLAYPAUSE_BTN, Y_HVGA_LANDSCAPE_PLAYPAUSE_BTN, W_HVGA_LANDSCAPE_PLAYPAUSE_BTN, H_HVGA_LANDSCAPE_PLAYPAUSE_BTN);
1733                                 __pFastForwardButton->SetBounds(X_HVGA_LANDSCAPE_FASTFORWARD_BTN, Y_HVGA_LANDSCAPE_FASTFORWARD_BTN, W_HVGA_LANDSCAPE_FASTFORWARD_BTN, H_HVGA_LANDSCAPE_FASTFORWARD_BTN);
1734                                 __pVerticalRightLine->SetBounds(X_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, Y_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, W_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE, H_HVGA_LANDSCAPE_VERTICAL_RIGHT_LINE);
1735                                 __pBackButton->SetBounds(X_HVGA_LANDSCAPE_BACK_BTN, Y_HVGA_LANDSCAPE_BACK_BTN, W_HVGA_LANDSCAPE_BACK_BTN, H_HVGA_LANDSCAPE_BACK_BTN);
1736                         }
1737                 }
1738                 break;
1739
1740         default:
1741                 break;
1742         }
1743 }
1744
1745 void
1746 VideoPlayerForm::ShowControlByFrameActivated(void)
1747 {
1748         Bitmap* pPlayBitmap = null;
1749
1750         AppLogDebug("ShowControlByFrameActivated");
1751
1752         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1753
1754         SetActionBarsVisible(FORM_ACTION_BAR_INDICATOR|FORM_ACTION_BAR_HEADER, true);
1755
1756         pPlayBitmap = pAppResource->GetBitmapN(L"T01_icon_toolbar_play.png");
1757         __pPlayPauseButton->SetNormalBackgroundBitmap(*pPlayBitmap);
1758
1759         __pPlayPauseButton->SetShowState(true);
1760         __pFastRewindButton->SetShowState(true);
1761         __pFastForwardButton->SetShowState(true);
1762         __pBackButton->SetShowState(true);
1763         __pSlider->SetShowState(true);
1764         __pCurrenTimeLabel->SetShowState(true);
1765         __pTotalTimeLabel->SetShowState(true);
1766         __pControlLabel->SetShowState(true);
1767         __pFirstLineLabel->SetShowState(true);
1768         __pVerticalLeftLine->SetShowState(true);
1769         __pVerticalRightLine->SetShowState(true);
1770
1771         Invalidate(true);
1772
1773         CheckCallStatus();
1774         CheckLowBatteryStatus();
1775
1776         delete pPlayBitmap;
1777 }
1778
1779 void
1780 VideoPlayerForm::CancelTimerByFrameDeactivated(void)
1781 {
1782         result r = E_FAILURE;
1783
1784         AppLogDebug("CancelTimerByFrameDeactivated");
1785
1786         __pUiControlTimer->Cancel();
1787
1788         __setPauseState = true;
1789
1790         if (__audioRouteMode == AUDIO_ROUTE_SPEAKER_ONLY)
1791         {
1792                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
1793                 TryReturnVoid(r == E_SUCCESS, "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
1794
1795                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
1796         }
1797         else
1798         {
1799                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
1800                 TryReturnVoid(r == E_SUCCESS, "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
1801
1802                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
1803         }
1804 }
1805
1806 void
1807 VideoPlayerForm::OnPlayContentChanged(const String& fileName)
1808 {
1809         String totalTime;
1810
1811         AppLogDebug("OnPlayContentChanged");
1812
1813         GetTotalTime(totalTime);
1814
1815         __pHeader->SetTitleText(fileName);
1816         __pHeader->Invalidate(true);
1817
1818         __pTotalTimeLabel->SetText(totalTime);
1819         __pTotalTimeLabel->Invalidate(true);
1820 }
1821
1822 void
1823 VideoPlayerForm::OnPlayTimeChanged(int currentProgressPos, String& playTime)
1824 {
1825         AppLogDebug("OnPlayTimeChanged");
1826
1827         __pSlider->SetValue(currentProgressPos);
1828         __pSlider->Invalidate(true);
1829
1830         __pCurrenTimeLabel->SetText(playTime);
1831         __pCurrenTimeLabel->Invalidate(true);
1832 }
1833
1834 void
1835 VideoPlayerForm::OnPlayStateChanged(PlayerState playState)
1836 {
1837         AppLogDebug("OnPlayStateChanged");
1838
1839         SetPlayPauseButtonImage(playState);
1840
1841         if (playState == PLAYER_STATE_PLAYING)
1842         {
1843                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1844         }
1845         else
1846         {
1847                 __pUiControlTimer->Cancel();
1848                 ShowControl(true);
1849         }
1850 }
1851
1852 void
1853 VideoPlayerForm::CheckLowBatteryStatus(void)
1854 {
1855         int result = 0;
1856         MessageBox msgBox;
1857         bool isCharging = false;
1858         BatteryLevel batteryLevel;
1859
1860         AppLogDebug("CheckLowBatteryStatus");
1861
1862         Battery::GetCurrentLevel(batteryLevel);
1863         Battery::IsCharging(isCharging);
1864
1865         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY)
1866         {
1867                 if (isCharging == false)
1868                 {
1869                         msgBox.Construct(L"", L"Unable to video play.Low battery", MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_3_SEC);
1870                         msgBox.ShowAndWait(result);
1871
1872                         switch (result)
1873                         {
1874                         case MSGBOX_RESULT_CLOSE:
1875                                 {
1876                                         AppLogDebug("MSGBOX_RESULT_CLOSE");
1877                                         OnFormBackRequested(*this);
1878                                 }
1879                                 break;
1880
1881                         default:
1882                                 break;
1883                         }
1884                 }
1885         }
1886 }
1887
1888 void
1889 VideoPlayerForm::CheckCallStatus(void)
1890 {
1891         MessageBox msgBox;
1892         String dispString;
1893         int modalResult = 0;
1894         result r = E_FAILURE;
1895
1896         AppLogDebug("CheckCallStatus");
1897
1898         CallManager* pCallManager = new (std::nothrow) CallManager();
1899
1900         r = pCallManager->Construct();
1901         TryCatch(r == E_SUCCESS, , "pCallManager->Construct() failed : %s", GetErrorMessage(r));
1902
1903         if (pCallManager->GetCurrentCallStatus() != CALL_STATUS_IDLE
1904                 && pCallManager->GetCurrentCallStatus() != CALL_STATUS_UNDEFINED)
1905         {
1906                 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1907                 pAppResource->GetString(L"IDS_VPL_BODY_UNABLE_TO_PLAY_VIDEO_DURING_CALL", dispString);
1908
1909                 msgBox.Construct(L"", dispString, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_3_SEC);
1910                 msgBox.ShowAndWait(modalResult);
1911
1912                 switch (modalResult)
1913                 {
1914                 case MSGBOX_RESULT_CLOSE:
1915                         {
1916                                 AppLogDebug("MSGBOX_RESULT_CLOSE");
1917                                 OnFormBackRequested(*this);
1918                         }
1919                         break;
1920
1921                 default:
1922                         break;
1923                 }
1924         }
1925
1926 CATCH:
1927         delete pCallManager;
1928         pCallManager = null;
1929 }
1930
1931 void
1932 VideoPlayerForm::OnFormBackRequested(Form& source)
1933 {
1934         result r = E_FAILURE;
1935
1936         AppLogDebug("OnFormBackRequested");
1937
1938         UiApp* pApp = UiApp::GetInstance();
1939         TryReturnVoid(pApp != null, "pApp is null");
1940
1941         r = pApp->Terminate();
1942         TryReturnVoid(r == E_SUCCESS, "Failed Terminate [%s]", GetErrorMessage(r));
1943 }
1944
1945 void
1946 VideoPlayerForm::OnActiveAudioRouteChanged(const AudioRouteInfo& route)
1947 {
1948         Color BtnColor(0, 0, 0, 0);
1949         int currentOutputAudioDevice = 0;
1950         Bitmap* pBitmapScreenMode = null;
1951         Bitmap* pBitmapSoundPath = null;
1952         ArrayList* pArgs = null;
1953         result r = E_FAILURE;
1954
1955         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1956
1957         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1958
1959         AppLogDebug("OnActiveAudioRouteChanged");
1960
1961         switch (route.GetOutputAudioDevice())
1962         {
1963         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
1964                 {
1965                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
1966                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1967                         {
1968                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1969                         }
1970                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
1971                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1972                         {
1973                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
1974
1975                                 if (__pSoundPathPopup != null)
1976                                 {
1977                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1978                                         pArgs->Construct();
1979
1980                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
1981                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1982
1983                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
1984                                 }
1985                         }
1986                 }
1987                 break;
1988
1989         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
1990                 {
1991                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
1992                                 &&(__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1993                         {
1994                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1995
1996                                 if (__pSoundPathPopup != null)
1997                                 {
1998                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1999                                         pArgs->Construct();
2000
2001                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
2002
2003                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_WIRED_ACCESSORY_MENU,
2004                                                         pArgs);
2005                                 }
2006                         }
2007                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2008                                         &&(__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2009                         {
2010                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2011
2012                                 if (__pHeader->GetButtonStatus(BUTTON_POSITION_LEFT) == BUTTON_ITEM_STATUS_DISABLED)
2013                                 {
2014                                         if (__screenMode == SCREEN_MODE_FIT)
2015                                         {
2016                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
2017                                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2018                                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2019                                         }
2020                                         else if (__screenMode == SCREEN_MODE_NORMAL)
2021                                         {
2022                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
2023                                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2024                                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2025                                         }
2026                                         else
2027                                         {
2028                                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
2029                                                 r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2030                                                 TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2031                                         }
2032
2033                                         __pButtonLeftItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2034                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2035                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
2036                                 }
2037
2038                                 pBitmapSoundPath = pAppResource->GetBitmapN(L"T01_icon_title_soundpath.png");
2039                                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapSoundPath);
2040                                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2041
2042                                 __pButtonRightItem->SetActionId(IDA_BUTTON_SOUNDPATH);
2043                                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2044                                 __pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
2045
2046                                 if (__pSoundPathPopup != null)
2047                                 {
2048                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2049                                         currentOutputAudioDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
2050
2051                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2052                                         pArgs->Construct();
2053
2054                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2055                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputAudioDevice)));
2056
2057                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
2058                                 }
2059                         }
2060                 }
2061                 break;
2062
2063         case OUTPUT_AUDIO_DEVICE_SPEAKER:
2064                 {
2065                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
2066                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false))
2067                         {
2068                                 __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
2069
2070                                 if (__screenMode == SCREEN_MODE_FIT)
2071                                 {
2072                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2073                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2074
2075                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
2076                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2077                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2078
2079                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2080
2081                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2082                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2083                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2084                                 }
2085                                 else if (__screenMode == SCREEN_MODE_NORMAL)
2086                                 {
2087                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2088                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2089
2090                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
2091                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2092                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2093
2094                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2095
2096                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2097                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2098                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2099                                 }
2100                                 else
2101                                 {
2102                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2103                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2104
2105                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
2106                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2107                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2108
2109                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2110
2111                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2112                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2113                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2114                                 }
2115
2116                                 if (__pSoundPathPopup != null)
2117                                 {
2118                                         if (__pSoundPathPopup->GetShowState() == true)
2119                                         {
2120                                                 __pSoundPathPopup->SetShowState(false);
2121                                         }
2122                                 }
2123                         }
2124                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
2125                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false))
2126                         {
2127                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2128
2129                                 if (__screenMode == SCREEN_MODE_FIT)
2130                                 {
2131                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
2132                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2133                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2134                                 }
2135                                 else if (__screenMode == SCREEN_MODE_NORMAL)
2136                                 {
2137                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
2138                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2139                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2140                                 }
2141                                 else
2142                                 {
2143                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
2144                                         r = __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2145                                         TryCatch(r == E_SUCCESS, , "__pButtonLeftItem->SetIcon() Failed:%s", GetErrorMessage(r));
2146                                 }
2147
2148                                 __pButtonLeftItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2149                                 __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2150                                 __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, true);
2151
2152                                 pBitmapSoundPath = pAppResource->GetBitmapN(L"T01_icon_title_soundpath.png");
2153                                 r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapSoundPath);
2154                                 TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2155
2156                                 __pButtonRightItem->SetActionId(IDA_BUTTON_SOUNDPATH);
2157                                 __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2158                                 __pHeader->SetButtonEnabled(BUTTON_POSITION_RIGHT, true);
2159
2160                                 if (__pSoundPathPopup != null)
2161                                 {
2162                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2163                                         currentOutputAudioDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
2164
2165                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2166                                         pArgs->Construct();
2167
2168                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2169                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputAudioDevice)));
2170
2171                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
2172                                 }
2173                         }
2174                 }
2175                 break;
2176
2177         default:
2178                 break;
2179         }
2180
2181         delete pBitmapSoundPath;
2182         pBitmapSoundPath = null;
2183
2184 CATCH:
2185         delete pBitmapSoundPath;
2186         pBitmapSoundPath = null;
2187 }
2188
2189 void
2190 VideoPlayerForm::OnAudioRouteAdded(const AudioRouteInfo& route)
2191 {
2192         AppLogDebug("OnAudioRouteAdded");
2193
2194         switch (route.GetOutputAudioDevice())
2195         {
2196         case OUTPUT_AUDIO_DEVICE_NONE:
2197                 {
2198                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = true;
2199                 }
2200                 break;
2201
2202         case OUTPUT_AUDIO_DEVICE_SPEAKER:
2203                 {
2204                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = true;
2205                 }
2206                 break;
2207
2208         case OUTPUT_AUDIO_DEVICE_RECEIVER:
2209                 {
2210                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = true;
2211                 }
2212                 break;
2213
2214         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
2215                 {
2216                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = true;
2217                 }
2218                 break;
2219
2220         case OUTPUT_AUDIO_DEVICE_BT_SCO:
2221                 {
2222                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = true;
2223                 }
2224                 break;
2225
2226         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
2227                 {
2228                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] = true;
2229                 }
2230                 break;
2231
2232         default:
2233                 break;
2234         }
2235 }
2236
2237 void
2238 VideoPlayerForm::OnAudioRouteRemoved(const AudioRouteInfo& route)
2239 {
2240         result r = E_FAILURE;
2241         ArrayList* pArgs = null;
2242         Bitmap* pBitmapScreenMode = null;
2243         int currentOutputDevice = 0;
2244         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
2245
2246         AppLogDebug("OnAudioRouteRemoved");
2247
2248         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
2249
2250         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2251
2252         switch (route.GetOutputAudioDevice())
2253         {
2254         case OUTPUT_AUDIO_DEVICE_NONE:
2255                 {
2256                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = false;
2257                 }
2258                 break;
2259
2260         case OUTPUT_AUDIO_DEVICE_SPEAKER:
2261                 {
2262                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = false;
2263                 }
2264                 break;
2265
2266         case OUTPUT_AUDIO_DEVICE_RECEIVER:
2267                 {
2268                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = false;
2269                 }
2270                 break;
2271
2272         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
2273                 {
2274                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = false;
2275                 }
2276                 break;
2277
2278         case OUTPUT_AUDIO_DEVICE_BT_SCO:
2279                 {
2280                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = false;
2281                 }
2282                 break;
2283
2284         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
2285                 {
2286                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] = false;
2287                 }
2288                 break;
2289
2290         default:
2291                 break;
2292         }
2293
2294         if (currentAudioRoute.GetOutputAudioDevice() != route.GetOutputAudioDevice())
2295         {
2296                 if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_A2DP)
2297                 {
2298                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
2299                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2300                         {
2301                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2302
2303                                 if (__pSoundPathPopup != null)
2304                                 {
2305                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2306                                         pArgs->Construct();
2307
2308                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
2309                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2310
2311                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
2312                                 }
2313                         }
2314                 }
2315                 else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
2316                 {
2317                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2318                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2319                         {
2320                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2321                         }
2322                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2323                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
2324                         {
2325                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2326                         }
2327                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2328                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2329                         {
2330                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2331
2332                                 if (__pSoundPathPopup != null)
2333                                 {
2334                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2335                                         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
2336
2337                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2338                                         pArgs->Construct();
2339
2340                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2341                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputDevice)));
2342
2343                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
2344                                 }
2345                         }
2346                 }
2347                 else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
2348                 {
2349                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2350                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2351                         {
2352                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2353
2354                                 if (__pSoundPathPopup != null)
2355                                 {
2356                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2357                                         pArgs->Construct();
2358
2359                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
2360                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2361
2362                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
2363                                 }
2364                         }
2365                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2366                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true))
2367                         {
2368                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2369
2370                                 if (__pSoundPathPopup != null)
2371                                 {
2372                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2373                                         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
2374
2375                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
2376                                         pArgs->Construct();
2377
2378                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
2379                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputDevice)));
2380
2381                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
2382                                 }
2383                         }
2384                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2385                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2386                         {
2387                                 __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
2388
2389                                 if (__screenMode == SCREEN_MODE_FIT)
2390                                 {
2391                                         __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2392
2393                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode03.png");
2394                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2395                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2396
2397                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2398
2399                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2400                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2401                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2402                                 }
2403                                 else if (__screenMode == SCREEN_MODE_NORMAL)
2404                                 {
2405                                         __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2406
2407                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode01.png");
2408                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2409                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2410
2411                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2412
2413                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2414                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2415                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2416                                 }
2417                                 else
2418                                 {
2419                                         __pButtonLeftItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, null);
2420
2421                                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01_icon_title_screenmode02.png");
2422                                         r = __pButtonRightItem->SetIcon(BUTTON_ITEM_STATUS_NORMAL, pBitmapScreenMode);
2423                                         TryCatch(r == E_SUCCESS, , "__pButtonRightItem->SetIcon() Failed:%s", GetErrorMessage(r));
2424
2425                                         __pButtonRightItem->SetActionId(IDA_BUTTON_FULLSCREEN);
2426
2427                                         __pHeader->SetButton(BUTTON_POSITION_LEFT, *__pButtonLeftItem);
2428                                         __pHeader->SetButton(BUTTON_POSITION_RIGHT, *__pButtonRightItem);
2429                                         __pHeader->SetButtonEnabled(BUTTON_POSITION_LEFT, false);
2430                                 }
2431
2432                                 if (__pSoundPathPopup != null)
2433                                 {
2434                                         if (__pSoundPathPopup->GetShowState() == true)
2435                                         {
2436                                                 __pSoundPathPopup->SetShowState(false);
2437                                         }
2438                                 }
2439                         }
2440                 }
2441         }
2442
2443         delete pBitmapScreenMode;
2444         pBitmapScreenMode = null;
2445
2446 CATCH:
2447         delete pBitmapScreenMode;
2448         pBitmapScreenMode = null;
2449 }
2450
2451 void
2452 VideoPlayerForm::InitAudioRouteList(void)
2453 {
2454         AppLogDebug("InitAudioRouteList");
2455
2456         int listCount = 0;
2457         IList* availableAudioRouteList = null;
2458         AudioRouteInfo* tempRouteInfo = null;
2459         AudioRouteInfo availableRouteInfo(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
2460         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
2461
2462         availableAudioRouteList = __pAudioRouteManager->GetAvailableAudioRouteListN();
2463
2464         for (listCount = 0; listCount < availableAudioRouteList->GetCount(); ++listCount)
2465         {
2466                 tempRouteInfo = static_cast<AudioRouteInfo*>(availableAudioRouteList->GetAt(listCount));
2467                 availableRouteInfo = *tempRouteInfo;
2468
2469                 if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_NONE)
2470                 {
2471                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = true;
2472                 }
2473                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
2474                 {
2475                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = true;
2476                 }
2477                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_RECEIVER)
2478                 {
2479                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = true;
2480                 }
2481                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
2482                 {
2483                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = true;
2484                 }
2485                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_SCO)
2486                 {
2487                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = true;
2488                 }
2489                 else
2490                 {
2491                         __availableAudioRoute[OUTPUT_AUDIO_DEVICE_BT_A2DP] = true;
2492                 }
2493         }
2494
2495         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2496
2497         if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_A2DP)
2498         {
2499                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
2500                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2501                 {
2502                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2503                 }
2504                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
2505                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
2506                 {
2507                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2508                 }
2509                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
2510                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2511                 {
2512                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2513                 }
2514         }
2515         else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
2516         {
2517                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2518                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2519                 {
2520                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2521                 }
2522                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2523                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
2524                 {
2525                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2526                 }
2527                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2528                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2529                 {
2530                         __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2531                 }
2532         }
2533         else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
2534         {
2535                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2536                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2537                 {
2538                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2539                 }
2540                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2541                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true))
2542                 {
2543                         __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2544                 }
2545                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2546                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2547                 {
2548                         __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
2549                 }
2550         }
2551 }
2552
2553 result
2554 VideoPlayerForm::SetActiveAudioRoute(const AudioRouteInfo& route)
2555 {
2556         AppLogDebug("SetActiveAudioRoute");
2557         result r = __pAudioRouteManager->SetActiveAudioRoute(route);
2558
2559         return r;
2560 }
2561
2562 void
2563 VideoPlayerForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
2564 {
2565         BatteryLevel batteryLevel;
2566
2567         AppLogDebug("OnUserEventReceivedN");
2568
2569         switch (requestId)
2570         {
2571         case REQUEST_VIDEO_EVENT_BATTERY_LEVEL_CHANGED:
2572                 {
2573                         Battery::GetCurrentLevel(batteryLevel);
2574
2575                         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY)
2576                         {
2577                                 OnFormBackRequested(*this);
2578                         }
2579                 }
2580                 break;
2581
2582         default:
2583                 break;
2584         }
2585 }