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