eaf90456f286c9e13021e5fbb2f4c762782b04ce
[apps/osp/VideoPlayer.git] / src / VpVideoPlayerForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                VpVideoPlayerForm.cpp
19  * @brief               This is the implementation file for VideoPlayerForm class.
20  */
21
22 #include <FSystem.h>
23 #include <FTelephony.h>
24 #include "VpSoundPathPopup.h"
25 #include "VpVideoPlayerApp.h"
26 #include "VpVideoPlayerForm.h"
27 #include "VpVideoPlayerPresentationModel.h"
28 #include "VpTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::Base::Utility;
35 using namespace Tizen::Content;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::System;
39 using namespace Tizen::Telephony;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Ui::Scenes;
43
44 static const int MIN_PROGRESS_RANGE = 0;
45 static const int MAX_PROGRESS_RANGE = 100;
46
47 static const int SHOW_CONTROL_DURATION = 5000;
48
49 static const int MILLISECOND = 1000;
50 static const int START_TIME = 0;
51
52 static const int X_BASE = 0;
53 static const int Y_BASE = 0;
54 static const int DIVIDE_BY_TWO = 2;
55
56 static const int X_NORMAL = 0;
57 static const int Y_NORMAL = 310;
58 static const int W_NORMAL = 720;
59 static const int H_NORMAL = 432;
60
61 static const int COLOR_THUMB_RED = 0;
62 static const int COLOR_THUMB_GREEN = 0;
63 static const int COLOR_THUMB_BLUE = 0;
64 static const int COLOR_THUMB_ALPHA = 0;
65
66 static const int MULTI_CONTENT_COUNT = 2;
67
68 static const int MESSAGEBOX_DISPLAY_TIME_3_SEC = 3000;
69
70 static const wchar_t* INIT_TIME = L"00:00:00";
71
72 static const RequestId REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU = 111;
73 static const RequestId REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU = 112;
74 static const RequestId REQUEST_UPDATE_BLUETOOTHA2DP_AND_WIRED_ACCESSORY_MENU = 113;
75 static const RequestId REQUEST_VIDEO_EVENT_BATTERY_LEVEL_CHANGED = 114;
76
77 void DestroyPresentationModelInstance(void)
78 {
79         delete VideoPlayerPresentationModel::GetInstance();
80 }
81
82 VideoPlayerForm::VideoPlayerForm(void)
83         : __pOverlayPanel(null)
84         , __screenMode(SCREEN_MODE_NORMAL)
85         , __pSoundPathPopup(null)
86         , __pUiControlTimer(null)
87         , __pAudioRouteManager(null)
88         , __pHeader(null)
89         , __pFunctionPanel(null)
90         , __pControllerPanel(null)
91         , __pPlayPauseButton(null)
92         , __pFastForwardButton(null)
93         , __pFastRewindButton(null)
94         , __pBackButton(null)
95         , __pShareButton(null)
96         , __pScreenModeButton(null)
97         , __pRepeatModeButton(null)
98         , __pCurrenTimeLabel(null)
99         , __pTotalTimeLabel(null)
100         , __pSlider(null)
101         , __pContextMenuShare(null)
102         , __actionTouchLongPressed(false)
103         , __setPauseState(false)
104         , __isControlVisibleState(true)
105         , __audioRouteMode(0)
106         , __pVideoPlayerPresentationModel(null)
107 {
108         for (int count = 0; count < OUTPUT_AUDIO_ROUTE_MAX; ++count)
109         {
110                 __availableAudioRoute[count] = false;
111         }
112 }
113
114 VideoPlayerForm::~VideoPlayerForm(void)
115 {
116 }
117
118 void
119 VideoPlayerForm::Initialize(void)
120 {
121         AppLogDebug("Initialize");
122         Construct(L"IDL_MAIN_FORM");
123 }
124
125 result
126 VideoPlayerForm::SetScreenMode(const ScreenMode mode, bool destroyOverlay)
127 {
128         result r = E_SUCCESS;
129
130         Rectangle clientRect = GetClientAreaBounds();
131
132         switch (mode)
133         {
134         case SCREEN_MODE_NORMAL:
135                 {
136                         Rectangle rect = Rectangle(X_NORMAL, Y_NORMAL, W_NORMAL, H_NORMAL);
137
138                         if ((clientRect.width - rect.width) <= X_BASE)
139                         {
140                                 rect.x = X_BASE;
141                         }
142                         else
143                         {
144                                 rect.x = (clientRect.width - rect.width) / DIVIDE_BY_TWO;
145                         }
146
147                         if ((clientRect.height - rect.height) <= Y_BASE)
148                         {
149                                 rect.y = Y_BASE;
150                         }
151                         else
152                         {
153                                 rect.y = (clientRect.height - rect.height) / DIVIDE_BY_TWO;
154                         }
155
156                         if (destroyOverlay == true)
157                         {
158                                 if (__pOverlayPanel != null)
159                                 {
160                                         __pOverlayPanel->RemoveTouchEventListener(*this);
161                                         RemoveControl(*__pOverlayPanel);
162                                         __pOverlayPanel = null;
163                                 }
164
165                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
166                                 r = __pOverlayPanel->Construct(rect);
167                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
168
169                                 r = AddControl(*__pOverlayPanel);
170                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
171
172                                 __pOverlayPanel->AddTouchEventListener(*this);
173                         }
174                         else
175                         {
176                                 __pOverlayPanel->SetBounds(rect);
177                         }
178
179                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
180
181                         __screenMode = SCREEN_MODE_NORMAL;
182                 }
183                 break;
184
185         case SCREEN_MODE_FULL:
186                 {
187                         Rectangle rect = Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height);
188                         AppLogDebug("SetScreenMode [%d] [%d]", rect.height, rect.width);
189
190                         if (destroyOverlay == true)
191                         {
192                                 if (__pOverlayPanel != null)
193                                 {
194                                         __pOverlayPanel->RemoveTouchEventListener(*this);
195                                         RemoveControl(*__pOverlayPanel);
196                                         __pOverlayPanel = null;
197                                 }
198
199                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
200                                 r = __pOverlayPanel->Construct(rect);
201                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
202
203                                 r = AddControl(*__pOverlayPanel);
204                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
205
206                                 __pOverlayPanel->AddTouchEventListener(*this);
207                         }
208                         else
209                         {
210                                 __pOverlayPanel->SetBounds(rect);
211                         }
212                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
213
214                         __screenMode = SCREEN_MODE_FULL;
215                 }
216                 break;
217
218         case SCREEN_MODE_FIT:
219                 {
220                         Rectangle rect = __pVideoPlayerPresentationModel->GetVideoInfoN(
221                                         __pVideoPlayerPresentationModel->GetMediaPathName());
222
223                         if ((clientRect.width - rect.width) <= X_BASE)
224                         {
225                                 rect.x = X_BASE;
226                         }
227                         else
228                         {
229                                 rect.x = (clientRect.width - rect.width) / DIVIDE_BY_TWO;
230                         }
231
232                         if ((clientRect.height - rect.height) <= Y_BASE)
233                         {
234                                 rect.y = Y_BASE;
235                         }
236                         else
237                         {
238                                 rect.y = (clientRect.height - rect.height) / DIVIDE_BY_TWO;
239                         }
240
241                         if (destroyOverlay == true)
242                         {
243                                 if (__pOverlayPanel != null)
244                                 {
245                                         __pOverlayPanel->RemoveTouchEventListener(*this);
246                                         RemoveControl(*__pOverlayPanel);
247                                         __pOverlayPanel = null;
248                                 }
249
250                                 __pOverlayPanel = new (std::nothrow) OverlayPanel();
251                                 r = __pOverlayPanel->Construct(rect);
252                                 TryCatch(r == E_SUCCESS, , "__pOverlayPanel->Construct() failed:%s", GetErrorMessage(r));
253
254                                 r = AddControl(*__pOverlayPanel);
255                                 TryCatch(r == E_SUCCESS, , "AddControl(*__pOverlayPanel) failed:%s", GetErrorMessage(r));
256
257                                 __pOverlayPanel->AddTouchEventListener(*this);
258                         }
259                         else
260                         {
261                                 __pOverlayPanel->SetBounds(rect);
262                         }
263                         SetControlAlwaysAtBottom(*__pOverlayPanel, true);
264
265                         __screenMode = SCREEN_MODE_FIT;
266                 }
267                 break;
268
269         default:
270                 break;
271         }
272
273         return r;
274
275 CATCH:
276         RemoveControl(*__pOverlayPanel);
277         __pOverlayPanel = null;
278         __screenMode = SCREEN_MODE_NORMAL;
279
280         return r;
281 }
282
283 result
284 VideoPlayerForm::OnInitializing(void)
285 {
286         result r = E_FAILURE;
287
288         AppLogDebug("OnInitializing");
289
290         AddOrientationEventListener(*this);
291         AddKeyEventListener(*this);
292         AddTouchEventListener(*this);
293
294         __pAudioRouteManager = AudioRouteManager::GetInstance();
295         __pAudioRouteManager->SetAudioRouteEventListener(this);
296
297         r = SetScreenMode(SCREEN_MODE_NORMAL, true);
298         TryCatch(r == E_SUCCESS, , "SetScreenMode() failed:%s", GetErrorMessage(r));
299
300         __pVideoPlayerPresentationModel = VideoPlayerPresentationModel::GetInstance();
301         TryCatch(__pVideoPlayerPresentationModel != null, r = E_SYSTEM, "__pVideoPlayerPresentationModel is null");
302
303         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
304         __pVideoPlayerPresentationModel->InitializePlayer();
305
306         __pVideoPlayerPresentationModel->SetVideoPlayerEventListener(this);
307
308         InitTimer();
309         InitAudioRouteList();
310
311         r = InitializeHeader();
312         TryCatch(r == E_SUCCESS, , "InitializeHeader() failed : %s", GetErrorMessage(r));
313         r = InitializeFuncPanel();
314         TryCatch(r == E_SUCCESS, , "InitializeFuncPanel() failed : %s", GetErrorMessage(r));
315         r = InitializeController();
316         TryCatch(r == E_SUCCESS, , "InitializeController() failed : %s", GetErrorMessage(r));
317
318         return r;
319
320 CATCH:
321         DestroyPresentationModelInstance();
322
323         return r;
324 }
325
326 result
327 VideoPlayerForm::InitializeHeader(void)
328 {
329         result r = E_FAILURE;
330
331         AppLogDebug("InitializeHeader");
332
333         __pHeader = GetHeader();
334         TryCatch(__pHeader != null, r = E_SYSTEM, "__pHeader is null");
335
336         __pHeader->AddTouchEventListener(*this);
337
338         return E_SUCCESS;
339
340 CATCH:
341         return r;
342 }
343
344 result
345 VideoPlayerForm::InitializeFuncPanel(void)
346 {
347         result r = E_FAILURE;
348
349         AppLogDebug("InitializeFuncPanel");
350
351         __pFunctionPanel = static_cast<Panel*>(GetControl(IDC_PANEL_FUNCTION));
352         TryCatch(__pFunctionPanel != null, r = E_SYSTEM, "__pFunctionPanel is null");
353
354         __pScreenModeButton = static_cast<Button*>(__pFunctionPanel->GetControl(IDC_BUTTON_SCREENMODE));
355         TryCatch(__pScreenModeButton != null, r = E_SYSTEM, "__pScreenModeButton is null");
356         __pScreenModeButton->SetActionId(IDA_BUTTON_FULLSCREEN);
357         __pScreenModeButton->AddActionEventListener(*this);
358         __pScreenModeButton->AddTouchEventListener(*this);
359
360         __pShareButton = static_cast<Button*>(__pFunctionPanel->GetControl(IDC_BUTTON_SHARE));
361         TryCatch(__pShareButton != null, r = E_SYSTEM, "__pShareButton is null");
362         __pShareButton->SetActionId(IDA_BUTTON_SHARE);
363         __pShareButton->AddActionEventListener(*this);
364         __pShareButton->AddTouchEventListener(*this);
365
366         return E_SUCCESS;
367
368 CATCH:
369         return r;
370 }
371
372 result
373 VideoPlayerForm::InitializeController(void)
374 {
375         result r = E_FAILURE;
376
377         Bitmap* pSliderThumbNormalBitmap = null;
378         Bitmap* pSliderThumbPressedBitmap = null;
379         Bitmap* pSliderThumbDisableBitmap = null;
380
381         AppLogDebug("InitializeController");
382
383         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
384
385         __pControllerPanel = static_cast<Panel*>(GetControl(IDC_PANEL_CONTROLLER));
386         TryCatch(__pControllerPanel != null, r = E_SYSTEM, "__pControllerPanel is null");
387
388         __pRepeatModeButton = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_REPEATMODE));
389         TryCatch(__pRepeatModeButton != null, r = E_SYSTEM, "__pRepeatModeButton is null");
390         __pRepeatModeButton->SetActionId(IDA_BUTTON_REPEATMODE);
391         __pRepeatModeButton->AddActionEventListener(*this);
392         __pRepeatModeButton->AddTouchEventListener(*this);
393
394         __pPlayPauseButton = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_PLAY));
395         TryCatch(__pPlayPauseButton != null, r = E_SYSTEM, "__pPlayPauseButton is null");
396         __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
397         __pPlayPauseButton->AddActionEventListener(*this);
398         __pPlayPauseButton->AddTouchEventListener(*this);
399
400         __pFastRewindButton  = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_FASTREWIND));
401         TryCatch(__pFastRewindButton != null, r = E_SYSTEM, "__pFastRewindButton is null");
402         __pFastRewindButton ->SetActionId(IDA_BUTTON_FASTREWIND);
403         __pFastRewindButton ->AddActionEventListener(*this);
404         __pFastRewindButton->AddTouchEventListener(*this);
405
406         __pFastForwardButton = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_FASTFORWARD));
407         TryCatch(__pFastForwardButton != null, r = E_SYSTEM, "__pFastForwardButton is null");
408         __pFastForwardButton->SetActionId(IDA_BUTTON_FASTFORWARD);
409         __pFastForwardButton->AddActionEventListener(*this);
410         __pFastForwardButton->AddTouchEventListener(*this);
411
412         __pBackButton = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_BACK));
413         TryCatch(__pBackButton != null, r = E_SYSTEM, "__pBackButton is null");
414         __pBackButton->SetActionId(IDA_BUTTON_BACK);
415         __pBackButton->AddActionEventListener(*this);
416         __pBackButton->AddTouchEventListener(*this);
417
418         __pCurrenTimeLabel = static_cast<Label*>(__pControllerPanel->GetControl(IDC_LABEL_CURRENTTIME));
419         TryCatch(__pCurrenTimeLabel != null, r = E_SYSTEM, "__pCurrenTimeLabel is null");
420         __pCurrenTimeLabel->AddTouchEventListener(*this);
421
422         __pTotalTimeLabel = static_cast<Label*>(__pControllerPanel->GetControl(IDC_LABEL_FULLTIME));
423         TryCatch(__pTotalTimeLabel != null, r = E_SYSTEM, "__pTotalTimeLabel is null");
424         __pTotalTimeLabel->AddTouchEventListener(*this);
425
426         __pSlider = static_cast<Slider*>(__pControllerPanel->GetControl(IDC_SLIDER));
427         TryCatch(__pSlider != null, r = E_SYSTEM, "__pSlider is null");
428         __pSlider->SetEnabled(true);
429         __pSlider->SetRange(MIN_PROGRESS_RANGE, MAX_PROGRESS_RANGE);
430         __pSlider->SetValue(MIN_PROGRESS_RANGE);
431         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_NORMAL,
432                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
433         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_PRESSED,
434                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
435         __pSlider->SetThumbTextColor(SLIDER_THUMB_STATUS_DISABLED,
436                         Color(COLOR_THUMB_RED, COLOR_THUMB_GREEN, COLOR_THUMB_BLUE, COLOR_THUMB_ALPHA));
437
438         pSliderThumbNormalBitmap = pAppResource->GetBitmapN(L"T01_2_control_progress_handle.png");
439         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_NORMAL, *pSliderThumbNormalBitmap);
440         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
441
442         pSliderThumbPressedBitmap = pAppResource->GetBitmapN(L"T01_2_control_progress_handle_press.png");
443         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_PRESSED, *pSliderThumbPressedBitmap);
444         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
445
446         pSliderThumbDisableBitmap = pAppResource->GetBitmapN(L"T01_2_control_progress_handle.png");
447         r = __pSlider->SetThumbBitmap(SLIDER_THUMB_STATUS_DISABLED, *pSliderThumbDisableBitmap);
448         TryCatch(r == E_SUCCESS, , "__pSlider->SetThumbBitmap() Failed:%s", GetErrorMessage(r));
449
450         __pSlider->AddAdjustmentEventListener(*this);
451         __pSlider->AddTouchEventListener(*this);
452
453 CATCH:
454         delete pSliderThumbNormalBitmap;
455         delete pSliderThumbPressedBitmap;
456         delete pSliderThumbDisableBitmap;
457
458         return r;
459 }
460
461 result
462 VideoPlayerForm::OnTerminating(void)
463 {
464         AppLogDebug("OnTerminating");
465         DeleteTimer();
466         DestroyPresentationModelInstance();
467
468         RemoveControl(*__pOverlayPanel);
469         __pOverlayPanel = null;
470
471         delete __pSoundPathPopup;
472         __pSoundPathPopup = null;
473
474         delete __pContextMenuShare;
475         __pContextMenuShare = null;
476
477         return E_SUCCESS;
478 }
479
480 void
481 VideoPlayerForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
482 {
483         result r = E_FAILURE;
484         AppLogDebug("OnSceneActivatedN");
485
486         String totalTime;
487
488         CheckCallStatus();
489         CheckLowBatteryStatus();
490
491         r = __pVideoPlayerPresentationModel->StartPlay();
492         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->StartPlay() failed:%s", GetErrorMessage(r));
493
494         GetTotalTime(totalTime);
495         AppLogDebug("totalTime [%ls]", totalTime.GetPointer());
496
497         __pTotalTimeLabel->SetText(totalTime);
498         __pTotalTimeLabel->Invalidate(true);
499
500         SetScreenModeButtonImage();
501
502         r = PowerManager::KeepScreenOnState(true, false);
503         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
504 }
505
506 void
507 VideoPlayerForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
508 {
509         result r = E_FAILURE;
510
511         AppLogDebug("OnSceneDeactivated");
512
513         r = __pVideoPlayerPresentationModel->PausePlay();
514         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->PausePlay() failed:%s", GetErrorMessage(r));
515
516         r = PowerManager::KeepScreenOnState(false);
517         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
518 }
519
520 void
521 VideoPlayerForm::OnPlayOpened(result r)
522 {
523         AppLogDebug("OnPlayOpened");
524 }
525
526 void
527 VideoPlayerForm::OnPlayEndOfClip(bool playNextContent, int repeatMode, int mediaCount)
528 {
529         result r = E_FAILURE;
530         Rectangle rect;
531         Point point(X_BASE, Y_BASE);
532         Bitmap* pPlayBitmap = null;
533
534         AppLogDebug("OnPlayEndOfClip : %d", playNextContent);
535
536         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
537
538         if (__pSoundPathPopup != null)
539         {
540                 if (__pSoundPathPopup->GetShowState() == true)
541                 {
542                         __pSoundPathPopup->SetShowState(false);
543                 }
544         }
545
546         __pUiControlTimer->Cancel();
547         ShowControl(true);
548         UpdateProgressBar(START_TIME);
549
550         __pCurrenTimeLabel->SetText(INIT_TIME);
551         __pCurrenTimeLabel->Invalidate(true);
552
553         pPlayBitmap = pAppResource->GetBitmapN(L"T01-2_control_circle_icon_play.png");
554         TryCatch(pPlayBitmap != null, r = E_SYSTEM, "pPlayBitmap is null");
555
556         __pPlayPauseButton->SetNormalBitmap(point ,*pPlayBitmap);
557         __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
558         Invalidate(true);
559
560         __pSlider->SetEnabled(false);
561
562         if (__pScreenModeButton->GetShowState() == true)
563         {
564                 __pScreenModeButton->SetShowState(false);
565         }
566
567         switch (repeatMode)
568         {
569         case REPEAT_TYPE_OFF:
570                 {
571                         if (mediaCount < MULTI_CONTENT_COUNT)
572                         {
573                                 r = PowerManager::KeepScreenOnState(false);
574                                 TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
575                         }
576                         else
577                         {
578                                 if (playNextContent == true)
579                                 {
580                                         SetScreenMode(SCREEN_MODE_NORMAL, true);
581                                         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
582
583                                         r = __pVideoPlayerPresentationModel->StartPlay();
584                                         TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() Failed:%s", GetErrorMessage(r));
585
586                                         SetScreenModeButtonImage();
587
588                                         __pSlider->SetEnabled(true);
589
590                                         if (__pScreenModeButton->GetShowState() == false)
591                                         {
592                                                 __pScreenModeButton->SetShowState(true);
593                                         }
594                                 }
595
596                                 r = PowerManager::KeepScreenOnState(true, false);
597                                 TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
598                         }
599                 }
600                 break;
601
602         case REPEAT_TYPE_ONE:
603                 {
604                         r = __pVideoPlayerPresentationModel->StartPlay();
605                         TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() Failed:%s", GetErrorMessage(r));
606
607                         __pSlider->SetEnabled(true);
608
609                         SetScreenModeButtonImage();
610                         if (__pScreenModeButton->GetShowState() == false)
611                         {
612                                 __pScreenModeButton->SetShowState(true);
613                         }
614
615                         r = PowerManager::KeepScreenOnState(true, false);
616                         TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
617                 }
618                 break;
619
620         case REPEAT_TYPE_ALL:
621                 {
622                         if (mediaCount < MULTI_CONTENT_COUNT)
623                         {
624                                 r = __pVideoPlayerPresentationModel->StartPlay();
625                                 TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() Failed:%s", GetErrorMessage(r));
626                         }
627                         else
628                         {
629                                 SetScreenMode(SCREEN_MODE_NORMAL, true);
630                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
631
632                                 r = __pVideoPlayerPresentationModel->StartPlay();
633                                 TryCatch(r == E_SUCCESS, , "__pVideoPlayerPresentationModel->StartPlay() Failed:%s", GetErrorMessage(r));
634                         }
635
636                         __pSlider->SetEnabled(true);
637
638                         SetScreenModeButtonImage();
639                         if (__pScreenModeButton->GetShowState() == false)
640                         {
641                                 __pScreenModeButton->SetShowState(true);
642                         }
643
644                         r = PowerManager::KeepScreenOnState(true, false);
645                         TryCatch(r == E_SUCCESS, , "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
646                 }
647                 break;
648
649         default:
650                 break;
651         }
652
653 CATCH:
654         delete pPlayBitmap;
655 }
656
657 void
658 VideoPlayerForm::OnPlayBuffering(int percent)
659 {
660         AppLogDebug("OnPlayBuffering");
661 }
662
663 void
664 VideoPlayerForm::OnPlayErrorOccurred(PlayerErrorReason r)
665 {
666         MessageBox messageBox;
667         String messageBoxString;
668         int modalResult = 0;
669         AppResource* pAppResource = null;
670
671         AppLogDebug("OnPlayErrorOccurred [%d]", r);
672
673         switch (r)
674         {
675         case PLAYER_ERROR_INVALID_DATA:
676                 {
677                         if ((__pVideoPlayerPresentationModel->GetMediaPathName().EndsWith(L"flv") == true)
678                                 || (__pVideoPlayerPresentationModel->GetMediaPathName().EndsWith(L"FLV") == true))
679                         {
680                                 pAppResource = Application::GetInstance()->GetAppResource();
681                                 pAppResource->GetString(IDS_COM_POP_UNSUPPORTED_FILE_TYPE, messageBoxString);
682
683                                 messageBox.Construct(L"", messageBoxString, MSGBOX_STYLE_OK, MESSAGEBOX_DISPLAY_TIME_3_SEC);
684                                 messageBox.ShowAndWait(modalResult);
685
686                                 AppLogDebug("OnPlayErrorOccurred : pApp->Terminate");
687                                 UiApp* pApp = UiApp::GetInstance();
688                                 pApp->Terminate();
689                         }
690                 }
691                 break;
692
693         case PLAYER_ERROR_DEVICE_FAILED:
694                 {
695                         pAppResource = Application::GetInstance()->GetAppResource();
696                         pAppResource->GetString(IDS_VPL_POP_UNABLE_TO_PLAY_VIDEO_ERROR_OCCURRED, messageBoxString);
697
698                         messageBox.Construct(L"", messageBoxString, MSGBOX_STYLE_OK, MESSAGEBOX_DISPLAY_TIME_3_SEC);
699                         messageBox.ShowAndWait(modalResult);
700
701                         AppLogDebug("OnPlayErrorOccurred : pApp->Terminate");
702                         UiApp* pApp = UiApp::GetInstance();
703                         pApp->Terminate();
704                 }
705                 break;
706
707         default:
708                 break;
709         }
710 }
711
712 void
713 VideoPlayerForm::OnPlayInterrupted(void)
714 {
715         AppLogDebug("OnPlayInterrupted");
716 }
717
718 void
719 VideoPlayerForm::OnPlayReleased(void)
720 {
721         AppLogDebug("OnPlayReleased");
722 }
723
724 void
725 VideoPlayerForm::OnActionPerformed(const Control& source, int actionId)
726 {
727         result r = E_FAILURE;
728
729         String currentTime;
730         String totalTime;
731         Rectangle rect;
732         Point point(X_BASE, Y_BASE);
733
734         PlayerState playState = PLAYER_STATE_ERROR;
735         AppLogDebug("OnActionPerformed : %d", actionId);
736
737         playState = __pVideoPlayerPresentationModel->GetState();
738
739         Rectangle clientRect = GetClientAreaBounds();
740
741         switch (actionId)
742         {
743         case IDA_BUTTON_PLAY:
744                 {
745                         __setPauseState = false;
746
747                         if (playState == PLAYER_STATE_ENDOFCLIP)
748                         {
749                                 if (__pVideoPlayerPresentationModel->GetMediaCount() >= MULTI_CONTENT_COUNT)
750                                 {
751                                         int repeatMode = __pVideoPlayerPresentationModel->GetRepeatMode();
752
753                                         if (repeatMode == REPEAT_TYPE_OFF || repeatMode == REPEAT_TYPE_ALL)
754                                         {
755                                                 SetScreenMode(SCREEN_MODE_NORMAL, true);
756                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
757                                         }
758                                 }
759                         }
760
761                         r = __pVideoPlayerPresentationModel->StartPlay();
762                         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->StartPlay() failed:%s", GetErrorMessage(r));
763
764                         __pSlider->SetEnabled(true);
765
766                         SetScreenModeButtonImage();
767
768                         if (__pScreenModeButton->GetShowState() == false)
769                         {
770                                 __pScreenModeButton->SetShowState(true);
771                         }
772
773                         r = PowerManager::KeepScreenOnState(true, false);
774                         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
775                 }
776                 break;
777
778         case IDA_BUTTON_PAUSE:
779                 {
780                         __setPauseState = true;
781
782                         r = __pVideoPlayerPresentationModel->PausePlay();
783                         TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->PausePlay() failed:%s", GetErrorMessage(r));
784
785                         if (__pScreenModeButton->GetShowState() == true)
786                         {
787                                 __pScreenModeButton->SetShowState(false);
788                         }
789
790                         r = PowerManager::KeepScreenOnState(false);
791                         TryReturnVoid(r == E_SUCCESS, "PowerManager::KeepScreenOnState() failed:%s", GetErrorMessage(r));
792                 }
793                 break;
794
795         case IDA_BUTTON_FULLSCREEN:
796                 {
797                         if (playState == PLAYER_STATE_PLAYING)
798                         {
799                                 __pUiControlTimer->Cancel();
800                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
801                         }
802                         else
803                         {
804                                 return;
805                         }
806
807                         rect = __pVideoPlayerPresentationModel->GetVideoInfoN(
808                                         __pVideoPlayerPresentationModel->GetMediaPathName());
809
810                         switch (__screenMode)
811                         {
812                         case SCREEN_MODE_FIT:
813                                 {
814                                         r = SetScreenMode(SCREEN_MODE_FULL, true);
815                                         TryReturnVoid(r == E_SUCCESS, "SetScreenMode() failed:%s", GetErrorMessage(r));
816
817                                         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
818                                         __pVideoPlayerPresentationModel->SetRenderingBuffer();
819
820                                         SetScreenModeButtonImage();
821                                 }
822                                 break;
823
824                         case SCREEN_MODE_FULL:
825                                 {
826                                         r = SetScreenMode(SCREEN_MODE_NORMAL, true);
827                                         TryReturnVoid(r == E_SUCCESS, "SetScreenMode() failed:%s", GetErrorMessage(r));
828
829                                         __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
830                                         __pVideoPlayerPresentationModel->SetRenderingBuffer();
831
832                                         SetScreenModeButtonImage();
833                                 }
834                                 break;
835
836                         case SCREEN_MODE_NORMAL:
837                                 {
838                                         if (rect.width > W_NORMAL || rect.height > W_NORMAL)
839                                         {
840                                                 r = SetScreenMode(SCREEN_MODE_FULL, true);
841                                                 TryReturnVoid(r == E_SUCCESS, "SetScreenMode() failed:%s", GetErrorMessage(r));
842
843                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
844                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
845                                         }
846                                         else
847                                         {
848                                                 r = SetScreenMode(SCREEN_MODE_FIT, true);
849                                                 TryReturnVoid(r == E_SUCCESS, "SetScreenMode() failed:%s", GetErrorMessage(r));
850
851                                                 __pVideoPlayerPresentationModel->SetOverlayPanel(__pOverlayPanel);
852                                                 __pVideoPlayerPresentationModel->SetRenderingBuffer();
853                                         }
854                                         SetScreenModeButtonImage();
855                                 }
856                                 break;
857
858                         default:
859                                 break;
860                         }
861                 }
862                 break;
863
864         case IDA_BUTTON_SOUNDPATH:
865                 {
866                         if (__pSoundPathPopup == null)
867                         {
868                                 PlayerSoundPathPopupInit();
869                         }
870
871                         if (playState == PLAYER_STATE_PLAYING)
872                         {
873                                 __pUiControlTimer->Cancel();
874                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
875                         }
876                         __pSoundPathPopup->ShowPopup(true);
877                 }
878                 break;
879
880         case IDA_BUTTON_FASTFORWARD:
881                 {
882                         if (__actionTouchLongPressed == true)
883                         {
884                                 __actionTouchLongPressed = false;
885                                 break;
886                         }
887
888                         if (playState == PLAYER_STATE_PLAYING)
889                         {
890                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
891                         }
892
893                         __pVideoPlayerPresentationModel->Forward();
894                 }
895                 break;
896
897         case IDA_BUTTON_FASTREWIND:
898                 {
899                         if (__actionTouchLongPressed == true)
900                         {
901                                 __actionTouchLongPressed = false;
902                                 break;
903                         }
904
905                         if (playState == PLAYER_STATE_PLAYING)
906                         {
907                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
908                         }
909
910                         __pVideoPlayerPresentationModel->Rewind();
911                 }
912                 break;
913
914         case IDA_BUTTON_SHARE:
915                 {
916                         Point point((((GetClientAreaBounds().width - __pFunctionPanel->GetBounds().width) / DIVIDE_BY_TWO)
917                                         + (__pShareButton->GetBounds().width / DIVIDE_BY_TWO)),
918                                         __pFunctionPanel->GetBounds().y + __pFunctionPanel->GetBounds().height);
919
920                         if (__pContextMenuShare != null)
921                         {
922                                 delete __pContextMenuShare;
923                                 __pContextMenuShare = null;
924                         }
925
926                         __pContextMenuShare = new (std::nothrow) ContextMenu();
927                         r = __pContextMenuShare->Construct(point, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD);
928                         TryReturnVoid(r == E_SUCCESS, "__pContextMenuShare->Construct() failed:%s", GetErrorMessage(r));
929
930                         String str;
931                         Application::GetInstance()->GetAppResource()->GetString(L"IDS_COM_BODY_MESSAGE", str);
932                         __pContextMenuShare->AddItem(str, IDA_CONTEXTMENU_MESSAGE);
933                         Application::GetInstance()->GetAppResource()->GetString(L"IDS_COM_BODY_EMAIL", str);
934                         __pContextMenuShare->AddItem(str, IDA_CONTEXTMENU_EMAIL);
935                         __pContextMenuShare->AddActionEventListener(*this);
936                         __pContextMenuShare->SetShowState(true);
937                         __pContextMenuShare->Show();
938
939                         if (playState == PLAYER_STATE_PLAYING)
940                         {
941                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
942                         }
943                 }
944                 break;
945
946         case IDA_CONTEXTMENU_MESSAGE:
947                 {
948                         AppControl* pAppControl = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_MESSAGE, APPCONTROL_OPERATION_ID_COMPOSE);
949                         if (pAppControl == null)
950                         {
951                                 return;
952                         }
953
954                         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
955                         pDataList->Construct();
956
957                         String mediaPathName = __pVideoPlayerPresentationModel->GetMediaPathName();
958                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
959                                                 new (std::nothrow) String(mediaPathName));
960                         AppLogDebug("AppControl Data : %ls", mediaPathName.GetPointer());
961
962                         pAppControl->Start(null, null, pDataList, this);
963
964                         if (pAppControl != null)
965                         {
966                                 delete pAppControl;
967                         }
968                 }
969                 break;
970
971         case IDA_CONTEXTMENU_EMAIL:
972                 {
973                         AppControl* pAppControl = AppManager::FindAppControlN(APPCONTROL_PROVIDER_ID_EMAIL, APPCONTROL_OPERATION_ID_COMPOSE);
974                         if (pAppControl == null)
975                         {
976                                 return;
977                         }
978
979                         HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
980                         pDataList->Construct();
981
982                         String mediaPathName = __pVideoPlayerPresentationModel->GetMediaPathName();
983                         pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_ATTACHMENTS),
984                                                 new (std::nothrow) String(mediaPathName));
985                         AppLogDebug("AppControl Data : %ls", mediaPathName.GetPointer());
986
987                         pAppControl->Start(null, null, pDataList, this);
988
989                         if (pAppControl != null)
990                         {
991                                 delete pAppControl;
992                         }
993                 }
994                 break;
995
996         case IDA_BUTTON_REPEATMODE:
997                 {
998                         int repeatMode = __pVideoPlayerPresentationModel->GetRepeatMode();
999
1000                         switch (repeatMode)
1001                         {
1002                         case REPEAT_TYPE_OFF:
1003                                 {
1004                                         SetRepeatButtonImage(REPEAT_TYPE_ONE);
1005                                 }
1006                                 break;
1007
1008                         case REPEAT_TYPE_ONE:
1009                                 {
1010                                         if (__pVideoPlayerPresentationModel->GetMediaCount() > 1)
1011                                         {
1012                                                 SetRepeatButtonImage(REPEAT_TYPE_ALL);
1013                                         }
1014                                         else
1015                                         {
1016                                                 SetRepeatButtonImage(REPEAT_TYPE_OFF);
1017                                         }
1018                                 }
1019                                 break;
1020
1021                         case REPEAT_TYPE_ALL:
1022                                 {
1023                                         SetRepeatButtonImage(REPEAT_TYPE_OFF);
1024                                 }
1025                                 break;
1026
1027                         default:
1028                                 break;
1029                         }
1030
1031                         if (playState == PLAYER_STATE_PLAYING)
1032                         {
1033                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1034                         }
1035                 }
1036                 break;
1037
1038         case IDA_BUTTON_BACK:
1039                 {
1040                         Application::GetInstance()->Terminate();
1041                 }
1042                 break;
1043
1044         default:
1045                 break;
1046         }
1047 }
1048
1049 void
1050 VideoPlayerForm::OnTouchPressed(const Control& source, const Point& currentPosition,
1051                 const TouchEventInfo& touchInfo)
1052 {
1053         AppLogDebug("OnTouchPressed");
1054         __pUiControlTimer->Cancel();
1055 }
1056
1057 void
1058 VideoPlayerForm::OnTouchReleased(const Control& source, const Point& currentPosition,
1059                 const TouchEventInfo& touchInfo)
1060 {
1061         AppLogDebug("OnTouchReleased");
1062
1063         PlayerState playState = PLAYER_STATE_ERROR;
1064
1065         if ((&source == __pFastForwardButton
1066                 || &source == __pFastRewindButton)
1067                 && __actionTouchLongPressed == true)
1068         {
1069                 __pVideoPlayerPresentationModel->StopFastForwardRewind();
1070         }
1071
1072         playState = __pVideoPlayerPresentationModel->GetState();
1073
1074         if (playState == PLAYER_STATE_PLAYING)
1075         {
1076                 if (source.GetName() == L"IDL_MAIN_FORM"
1077                         || source.GetHashCode() == __pOverlayPanel->GetHashCode()
1078                         || source.GetHashCode() == __pHeader->GetHashCode())
1079                 {
1080                         if (__isControlVisibleState == true)
1081                         {
1082                                 if (source.GetHashCode() == __pHeader->GetHashCode())
1083                                 {
1084                                         if (__pUiControlTimer != null)
1085                                         {
1086                                                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1087                                         }
1088                                 }
1089                                 else
1090                                 {
1091                                         ShowControl(false);
1092                                 }
1093                         }
1094                         else
1095                         {
1096                                 ShowControl(true);
1097
1098                                 if (__pUiControlTimer != null)
1099                                 {
1100                                         __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1101                                 }
1102                         }
1103                 }
1104         }
1105 }
1106
1107 void
1108 VideoPlayerForm::OnTouchLongPressed(const Control& source, const Point& currentPosition,
1109                 const TouchEventInfo& touchInfo)
1110 {
1111         AppLogDebug("OnTouchLongPressed");
1112
1113         if (&source == __pFastForwardButton)
1114         {
1115                 __actionTouchLongPressed = true;
1116
1117                 if (__setPauseState == true)
1118                 {
1119                         __pVideoPlayerPresentationModel->FastForward(false);
1120                 }
1121                 else
1122                 {
1123                         __pVideoPlayerPresentationModel->FastForward(true);
1124                 }
1125         }
1126         else if (&source == __pFastRewindButton)
1127         {
1128                 __actionTouchLongPressed = true;
1129
1130                 if (__setPauseState == true)
1131                 {
1132                         __pVideoPlayerPresentationModel->FastRewind(false);
1133                 }
1134                 else
1135                 {
1136                         __pVideoPlayerPresentationModel->FastRewind(true);
1137                 }
1138         }
1139 }
1140
1141 void
1142 VideoPlayerForm::OnTouchMoved(const Control& source, const Point& currentPosition,
1143                 const TouchEventInfo& touchInfo)
1144 {
1145 }
1146
1147 void
1148 VideoPlayerForm::OnTouchFocusIn(const Control& source, const Point& currentPosition,
1149                 const TouchEventInfo& touchInfo)
1150 {
1151 }
1152
1153 void
1154 VideoPlayerForm::OnTouchFocusOut(const Control& source, const Point& currentPosition,
1155                 const TouchEventInfo& touchInfo)
1156 {
1157 }
1158
1159 void
1160 VideoPlayerForm::OnTimerExpired(Timer& timer)
1161 {
1162         if (timer.GetHashCode() == __pUiControlTimer->GetHashCode())
1163         {
1164                 if (__pVideoPlayerPresentationModel->GetState() == PLAYER_STATE_PLAYING)
1165                 {
1166                         ShowControl(false);
1167                 }
1168         }
1169 }
1170
1171 void
1172 VideoPlayerForm::OnAdjustmentValueChanged(const Control& source, int adjustment)
1173 {
1174         result r = E_FAILURE;
1175         long seekTime = 0;
1176
1177         AppLogDebug("OnAdjustmentValueChanged : %d", adjustment);
1178
1179         if (adjustment >= MIN_PROGRESS_RANGE && adjustment <= MAX_PROGRESS_RANGE)
1180         {
1181                 seekTime = adjustment * (__pVideoPlayerPresentationModel->GetDuration() / MAX_PROGRESS_RANGE);
1182
1183                 r = __pVideoPlayerPresentationModel->SeekTo(seekTime);
1184                 TryReturnVoid(r == E_SUCCESS, "__pVideoPlayerPresentationModel->SeekTo() failed:%s", GetErrorMessage(r));
1185
1186                 UpdateProgressBar(adjustment);
1187         }
1188
1189         if (__pVideoPlayerPresentationModel->GetState() == PLAYER_STATE_PLAYING)
1190         {
1191                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1192         }
1193 }
1194
1195 void
1196 VideoPlayerForm::OnKeyPressed(const Control& source, KeyCode keyCode)
1197 {
1198         AppLogDebug("OnKeyPressed Control : %ls, KeyCode : %d", source.GetName().GetPointer(), keyCode);
1199
1200         if (keyCode == KEY_SIDE_UP || keyCode == KEY_SIDE_DOWN)
1201         {
1202                 // Empty statement
1203         }
1204 }
1205
1206 void
1207 VideoPlayerForm::OnKeyReleased(const Control& source, KeyCode keyCode)
1208 {
1209 }
1210
1211 void
1212 VideoPlayerForm::OnKeyLongPressed(const Control& source, KeyCode keyCode)
1213 {
1214 }
1215
1216 void
1217 VideoPlayerForm::UpdateProgressBar(const int currentPlayTime)
1218 {
1219         TryReturnVoid(__pSlider, "__pSlider is null");
1220
1221         __pSlider->SetValue(currentPlayTime);
1222         __pSlider->Invalidate(true);
1223 }
1224
1225 void
1226 VideoPlayerForm::InitTimer(void)
1227 {
1228         __pUiControlTimer = new (std::nothrow) Timer();
1229         __pUiControlTimer->Construct(*this);
1230 }
1231
1232 void
1233 VideoPlayerForm::DeleteTimer(void)
1234 {
1235         if (__pUiControlTimer != null)
1236         {
1237                 __pUiControlTimer->Cancel();
1238                 delete __pUiControlTimer;
1239                 __pUiControlTimer = null;
1240         }
1241 }
1242
1243 result
1244 VideoPlayerForm::SetPlayPauseButtonImage(PlayerState playState)
1245 {
1246         result r = E_SUCCESS;
1247
1248         Bitmap* pPlayBitmap = null;
1249         Bitmap* pPauseBitmap = null;
1250         Point point(X_BASE, Y_BASE);
1251
1252         AppLogDebug("SetPlayPauseButtonImage : %d", playState);
1253
1254         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1255
1256         __pPlayPauseButton = static_cast<Button*>(__pControllerPanel->GetControl(IDC_BUTTON_PLAY));
1257         TryCatch(__pPlayPauseButton != null, r = E_SYSTEM, "__pPlayPauseButton is null");
1258
1259         if (playState == PLAYER_STATE_PLAYING)
1260         {
1261                 pPauseBitmap = pAppResource->GetBitmapN(L"T01-2_control_circle_icon_pause.png");
1262                 TryCatch(pPauseBitmap != null, r = E_SYSTEM, "pPauseBitmap is null");
1263
1264                 __pPlayPauseButton->SetNormalBitmap(point, *pPauseBitmap);
1265
1266                 __pPlayPauseButton->SetActionId(IDA_BUTTON_PAUSE);
1267                 __pPlayPauseButton->Invalidate(true);
1268
1269                 delete pPauseBitmap;
1270         }
1271         else
1272         {
1273                 pPlayBitmap = pAppResource->GetBitmapN(L"T01-2_control_circle_icon_play.png");
1274                 TryCatch(pPlayBitmap != null, r = E_SYSTEM, "pPlayBitmap is null");
1275
1276                 __pPlayPauseButton->SetNormalBitmap(point, *pPlayBitmap);
1277
1278                 __pPlayPauseButton->SetActionId(IDA_BUTTON_PLAY);
1279                 __pPlayPauseButton->Invalidate(true);
1280
1281                 delete pPlayBitmap;
1282         }
1283         return r;
1284
1285 CATCH:
1286         return r;
1287 }
1288
1289 void
1290 VideoPlayerForm::SetRepeatButtonImage(int repeatValue)
1291 {
1292         AppLogDebug("SetRepeatButtonImage");
1293         Bitmap* pRepeatBitmap = null;
1294         Bitmap* pRepeatPressBitmap = null;
1295
1296         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1297
1298         switch (repeatValue)
1299         {
1300         case REPEAT_TYPE_OFF:
1301                 {
1302                         pRepeatBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat.png");
1303                         pRepeatPressBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat_press.png");
1304                 }
1305                 break;
1306
1307         case REPEAT_TYPE_ONE:
1308                 {
1309                         pRepeatBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat_1.png");
1310                         pRepeatPressBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat_1_press.png");
1311                 }
1312                 break;
1313
1314         case REPEAT_TYPE_ALL:
1315                 {
1316                         pRepeatBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat_all.png");
1317                         pRepeatPressBitmap = pAppResource->GetBitmapN(L"T01-2_function_icon_repeat_all_press.png");
1318                 }
1319                 break;
1320
1321         default:
1322                 break;
1323         }
1324         __pRepeatModeButton->SetNormalBitmap(Point(X_BASE, Y_BASE), *pRepeatBitmap);
1325         __pRepeatModeButton->SetPressedBitmap(Point(X_BASE, Y_BASE), *pRepeatPressBitmap);
1326         __pVideoPlayerPresentationModel->SetRepeatMode(repeatValue);
1327         __pVideoPlayerPresentationModel->ChangeCurrentMediaIndex();
1328
1329         delete pRepeatBitmap;
1330         delete pRepeatPressBitmap;
1331 }
1332
1333 void
1334 VideoPlayerForm::SetScreenModeButtonImage(void)
1335 {
1336         AppLogDebug("SetScreenModeButtonImage");
1337         Rectangle rect;
1338         Point point(X_BASE, Y_BASE);
1339         Bitmap* pBitmapScreenMode = null;
1340
1341         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1342
1343         String mediaPathName = __pVideoPlayerPresentationModel->GetMediaPathName();
1344         rect = __pVideoPlayerPresentationModel->GetVideoInfoN(mediaPathName);
1345
1346         switch (__screenMode)
1347         {
1348         case SCREEN_MODE_NORMAL:
1349                 {
1350                         if (rect.width > W_NORMAL || rect.height > W_NORMAL)
1351                         {
1352                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode03.png");
1353                                 __pScreenModeButton->SetNormalBitmap(point, *pBitmapScreenMode);
1354                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode03_press.png");
1355                                 __pScreenModeButton->SetPressedBitmap(point, *pBitmapScreenMode);
1356                         }
1357                         else
1358                         {
1359                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_Function_icon_screenmode_press.png");
1360                                 __pScreenModeButton->SetNormalBitmap(point, *pBitmapScreenMode);
1361                                 pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_Function_icon_screenmode_press.png");
1362                                 __pScreenModeButton->SetPressedBitmap(point, *pBitmapScreenMode);
1363                         }
1364                 }
1365                 break;
1366
1367         case SCREEN_MODE_FULL:
1368                 {
1369                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode02.png");
1370                         __pScreenModeButton->SetNormalBitmap(point, *pBitmapScreenMode);
1371                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode02_press.png");
1372                         __pScreenModeButton->SetPressedBitmap(point, *pBitmapScreenMode);
1373                 }
1374                 break;
1375
1376         case SCREEN_MODE_FIT:
1377                 {
1378                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode03.png");
1379                         __pScreenModeButton->SetNormalBitmap(point, *pBitmapScreenMode);
1380                         pBitmapScreenMode = pAppResource->GetBitmapN(L"T01-2_function_icon_screenmode03_press.png");
1381                         __pScreenModeButton->SetPressedBitmap(point, *pBitmapScreenMode);
1382                 }
1383                 break;
1384
1385         default:
1386                 break;
1387         }
1388
1389         delete pBitmapScreenMode;
1390         pBitmapScreenMode = null;
1391 }
1392
1393 void
1394 VideoPlayerForm::GetTotalTime(String& totalTime)
1395 {
1396         result r = E_FAILURE;
1397         DateTime dateTime;
1398
1399         dateTime.AddSeconds(__pVideoPlayerPresentationModel->GetDuration() / MILLISECOND);
1400         r = totalTime.Format(20, L"%02d:%02d:%02d", dateTime.GetHour(), dateTime.GetMinute(), dateTime.GetSecond());
1401         TryReturnVoid(r == E_SUCCESS, "totalTime.Format() failed:%s", GetErrorMessage(r));
1402 }
1403
1404 void
1405 VideoPlayerForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
1406 {
1407         AppLogDebug("OnOrientationChanged");
1408
1409         SetScreenMode(__screenMode, false);
1410
1411         switch (orientationStatus)
1412         {
1413         case ORIENTATION_STATUS_PORTRAIT:
1414                 {
1415                         // Empty statement
1416                 }
1417                 break;
1418
1419         case ORIENTATION_STATUS_LANDSCAPE:
1420                 // fall through
1421         case ORIENTATION_STATUS_LANDSCAPE_REVERSE:
1422                 {
1423                         // Empty statement
1424                 }
1425                 break;
1426
1427         default:
1428                 break;
1429         }
1430 }
1431
1432 void
1433 VideoPlayerForm::PlayerSoundPathPopupInit(void)
1434 {
1435         int tempAudioRouteMode = 0;
1436         int currentOutputDevice = 0;
1437         tempAudioRouteMode = __audioRouteMode;
1438         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1439
1440         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1441         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1442
1443         __pSoundPathPopup = new (std::nothrow) SoundPathPopup();
1444         result r = __pSoundPathPopup->Construct(currentOutputDevice,
1445                         __pAudioRouteManager->GetActiveBluetoothA2dpName(), tempAudioRouteMode);
1446         TryReturnVoid(r == E_SUCCESS, "__pSoundPathPopup->Construct() failed:%s", GetErrorMessage(r));
1447 }
1448
1449 void
1450 VideoPlayerForm::CreateMessageBox(const String& title, const String& message, MessageBoxStyle style,
1451                 unsigned long timeout)
1452 {
1453 }
1454
1455 void
1456 VideoPlayerForm::ShowControl(bool setShow)
1457 {
1458         AppLogDebug("ShowControl");
1459
1460         if (setShow == true)
1461         {
1462                 __pHeader->SetShowState(true);
1463                 __pFunctionPanel->SetShowState(true);
1464                 __pControllerPanel->SetShowState(true);
1465                 __isControlVisibleState = true;
1466         }
1467         else
1468         {
1469                 __pHeader->SetShowState(false);
1470                 __pFunctionPanel->SetShowState(false);
1471                 __pControllerPanel->SetShowState(false);
1472
1473                 if (__pContextMenuShare != null)
1474                 {
1475                         if (__pContextMenuShare->GetShowState() == true)
1476                         {
1477                                 __pContextMenuShare->SetShowState(false);
1478                         }
1479                 }
1480
1481                 __isControlVisibleState = false;
1482         }
1483 }
1484
1485 void
1486 VideoPlayerForm::ShowControlByFrameActivated(void)
1487 {
1488         AppLogDebug("ShowControlByFrameActivated");
1489
1490         CheckCallStatus();
1491         CheckLowBatteryStatus();
1492 }
1493
1494 void
1495 VideoPlayerForm::CancelTimerByFrameDeactivated(void)
1496 {
1497         AppLogDebug("CancelTimerByFrameDeactivated");
1498
1499         __pUiControlTimer->Cancel();
1500         __setPauseState = true;
1501
1502         ShowControl(true);
1503         __pScreenModeButton->SetShowState(false);
1504 }
1505
1506 void
1507 VideoPlayerForm::OnPlayContentChanged(const String& fileName)
1508 {
1509         String totalTime;
1510
1511         AppLogDebug("OnPlayContentChanged");
1512
1513         GetTotalTime(totalTime);
1514
1515         __pHeader->SetTitleText(fileName);
1516         __pHeader->Invalidate(true);
1517
1518         __pTotalTimeLabel->SetText(totalTime);
1519         __pTotalTimeLabel->Invalidate(true);
1520 }
1521
1522 void
1523 VideoPlayerForm::OnPlayTimeChanged(int currentProgressPos, String& playTime)
1524 {
1525         AppLogDebug("OnPlayTimeChanged");
1526
1527         __pSlider->SetValue(currentProgressPos);
1528         __pSlider->Invalidate(true);
1529
1530         __pCurrenTimeLabel->SetText(playTime);
1531         __pCurrenTimeLabel->Invalidate(true);
1532 }
1533
1534 void
1535 VideoPlayerForm::OnPlayStateChanged(PlayerState playState)
1536 {
1537         AppLogDebug("OnPlayStateChanged");
1538
1539         SetPlayPauseButtonImage(playState);
1540
1541         if (playState == PLAYER_STATE_PLAYING)
1542         {
1543                 __pUiControlTimer->Start(SHOW_CONTROL_DURATION);
1544         }
1545         else
1546         {
1547                 __pUiControlTimer->Cancel();
1548                 ShowControl(true);
1549         }
1550 }
1551
1552 void
1553 VideoPlayerForm::CheckLowBatteryStatus(void)
1554 {
1555         int result = 0;
1556         MessageBox msgBox;
1557         bool isCharging = false;
1558         BatteryLevel batteryLevel;
1559
1560         AppLogDebug("CheckLowBatteryStatus");
1561
1562         Battery::GetCurrentLevel(batteryLevel);
1563         Battery::IsCharging(isCharging);
1564
1565         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY)
1566         {
1567                 if (isCharging == false)
1568                 {
1569                         msgBox.Construct(L"", L"Unable to video play.Low battery", MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_3_SEC);
1570                         msgBox.ShowAndWait(result);
1571
1572                         switch (result)
1573                         {
1574                         case MSGBOX_RESULT_CLOSE:
1575                                 {
1576                                         AppLogDebug("MSGBOX_RESULT_CLOSE");
1577                                         OnFormBackRequested(*this);
1578                                 }
1579                                 break;
1580
1581                         default:
1582                                 break;
1583                         }
1584                 }
1585         }
1586 }
1587
1588 void
1589 VideoPlayerForm::CheckCallStatus(void)
1590 {
1591         MessageBox msgBox;
1592         String dispString;
1593         int modalResult = 0;
1594         result r = E_FAILURE;
1595
1596         AppLogDebug("CheckCallStatus");
1597
1598         CallManager* pCallManager = new (std::nothrow) CallManager();
1599
1600         r = pCallManager->Construct();
1601         TryCatch(r == E_SUCCESS, , "pCallManager->Construct() failed : %s", GetErrorMessage(r));
1602
1603         if (pCallManager->GetCurrentCallStatus() != CALL_STATUS_IDLE
1604                 && pCallManager->GetCurrentCallStatus() != CALL_STATUS_UNDEFINED)
1605         {
1606                 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1607                 pAppResource->GetString(L"IDS_VPL_BODY_UNABLE_TO_PLAY_VIDEO_DURING_CALL", dispString);
1608
1609                 msgBox.Construct(L"", dispString, MSGBOX_STYLE_NONE, MESSAGEBOX_DISPLAY_TIME_3_SEC);
1610                 msgBox.ShowAndWait(modalResult);
1611
1612                 switch (modalResult)
1613                 {
1614                 case MSGBOX_RESULT_CLOSE:
1615                         {
1616                                 AppLogDebug("MSGBOX_RESULT_CLOSE");
1617                                 OnFormBackRequested(*this);
1618                         }
1619                         break;
1620
1621                 default:
1622                         break;
1623                 }
1624         }
1625
1626 CATCH:
1627         delete pCallManager;
1628 }
1629
1630 void
1631 VideoPlayerForm::OnFormBackRequested(Form& source)
1632 {
1633         result r = E_FAILURE;
1634
1635         AppLogDebug("OnFormBackRequested");
1636
1637         UiApp* pApp = UiApp::GetInstance();
1638         TryReturnVoid(pApp != null, "pApp is null");
1639
1640         r = pApp->Terminate();
1641         TryReturnVoid(r == E_SUCCESS, "Failed Terminate [%s]", GetErrorMessage(r));
1642 }
1643
1644 void
1645 VideoPlayerForm::OnActiveAudioRouteChanged(const AudioRouteInfo& route)
1646 {
1647         Color BtnColor(0, 0, 0, 0);
1648         int currentOutputAudioDevice = 0;
1649         ArrayList* pArgs = null;
1650
1651         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1652
1653         AppLogDebug("OnActiveAudioRouteChanged");
1654
1655         switch (route.GetOutputAudioDevice())
1656         {
1657         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
1658                 {
1659                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
1660                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1661                         {
1662                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1663                         }
1664                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
1665                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1666                         {
1667                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
1668
1669                                 if (__pSoundPathPopup != null)
1670                                 {
1671                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1672                                         pArgs->Construct();
1673
1674                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
1675                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1676
1677                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
1678                                 }
1679                         }
1680                 }
1681                 break;
1682
1683         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
1684                 {
1685                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
1686                                 &&(__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1687                         {
1688                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1689
1690                                 if (__pSoundPathPopup != null)
1691                                 {
1692                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1693                                         pArgs->Construct();
1694
1695                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
1696
1697                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_WIRED_ACCESSORY_MENU,
1698                                                         pArgs);
1699                                 }
1700                         }
1701                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
1702                                         &&(__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1703                         {
1704                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
1705
1706                                 if (__pSoundPathPopup != null)
1707                                 {
1708                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1709                                         currentOutputAudioDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1710
1711                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1712                                         pArgs->Construct();
1713
1714                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1715                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputAudioDevice)));
1716
1717                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
1718                                 }
1719                         }
1720                 }
1721                 break;
1722
1723         case OUTPUT_AUDIO_DEVICE_SPEAKER:
1724                 {
1725                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
1726                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false))
1727                         {
1728                                 __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
1729
1730                                 if (__pSoundPathPopup != null)
1731                                 {
1732                                         if (__pSoundPathPopup->GetShowState() == true)
1733                                         {
1734                                                 __pSoundPathPopup->SetShowState(false);
1735                                         }
1736                                 }
1737                         }
1738                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
1739                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false))
1740                         {
1741                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
1742
1743                                 if (__pSoundPathPopup != null)
1744                                 {
1745                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1746                                         currentOutputAudioDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1747
1748                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1749                                         pArgs->Construct();
1750
1751                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1752                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputAudioDevice)));
1753
1754                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
1755                                 }
1756                         }
1757                 }
1758                 break;
1759
1760         default:
1761                 break;
1762         }
1763 }
1764
1765 void
1766 VideoPlayerForm::OnAudioRouteAdded(const AudioRouteInfo& route)
1767 {
1768         AppLogDebug("OnAudioRouteAdded");
1769
1770         switch (route.GetOutputAudioDevice())
1771         {
1772         case OUTPUT_AUDIO_DEVICE_NONE:
1773                 {
1774                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = true;
1775                 }
1776                 break;
1777
1778         case OUTPUT_AUDIO_DEVICE_SPEAKER:
1779                 {
1780                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = true;
1781                 }
1782                 break;
1783
1784         case OUTPUT_AUDIO_DEVICE_RECEIVER:
1785                 {
1786                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = true;
1787                 }
1788                 break;
1789
1790         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
1791                 {
1792                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = true;
1793                 }
1794                 break;
1795
1796         case OUTPUT_AUDIO_DEVICE_BT_SCO:
1797                 {
1798                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = true;
1799                 }
1800                 break;
1801
1802         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
1803                 {
1804                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] = true;
1805                 }
1806                 break;
1807
1808         default:
1809                 break;
1810         }
1811 }
1812
1813 void
1814 VideoPlayerForm::OnAudioRouteRemoved(const AudioRouteInfo& route)
1815 {
1816         ArrayList* pArgs = null;
1817         int currentOutputDevice = 0;
1818         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1819
1820         AppLogDebug("OnAudioRouteRemoved");
1821
1822         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1823
1824         switch (route.GetOutputAudioDevice())
1825         {
1826         case OUTPUT_AUDIO_DEVICE_NONE:
1827                 {
1828                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = false;
1829                 }
1830                 break;
1831
1832         case OUTPUT_AUDIO_DEVICE_SPEAKER:
1833                 {
1834                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = false;
1835                 }
1836                 break;
1837
1838         case OUTPUT_AUDIO_DEVICE_RECEIVER:
1839                 {
1840                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = false;
1841                 }
1842                 break;
1843
1844         case OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY:
1845                 {
1846                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = false;
1847                 }
1848                 break;
1849
1850         case OUTPUT_AUDIO_DEVICE_BT_SCO:
1851                 {
1852                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = false;
1853                 }
1854                 break;
1855
1856         case OUTPUT_AUDIO_DEVICE_BT_A2DP:
1857                 {
1858                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] = false;
1859                 }
1860                 break;
1861
1862         default:
1863                 break;
1864         }
1865
1866         if (currentAudioRoute.GetOutputAudioDevice() != route.GetOutputAudioDevice())
1867         {
1868                 if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_A2DP)
1869                 {
1870                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
1871                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1872                         {
1873                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
1874
1875                                 if (__pSoundPathPopup != null)
1876                                 {
1877                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1878                                         pArgs->Construct();
1879
1880                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
1881                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1882
1883                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
1884                                 }
1885                         }
1886                 }
1887                 else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
1888                 {
1889                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
1890                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1891                         {
1892                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1893                         }
1894                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
1895                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
1896                         {
1897                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
1898                         }
1899                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
1900                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
1901                         {
1902                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
1903
1904                                 if (__pSoundPathPopup != null)
1905                                 {
1906                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1907                                         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1908
1909                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1910                                         pArgs->Construct();
1911
1912                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1913                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputDevice)));
1914
1915                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
1916                                 }
1917                         }
1918                 }
1919                 else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
1920                 {
1921                         if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
1922                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
1923                         {
1924                                 __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
1925
1926                                 if (__pSoundPathPopup != null)
1927                                 {
1928                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1929                                         pArgs->Construct();
1930
1931                                         pArgs->Add(*(new (std::nothrow) String(__pAudioRouteManager->GetActiveBluetoothA2dpName())));
1932                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1933
1934                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_BLUETOOTHA2DP_AND_SPEAKER_MENU, pArgs);
1935                                 }
1936                         }
1937                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
1938                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true))
1939                         {
1940                                 __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
1941
1942                                 if (__pSoundPathPopup != null)
1943                                 {
1944                                         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
1945                                         currentOutputDevice = static_cast<int>(currentAudioRoute.GetOutputAudioDevice());
1946
1947                                         pArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
1948                                         pArgs->Construct();
1949
1950                                         pArgs->Add(*(new (std::nothrow) Integer(__audioRouteMode)));
1951                                         pArgs->Add(*(new (std::nothrow) Integer(currentOutputDevice)));
1952
1953                                         __pSoundPathPopup->SendUserEvent(REQUEST_UPDATE_WIRED_ACCESSORY_AND_SPEAKER_MENU, pArgs);
1954                                 }
1955                         }
1956                         else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
1957                                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
1958                         {
1959                                 __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
1960
1961                                 if (__pSoundPathPopup != null)
1962                                 {
1963                                         if (__pSoundPathPopup->GetShowState() == true)
1964                                         {
1965                                                 __pSoundPathPopup->SetShowState(false);
1966                                         }
1967                                 }
1968                         }
1969                 }
1970         }
1971 }
1972
1973 void
1974 VideoPlayerForm::InitAudioRouteList(void)
1975 {
1976         AppLogDebug("InitAudioRouteList");
1977
1978         int listCount = 0;
1979         IList* availableAudioRouteList = null;
1980         AudioRouteInfo* tempRouteInfo = null;
1981         AudioRouteInfo availableRouteInfo(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1982         AudioRouteInfo currentAudioRoute(INPUT_AUDIO_DEVICE_NONE, OUTPUT_AUDIO_DEVICE_NONE);
1983
1984         availableAudioRouteList = __pAudioRouteManager->GetAvailableAudioRouteListN();
1985
1986         for (listCount = 0; listCount < availableAudioRouteList->GetCount(); ++listCount)
1987         {
1988                 tempRouteInfo = static_cast<AudioRouteInfo*>(availableAudioRouteList->GetAt(listCount));
1989                 availableRouteInfo = *tempRouteInfo;
1990
1991                 if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_NONE)
1992                 {
1993                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_NONE] = true;
1994                 }
1995                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
1996                 {
1997                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] = true;
1998                 }
1999                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_RECEIVER)
2000                 {
2001                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_RECEIVER] = true;
2002                 }
2003                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
2004                 {
2005                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] = true;
2006                 }
2007                 else if (availableRouteInfo.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_SCO)
2008                 {
2009                         __availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_SCO] = true;
2010                 }
2011                 else
2012                 {
2013                         __availableAudioRoute[OUTPUT_AUDIO_DEVICE_BT_A2DP] = true;
2014                 }
2015         }
2016
2017         currentAudioRoute = __pAudioRouteManager->GetActiveAudioRoute();
2018
2019         if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_BT_A2DP)
2020         {
2021                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
2022                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2023                 {
2024                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2025                 }
2026                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true)
2027                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
2028                 {
2029                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2030                 }
2031                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false)
2032                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2033                 {
2034                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2035                 }
2036         }
2037         else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_WIRED_ACCESSORY)
2038         {
2039                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2040                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2041                 {
2042                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2043                 }
2044                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2045                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == false))
2046                 {
2047                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_WIRED_ACCESSORY;
2048                 }
2049                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2050                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_SPEAKER] == true))
2051                 {
2052                         __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2053                 }
2054         }
2055         else if (currentAudioRoute.GetOutputAudioDevice() == OUTPUT_AUDIO_DEVICE_SPEAKER)
2056         {
2057                 if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == true)
2058                         && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2059                 {
2060                         __audioRouteMode = AUDIO_ROUTE_BT_A2DP_AND_SPEAKER;
2061                 }
2062                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2063                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == true))
2064                 {
2065                         __audioRouteMode = AUDIO_ROUTE_WIRED_ACCESSORY_AND_SPEAKER;
2066                 }
2067                 else if ((__availableAudioRoute[OUTPUT_AUDIO_ROUTE_BT_A2DP] == false)
2068                                 && (__availableAudioRoute[OUTPUT_AUDIO_ROUTE_WIRED_ACCESSORY] == false))
2069                 {
2070                         __audioRouteMode = AUDIO_ROUTE_SPEAKER_ONLY;
2071                 }
2072         }
2073 }
2074
2075 result
2076 VideoPlayerForm::SetActiveAudioRoute(const AudioRouteInfo& route)
2077 {
2078         AppLogDebug("SetActiveAudioRoute");
2079         result r = __pAudioRouteManager->SetActiveAudioRoute(route);
2080
2081         return r;
2082 }
2083
2084 void
2085 VideoPlayerForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
2086 {
2087         BatteryLevel batteryLevel;
2088         bool isCharging = false;
2089
2090         AppLogDebug("OnUserEventReceivedN");
2091
2092         switch (requestId)
2093         {
2094         case REQUEST_VIDEO_EVENT_BATTERY_LEVEL_CHANGED:
2095                 {
2096                         Battery::GetCurrentLevel(batteryLevel);
2097                         Battery::IsCharging(isCharging);
2098
2099                         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY)
2100                         {
2101                                 if (isCharging == false)
2102                                 {
2103                                         OnFormBackRequested(*this);
2104                                 }
2105                         }
2106                 }
2107                 break;
2108
2109         default:
2110                 break;
2111         }
2112 }
2113
2114 void
2115 VideoPlayerForm::OnAppControlCompleteResponseReceived(const AppId& appId, const Tizen::Base::String& operationId,
2116                         AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
2117 {
2118         AppLogDebug("OnAppControlCompleteResponseReceived : %d", appControlResult);
2119 }