Removed footer from ImageViewer:N_SE-49146
[apps/native/sample/MediaApp.git] / project / src / Player / VideoRecorderPlayerForm.cpp
1 //
2 // Tizen Native SDK
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FMedia.h>
19 #include <FSystem.h>
20 #include <FIo.h>
21 #include <FApp.h>
22 #include <FBase.h>
23 #include <stdio.h>
24 #include <FApp.h>
25 #include "SafeMacros.h"
26 #include "AppConfig.h"
27 #include "UnitTestFactory.h"
28 #include "MediaPlayerForm.h"
29 #include "VideoRecorderPlayerForm.h"
30 #include "AppResourceId.h"
31
32
33 using namespace Tizen::Ui;
34 using namespace Tizen::Io;
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::System;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui::Controls;
40
41 #define SECTION_NAME            L"VideoRecorder_Player"
42 #define METHOD_FILE_LINENO      __FUNCTION__, __FILE__, (__LINE__ - 1)
43
44 #define TIMER_VALUE           500
45 #define KILOBYTE                1000
46 #define MESSAGE_BOX_TIMEOUT     10000
47
48 static const wchar_t* FORM_ID = L"VideoRecorderPlayerForm";
49 extern const wchar_t* VIDEO_RECORDER_PLAYER_SCENE_ID = L"VideoRecorderPlayerScene";
50
51 VideoRecorderPlayerForm*
52 VideoRecorderPlayerForm::CreateFormN(const Tizen::Ui::Scenes::SceneId &sceneId)
53 {
54         SceneManager* pSceneManager = SceneManager::GetInstance();
55         VideoRecorderPlayerForm* pForm = new (std::nothrow) VideoRecorderPlayerForm();
56         pForm->Initialize();
57         pSceneManager->AddSceneEventListener(sceneId, *(pForm->GetListener()));
58         return pForm;
59 }
60
61 MultiForm* VideoRecorderPlayerForm::FormCreateFunc()
62 {
63         VideoRecorderPlayerForm* pForm = VideoRecorderPlayerForm::CreateFormN(VIDEO_RECORDER_PLAYER_SCENE_ID);
64         return pForm;
65 }
66
67 String VideoRecorderPlayerForm::GetFormId()
68 {
69         return FORM_ID;
70 }
71
72 SceneId VideoRecorderPlayerForm::GetSceneId()
73 {
74         return VIDEO_RECORDER_PLAYER_SCENE_ID;
75 }
76 VideoRecorderPlayerForm::VideoRecorderPlayerForm(void)
77         : __pCamera(null)
78         , __pPlayer(null)
79         , __pCameraOverlay(null)
80         , __pPlayerOverlay(null)
81         , __batteryLevelFlag(false)
82         , __backGroundFlag(false)
83         , __cameraErrorFlag(false)
84         , __isHeadSetRemoved(false)
85         , __pVideoRecorder(null)
86         , __pTimer(null)
87         , __pConfig(null)
88         , __pProgress(null)
89 {
90
91 }
92
93 VideoRecorderPlayerForm::~VideoRecorderPlayerForm(void)
94 {
95         if (__pTimer != null)
96         {
97                 __pTimer->Cancel();
98                 SAFE_DELETE(__pTimer);
99         }
100
101         SAFE_DELETE(__pCameraOverlay);
102         SAFE_DELETE(__pPlayerOverlay);
103         SAFE_DELETE(__pPlayer);
104         SAFE_DELETE(__pCamera);
105         SAFE_DELETE(__pVideoRecorder);
106 }
107
108 bool
109 VideoRecorderPlayerForm::Initialize()
110 {
111         result r = E_SUCCESS;
112         r = Construct(IDF_VIDEO_RECORDER_PLAYER);
113         AppLog("Initialize return = %s", GetErrorMessage(r));
114         return true;
115 }
116
117 result
118 VideoRecorderPlayerForm::OnInitializing(void)
119 {
120         Footer* pFooter = GetFooter();
121         Header* pHeader = GetHeader();
122
123         SetHeaderText(L"Video recorder & player");
124         SetFooterStyle(FOOTER_STYLE_BUTTON_TEXT, ID_BUTTON_BACK, this);
125         AddFooterItem(L"Start", ID_BUTTON_START);
126
127         pFooter->AddTouchEventListener(*this);
128         pHeader->AddTouchEventListener(*this);
129
130         __pProgress = static_cast< Progress* >(GetControl(IDC_PROGRESS));
131         TryReturn(__pProgress != null, E_FAILURE,"__pProgress value is null from GetControl");
132
133         __pProgress->SetValue(0);
134         __pProgress->Draw();
135
136         __pConfig = AppConfig::GetInstance();
137         TryReturn(__pConfig != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pConfig is null");
138
139         //disable all buttons until camera is ready
140         ShowFooterItem(0, false);
141
142         AppLog("VideoRecorderPlayerForm::OnInitializing returned success");
143         return E_SUCCESS;
144 }
145
146
147 result
148 VideoRecorderPlayerForm::CreateOverlayRegionForCamera(void)
149 {
150         Rectangle rect = GetClientAreaBounds();
151         Rectangle clientRect = GetClientAreaBounds();
152         bool modified = false;
153         bool isValidRect = false;
154
155         SAFE_DELETE(__pCameraOverlay);
156
157         AppLog("Client area rect (%d,%d,%d,%d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
158         HideAndGetBounds(GetControl(IDC_OVERLAY_REGION), rect);
159         AppLog("Original w.r.t IDC_BUTTON rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
160
161         if (rect.width > clientRect.width || rect.height > clientRect.height)
162         {
163                 rect.width = clientRect.width;
164                 rect.height = clientRect.height;
165         }
166
167         AppLog("Rect passed to OverlayRegion::EvaluateBounds is (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
168         isValidRect = OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN, rect, modified);
169         TryReturn(isValidRect == true, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"OverlayRegion::EvaluateBounds returned error");
170
171         if (modified == true)
172         {
173                 AppLog("Bounds is modified to (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
174         }
175
176         AppLog("Overlay region width = %d  height = %d", rect.width, rect.height);
177
178         __pCameraOverlay = Tizen::Ui::Controls::Form::GetOverlayRegionN(rect, OVERLAY_REGION_TYPE_PRIMARY_CAMERA);
179         AppLog("Overlay region pointer = %X x = %d, y = %d, width = %d  height = %d", __pCameraOverlay, rect.x, rect.y, rect.width, rect.height);
180
181         TryReturn(__pCameraOverlay != null, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"__pCameraOverlay is null");
182
183         return E_SUCCESS;
184 }
185
186 result
187 VideoRecorderPlayerForm::CreateOverlayRegionForPlayer(void)
188 {
189         Rectangle rect = GetClientAreaBounds();
190         Rectangle clientRect = GetClientAreaBounds();
191         bool modified = false;
192         bool isValidRect = false;
193
194         SAFE_DELETE(__pPlayerOverlay);
195
196         AppLog("Client area rect (%d,%d,%d,%d)", clientRect.x, clientRect.y, clientRect.width, clientRect.height);
197         HideAndGetBounds(GetControl(IDC_OVERLAY_REGION2), rect);
198         AppLog("Original rect (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
199
200         if (rect.width > clientRect.width || rect.height > clientRect.height)
201         {
202                 rect.width = clientRect.width;
203                 rect.height = clientRect.height;
204         }
205
206         isValidRect = OverlayRegion::EvaluateBounds(OVERLAY_REGION_EVALUATION_OPTION_LESS_THAN, rect, modified);
207         TryReturn(isValidRect == true, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"OverlayRegion::EvaluateBounds returned error");
208
209         if (modified == true)
210         {
211                 AppLog("Bounds is modified to (%d,%d,%d,%d)", rect.x, rect.y, rect.width, rect.height);
212         }
213
214         AppLog("Overlay region width = %d  height = %d", rect.width, rect.height);
215
216         __pPlayerOverlay = Tizen::Ui::Controls::Form::GetOverlayRegionN(rect, OVERLAY_REGION_TYPE_NORMAL);
217         AppLog("Overlay region pointer = %X x = %d, y = %d, width = %d  height = %d", __pCameraOverlay, rect.x, rect.y, rect.width, rect.height);
218
219         TryReturn(__pPlayerOverlay != null, ShowErrorResult(GetLastResult(), METHOD_FILE_LINENO),"__pPlayerOverlay is null");
220
221         return E_SUCCESS;
222 }
223 VideoRecorderPlayerForm*
224 VideoRecorderPlayerForm::GetListener(void)
225 {
226         return this;
227 }
228 void
229 VideoRecorderPlayerForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
230                                                                    const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
231 {
232         Activate(null);
233 }
234 void
235 VideoRecorderPlayerForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
236                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
237 {
238 }
239
240 result
241 VideoRecorderPlayerForm::Activate(void* activateParam)
242 {
243         result r = E_SUCCESS;
244         Tizen::System::BatteryLevel batteryLevel;
245         Tizen::System::Battery::GetCurrentLevel(batteryLevel);
246
247         __backGroundFlag = false;
248         __cameraErrorFlag = false;
249
250         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
251         {
252                 bool isCharging = false;
253                 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
254                 if (isCharging == false)
255                 {
256                         ShowMessagePopup("Please Charge the Battery to use this feature", ID_BUTTON_ERROR_POPUP_OK);
257                         return E_SUCCESS;
258                 }
259                 else
260                 {
261                         EnableFooterItem(ID_BUTTON_START, true);
262                 }
263         }
264         else
265         {
266                 EnableFooterItem(ID_BUTTON_START, true);
267         }
268
269         __batteryLevelFlag = false;
270
271         Tizen::System::PowerManager::KeepScreenOnState(true, false);
272         SetOrientation(ORIENTATION_LANDSCAPE);
273
274         r = CreateOverlayRegionForCamera();
275         TryReturn(r == E_SUCCESS, r,"CreateOverlayRegionForCamera failed");
276
277         r = CreateOverlayRegionForPlayer();
278         TryReturn(r == E_SUCCESS, r,"CreateOverlayRegionForPlayer failed");
279
280         __pProgress->SetValue(0);
281         __pProgress->Draw();
282
283         SAFE_DELETE(__pTimer);
284         __pTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
285         TryReturn(__pTimer != null, E_OUT_OF_MEMORY,"__pTimer creation failed, no memory");
286
287         r = __pTimer->Construct(*this);
288         TryReturn(r == E_SUCCESS, r,"[%s] __pTimer->Construct", GetErrorMessage(r));
289
290         r = CreateCamera();
291         TryReturn(r == E_SUCCESS, r,"[%s] createCamera failed", GetErrorMessage(r));
292
293         r = CreateVideoRecorder();
294         TryReturn(r == E_SUCCESS, r,"[%s] CreateVideoRecorder failed", GetErrorMessage(r));
295
296         SetFooterItem(0, L"Start", ID_BUTTON_START);
297         return E_SUCCESS;
298 }
299
300 result
301 VideoRecorderPlayerForm::CreateCamera()
302 {
303         result r = E_SUCCESS;
304
305         __pCamera = new (std::nothrow) Camera();
306         TryReturn(__pCamera != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pCamera creation failed, no memory");
307
308         r = __pCamera->Construct(*this, CAMERA_PRIMARY);
309         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pCamera->Construct", GetErrorMessage(r));
310
311         r = __pCamera->PowerOn();
312         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pCamera->PowerOn", GetErrorMessage(r));
313
314         return r;
315 }
316
317 result
318 VideoRecorderPlayerForm::CreateVideoRecorder()
319 {
320         result r = E_SUCCESS;
321
322         __pVideoRecorder = new (std::nothrow) Tizen::Media::VideoRecorder();
323         TryReturn(__pVideoRecorder != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pVideoRecorder creation failed, no memory");
324
325         r = __pVideoRecorder->Construct(*this, *__pCamera);
326         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pVideoRecorder->Construct", GetErrorMessage(r));
327
328         return r;
329 }
330
331 result
332 VideoRecorderPlayerForm::CreatePlayer()
333 {
334         result r = E_SUCCESS;
335         Tizen::Graphics::BufferInfo bufferInfo;
336         String filePath;
337         filePath.Clear();
338         filePath.Append(App::GetInstance()->GetAppRootPath());
339         filePath.Append(__pConfig->GetString(SECTION_NAME, String(L"playerFileName")));
340
341         AppLog("playerFileName is %ls", filePath.GetPointer());
342
343         SAFE_DELETE(__pPlayer);
344
345         __pPlayer = new (std::nothrow) Player();
346         TryReturn(__pPlayer != null, ShowErrorResult(E_OUT_OF_MEMORY, METHOD_FILE_LINENO),"__pPlayer creation failed, no memory");
347
348         r = __pPlayerOverlay->GetBackgroundBufferInfo(bufferInfo);
349         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayerOverlay->GetBackgroundBufferInfo", GetErrorMessage(r));
350
351         r = __pPlayer->Construct(*this, &bufferInfo);
352         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->Construct", GetErrorMessage(r));
353
354         AppLog("File path is %ls", filePath.GetPointer());
355         r = __pPlayer->OpenFile(filePath); // Sync open, at once
356         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] pPlayer->OpenFile", GetErrorMessage(r));
357
358         r = __pPlayer->SetLooping(true);
359         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->SetLooping", GetErrorMessage(r));
360
361         r = __pPlayer->SetVolume(80);
362         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] __pPlayer->SetVolume", GetErrorMessage(r));
363
364         return r;
365 }
366
367 result
368 VideoRecorderPlayerForm::StartCamera()
369 {
370         result r = E_SUCCESS;
371         IList* pPreviewResolutionList = null;
372         Dimension* pResolution = null;
373
374         TryReturn(__pCameraOverlay != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCameraOverlay handle is null");
375         TryReturn(__pCamera != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCamera handle is null");
376
377         r = __pCameraOverlay->GetBackgroundBufferInfo(__bufferInfoCamera);
378         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCameraOverlay->GetBackgroundBufferInfo");
379
380         pPreviewResolutionList = __pCamera->GetSupportedPreviewResolutionListN();
381         TryCatch(pPreviewResolutionList != null, ShowError(GetLastResult(), METHOD_FILE_LINENO), " __pCamera->GetSupportedPreviewResolutionListN returned empty");
382
383         pResolution = static_cast< Dimension* >(pPreviewResolutionList->GetAt(0));
384         TryCatch(pResolution != null, ShowError(E_SYSTEM, METHOD_FILE_LINENO),"pPreviewResolutionList->GetAt");
385
386         r = __pCamera->SetPreviewResolution(*pResolution);
387         TryCatch(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO),"[%s] __pCamera->SetPreviewResolution", GetErrorMessage(r));
388         AppLog(" PreviewResolution = width(%d) height(%d)", pResolution->width, pResolution->height);
389
390
391         AppLog("StartPreview called");
392         r = __pCamera->StartPreview(&__bufferInfoCamera, false);
393         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCamera->StartPreview");
394
395         pPreviewResolutionList->RemoveAll(true);
396         delete pPreviewResolutionList;
397
398         return E_SUCCESS;
399 CATCH:
400         if (pPreviewResolutionList != null)
401         {
402                 pPreviewResolutionList->RemoveAll(true);
403                 delete pPreviewResolutionList;
404         }
405         return r;
406 }
407
408 result
409 VideoRecorderPlayerForm::StopCamera()
410 {
411         result r = E_SUCCESS;
412
413         TryReturn(__pCamera != null, ShowErrorResult(E_FAILURE, METHOD_FILE_LINENO),"__pCamera handle is null");
414
415         if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
416         {
417                 r = __pCamera->StopPreview();
418                 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"__pCamera->StopPreview");
419         }
420
421         return r;
422 }
423
424 void
425 VideoRecorderPlayerForm::GetAudioCodecFormat(String& audioCodecType, CodecType& audioCodec)
426 {
427         //Only supported audio codecs are checked
428         if (audioCodecType == L"AMR_NB")
429         {
430                 audioCodec = CODEC_AMR_NB;
431         }
432         else if (audioCodecType == L"AAC")
433         {
434                 audioCodec = CODEC_AAC;
435         }
436         else
437         {
438                 audioCodec = CODEC_NONE;
439         }
440 }
441
442 void
443 VideoRecorderPlayerForm::GetVideoCodecFormat(String& videoCodecType, CodecType& videoCodec)
444 {
445         //Only supported video codecs are checked
446         if (videoCodecType == L"H263")
447         {
448                 videoCodec = CODEC_H263;
449         }
450         else if (videoCodecType == L"MPEG4")
451         {
452                 videoCodec = CODEC_MPEG4;
453         }
454         else if (videoCodecType == L"H264")
455         {
456                 videoCodec = CODEC_H264;
457         }
458         else
459         {
460                 videoCodec = CODEC_NONE;
461         }
462 }
463
464 void
465 VideoRecorderPlayerForm::GetFileFormat(String& fileFormatType, MediaContainerType& fileformat)
466 {
467         //Only supported video codecs are checked
468         if (fileFormatType == L"3gp")
469         {
470                 fileformat = MEDIA_CONTAINER_3GP;
471         }
472         else if (fileFormatType == L"MP4")
473         {
474                 fileformat = MEDIA_CONTAINER_MP4;
475         }
476         else
477         {
478                 fileformat = MEDIA_CONTAINER_NONE;
479         }
480 }
481
482 result
483 VideoRecorderPlayerForm::StartRecording()
484 {
485         result r = E_SUCCESS;
486         CodecType audioCodec = CODEC_NONE;
487         CodecType videoCodec = CODEC_NONE;
488         MediaContainerType container = MEDIA_CONTAINER_NONE;
489         unsigned int maxRecordingTime = 0;
490         String audioCodecType;
491         String videoCodectype;
492         String fileFormatType;
493         IList* pRecordingResolutionList = null;
494         Dimension* pResolution = null;
495
496         __filePath.Clear();
497         __filePath.Append(App::GetInstance()->GetAppRootPath() + L"data/Video/videorecorder.3gp");
498
499         maxRecordingTime = __pConfig->GetInt(0, SECTION_NAME, String(L"maxRecordingTime"));
500
501         if (maxRecordingTime == 0 || maxRecordingTime == 0)
502         {
503                 maxRecordingTime = (15 * 1000); //15 sec
504         }
505
506         audioCodecType = __pConfig->GetString(SECTION_NAME, String(L"audioCodec"));
507         videoCodectype = __pConfig->GetString(SECTION_NAME, String(L"videoCodec"));
508         fileFormatType = __pConfig->GetString(SECTION_NAME, String(L"FileFormat"));
509
510         GetAudioCodecFormat(audioCodecType, audioCodec);
511         GetVideoCodecFormat(videoCodectype, videoCodec);
512         GetFileFormat(fileFormatType, container);
513
514         if (audioCodec == CODEC_NONE ||
515                 videoCodec == CODEC_NONE ||
516                 container == MEDIA_CONTAINER_NONE)
517         {
518                 AppLog("reset- audioCodec is %d, videoCodec is %d, container is %d", audioCodec, videoCodec, container);
519                 //set to default configuration
520                 audioCodec = CODEC_AMR_NB;
521                 videoCodec = CODEC_H263;
522                 container = MEDIA_CONTAINER_3GP;
523         }
524
525         AppLog("maxRecordingTime is %d", maxRecordingTime);
526
527         __maxRecordingTime = (maxRecordingTime / KILOBYTE);
528
529         pRecordingResolutionList = __pVideoRecorder->GetSupportedRecordingResolutionListN();
530         TryCatch(pRecordingResolutionList != null, ShowError(GetLastResult(), METHOD_FILE_LINENO), " __pVideoRecorder->GetSupportedRecordingResolutionListN returned empty");
531
532         pResolution = static_cast< Dimension* >(pRecordingResolutionList->GetAt(0));
533         TryCatch(pResolution != null, ShowError(E_SYSTEM, METHOD_FILE_LINENO),"pRecordingResolutionList->GetAt");
534         AppLog(" RecordingResolution = width(%d) height(%d)", pResolution->width, pResolution->height);
535
536         r = __pVideoRecorder->SetRecordingResolution(*pResolution);
537         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetRecordingResolution", GetErrorMessage(r));
538
539         r = __pVideoRecorder->SetFormat(audioCodec, videoCodec, container);
540         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetFormat", GetErrorMessage(r));
541
542         r = __pVideoRecorder->SetQuality(RECORDING_QUALITY_HIGH);
543         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetQuality", GetErrorMessage(r));
544
545         r = __pVideoRecorder->SetMaxRecordingTime(maxRecordingTime);
546         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->SetMaxRecordingTime", GetErrorMessage(r));
547
548         if (__pProgress)
549         {
550                 __pProgress->SetRange(0, 100); //progress based on recorded %
551         }
552
553         r = __pVideoRecorder->CreateVideoFile(__filePath, true);
554         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->CreateVideoFile", GetErrorMessage(r));
555
556         r = __pVideoRecorder->Record();
557         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO)," [%s] __pVideoRecorder->Record", GetErrorMessage(r));
558
559         pRecordingResolutionList->RemoveAll(true);
560         delete pRecordingResolutionList;
561         return r;
562 CATCH:
563         if (pRecordingResolutionList != null)
564         {
565                 pRecordingResolutionList->RemoveAll(true);
566                 delete pRecordingResolutionList;
567         }
568         return r;
569 }
570
571 result
572 VideoRecorderPlayerForm::StartVideoRecorder()
573 {
574         if (__pVideoRecorder)
575         {
576                 result r = E_SUCCESS;
577                 RecorderState state = __pVideoRecorder->GetState();
578
579                 if ((RECORDER_STATE_INITIALIZED == state) || (RECORDER_STATE_OPENED == state) || \
580                         (RECORDER_STATE_PAUSED == state) || (RECORDER_STATE_CLOSED == state) || \
581                         (RECORDER_STATE_STOPPED == state))
582                 {
583                         AppLog("Start video Recording");
584
585                         r = StartRecording();
586                         TryReturn(r == E_SUCCESS, E_FAILURE," Start Recording failed");
587
588                         AppLog("__pTimer value is %x",__pTimer);
589                         r = __pTimer->Start(TIMER_VALUE);
590                         TryReturn((r == E_SUCCESS && r != E_INVALID_STATE), ShowErrorResult(r, METHOD_FILE_LINENO),"__pTimer->Start");
591                         return r;
592                 }
593
594                 ShowErrorResult(E_INVALID_STATE, METHOD_FILE_LINENO);
595                 return E_INVALID_STATE;
596         }
597
598         AppLog("__pVideoRecorder handle is null");
599         return E_FAILURE;
600 }
601
602 result
603 VideoRecorderPlayerForm::StopVideoRecorder()
604 {
605         result r = E_SUCCESS;
606
607         AppLog("StopRecord called");
608         __pTimer->Cancel();
609
610         r = __pVideoRecorder->Stop();
611         //Once stop is called. close will be called in OnVideoRecorderStopped()
612
613         return r;
614
615 }
616
617 result
618 VideoRecorderPlayerForm::StartPlayer()
619 {
620         result r = E_SUCCESS;
621         r = CreatePlayer();
622         TryReturn(r == E_SUCCESS, r,"[%s] createPlayer failed", GetErrorMessage(r));
623
624         r = __pPlayer->Play();
625         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Play has failed", GetErrorMessage(r));
626
627         return E_SUCCESS;
628 }
629
630 result
631 VideoRecorderPlayerForm::StopPlayer()
632 {
633         if (__pPlayer)
634         {
635                 result r = E_SUCCESS;
636                 PlayerState nowState = __pPlayer->GetState();
637
638                 // Stop playing.
639                 if (nowState == PLAYER_STATE_PLAYING || nowState == PLAYER_STATE_PAUSED)
640                 {
641                         AppLog("Player Stop");
642                         r = __pPlayer->Stop();
643                         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Stop failed", GetErrorMessage(r));
644
645                         r = __pPlayer->Close();
646                         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO),"[%s] Player Close failed", GetErrorMessage(r));
647                 }
648
649                 return r;
650         }
651
652         return E_FAILURE;
653 }
654
655 void
656 VideoRecorderPlayerForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
657 {
658         switch (actionId)
659         {
660         case ID_BUTTON_BACK:
661         {
662                 __pProgress->SetValue(0);
663                 __pProgress->Draw();
664
665                 FreeResources();
666                 Deactivate();
667         }
668         break;
669
670         case ID_BUTTON_START:
671         {
672                 SendUserEvent(START_RECORDING, null);
673                 ShowFooterItem(0, false);
674
675         }
676         break;
677
678         case ID_BUTTON_STOP:
679         {
680                 SendUserEvent(STOP_RECORDING, null);
681                 ShowFooterItem(0, false);
682                 __pProgress->SetValue(0);
683                 __pProgress->Draw();
684         }
685         break;
686
687         case ID_BUTTON_ERROR_POPUP_OK:
688         {
689                 AppLog("Destroy Error Message Popup\n");
690                 MultiForm::ClearErrorPopup();
691                 FreeResources();
692                 Deactivate();
693         }
694         break;
695
696         default:
697                 break;
698         }
699
700         return;
701 }
702
703 void
704 VideoRecorderPlayerForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
705 {
706         result r = E_SUCCESS;
707         AppLog("VideoRecorderPlayerForm::OnUserEventReceivedN : request id = %d", requestId);
708         switch (requestId)
709         {
710         case START_RECORDING:
711         {
712                 r = StartCamera();
713                 TryCatch(r == E_SUCCESS, ,"[%s] StartCamera failed", GetErrorMessage(r));
714
715                 r = StartVideoRecorder();
716                 TryCatch(r == E_SUCCESS, ,"[%s] StartVideoRecorder failed", GetErrorMessage(r));
717
718                 AppLog("Recorder started");
719
720                 r = StartPlayer();
721                 TryCatch(r == E_SUCCESS, ,"[%s] StartPlayer failed", GetErrorMessage(r));
722
723                 AppLog("Player started");
724
725                 SetFooterItem(0, L"Stop", ID_BUTTON_STOP);
726
727         }
728         break;
729
730         case STOP_RECORDING:
731         {
732                 r = StopPlayer();
733                 TryCatch(r == E_SUCCESS, ,"[%s] StopPlayer failed", GetErrorMessage(r));
734
735                 r = StopVideoRecorder();
736                 TryCatch((r == E_SUCCESS || r == E_INVALID_STATE), ,"[%s] StopVideoRecorder failed", GetErrorMessage(r));
737
738                 r = StopCamera();
739                 TryCatch(r == E_SUCCESS, ,"[%s] StopCamera failed", GetErrorMessage(r));
740
741                 SetFooterItem(0, L"Start", ID_BUTTON_START);
742         }
743         break;
744
745         case RECORDER_ON_STOP:
746         {
747                 if (__pVideoRecorder)
748                 {
749                         AppLog("__pVideoRecorder->Close() is called");
750                         __pVideoRecorder->Close();
751                 }
752         }
753         break;
754
755         case RECORDER_ON_CLOSE:
756         {
757                 __pTimer->Cancel();
758
759                 FreeCameraResource();
760                 FreePlayerResource();
761                 ClearErrorPopup();
762
763                 SAFE_DELETE(__pVideoRecorder);
764                 SAFE_DELETE(__pCamera);
765                 SAFE_DELETE(__pPlayer);
766                 SAFE_DELETE(__pCameraOverlay);
767                 SAFE_DELETE(__pPlayerOverlay);
768                 AppLog("Launching the mediaPlayer");
769                 //To complete freeResource activity before launching MediaPlayerForm
770                 LaunchMediaPlayer(false);
771                 __backGroundFlag = true;
772         }
773         break;
774
775         default:
776                 break;
777         }
778
779         return;
780
781 CATCH:
782         AppLog("Error occured %s", GetErrorMessage(r));
783         __cameraErrorFlag = true;
784
785 }
786
787 void
788 VideoRecorderPlayerForm::LaunchMediaPlayer(bool flag)
789 {
790         ArrayList* pArg = null;
791         String* pMediaType;
792         String* pFilePath;
793         Integer* pDeviceOrientation = 0;
794         result r = E_SUCCESS;
795
796         AppLog("MediaPlayerForm's LaunchMediaPlayer invoked file path %ls", __filePath.GetPointer());
797
798         pMediaType = new (std::nothrow) String;
799         TryReturnVoid(pMediaType != null, "pMediaType string is null, no memory");
800         pMediaType->Clear();
801         pMediaType->Append(L"VIDEO");
802
803         pFilePath = new (std::nothrow) String;
804         TryReturnVoid(pFilePath != null, "pFilePath string is null, no memory");
805         pFilePath->Clear();
806         pFilePath->Append(__filePath);
807
808         pDeviceOrientation = new (std::nothrow) Integer(0);
809         TryReturnVoid(pDeviceOrientation != null, "pDeviceOrientation string is null, no memory");
810
811         pArg = new (std::nothrow) ArrayList;
812         TryReturnVoid(pArg != null, "ArrayList creation failed, no memory");
813         r = pArg->Construct();
814         TryReturnVoid(r == E_SUCCESS, "[%s] pArg->Construct()", GetErrorMessage(r));
815
816         pArg->Add(*pMediaType);
817         pArg->Add(*pFilePath);
818         pArg->Add(*pDeviceOrientation);
819
820         SceneManager* pSceneManager = SceneManager::GetInstance();
821         TryReturnVoid(pSceneManager != null, "pSceneManager handle is null");
822
823         pSceneManager->GoForward(ForwardSceneTransition(L"MediaPlayerScene"), pArg);
824 }
825
826
827 void
828 VideoRecorderPlayerForm::GetCameraToForeground(void)
829 {
830         AppLog("GetCameraForeground");
831
832         result r = E_SUCCESS;
833         if (__pCamera != null)
834         {
835                 if (__pCamera->IsPoweredOn() == false)
836                 {
837                         r = __pCamera->PowerOn();
838                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCamera->PowerOn()", GetErrorMessage(r));
839
840                         r = __pCameraOverlay->GetBackgroundBufferInfo(__bufferInfoCamera);
841                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCameraOverlay->GetBackgroundBufferInfo", GetErrorMessage(r));
842
843                         r = __pCamera->StartPreview(&__bufferInfoCamera, false);
844                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] __pCamera->StartPreview", GetErrorMessage(r));
845                 }
846         }
847 }
848
849 void
850 VideoRecorderPlayerForm::GetVideoRecorderToForeground(void)
851 {
852         result r = E_SUCCESS;
853         r = CreateVideoRecorder();
854         TryReturnVoid(r == E_SUCCESS, "[%s] CreateVideoRecorder failed", GetErrorMessage(r));
855 }
856 void
857 VideoRecorderPlayerForm::GetPlayerToForeground(void)
858 {
859         result r = E_SUCCESS;
860         if (__pPlayer != null)
861         {
862                 if (__pPlayer->GetState() == PLAYER_STATE_PAUSED)
863                 {
864                         r = __pPlayer->Play();
865                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] Player->Play failed", GetErrorMessage(r));
866                 }
867                 else if (__pPlayer->GetState() == PLAYER_STATE_CLOSED)
868                 {
869                         StartPlayer();
870                 }
871         }
872 }
873
874 void
875 VideoRecorderPlayerForm::OnForeground(void)
876 {
877
878         AppLog("VideoRecorderPlayerForm::OnForeground");
879         if (__backGroundFlag == true)
880         {
881                 VideoRecorderPlayerForm::Activate(null);
882         }
883
884         __backGroundFlag = false;
885         __cameraErrorFlag = false;
886 }
887
888 void
889 VideoRecorderPlayerForm::PlayerPause()
890 {
891         if (__pPlayer != null)
892         {
893                 result r = E_SUCCESS;
894                 // Pause the playing.
895                 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
896                 {
897                         r = __pPlayer->Pause();
898                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] Player->Pause failed", GetErrorMessage(r));
899                 }
900         }
901 }
902
903 void
904 VideoRecorderPlayerForm::SendVideoRecorderToBackground(void)
905 {
906         if (__pVideoRecorder != null)
907         {
908                 __pVideoRecorder->Cancel();
909                 __pVideoRecorder->Close();
910         }
911 }
912
913 void
914 VideoRecorderPlayerForm::SendCameraToBackground(void)
915 {
916         result r = E_SUCCESS;
917         TryReturnVoid(__pCamera != null, "Camera handle is null");
918
919         if ( __pCamera->GetState() == CAMERA_STATE_PREVIEW)
920         {
921                 r = __pCamera->StopPreview();
922                 if (IsFailed(r))
923                 {
924                         AppLog("OnBackground StopPreview error %s", GetErrorMessage(r));
925                         ShowError(r, METHOD_FILE_LINENO);
926                 }
927
928                 if (__pCamera->IsPoweredOn() == true)
929                 {
930                         r = __pCamera->PowerOff();
931                         TryReturn(r == E_SUCCESS, ShowError(r, METHOD_FILE_LINENO), "[%s] OnBackground PowerOff", GetErrorMessage(r));
932                 }
933         }
934 }
935
936 void
937 VideoRecorderPlayerForm::SendPlayerToBackground(void)
938 {
939         TryReturnVoid(__pPlayer != null, "Player handle is null");
940
941         if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
942         {
943                 PlayerPause();
944         }
945 }
946
947 void
948 VideoRecorderPlayerForm::OnBackground(void)
949 {
950         AppLog("OnBackground Enter");
951
952
953         if (__pTimer != null)
954         {
955                 __pTimer->Cancel();
956         }
957
958         FreeVideoRecorderResource();
959         FreeCameraResource();
960         FreePlayerResource();
961
962         SAFE_DELETE(__pVideoRecorder);
963         SAFE_DELETE(__pCamera);
964         SAFE_DELETE(__pPlayer);
965         SAFE_DELETE(__pCameraOverlay);
966         SAFE_DELETE(__pPlayerOverlay);
967
968         ShowFooterItem(0, true);
969         __pProgress->SetValue(0);
970
971         SetFooterItem(0, L"Start", ID_BUTTON_START);
972
973         __backGroundFlag = true;
974 }
975
976 void
977 VideoRecorderPlayerForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
978 {
979         AppLog("CameraCaptureForm::OnFormBackRequested called");
980
981         __backGroundFlag = true;
982         ShowFooterItem(0, false);
983
984         SetFooterItem(0, L"Start", ID_BUTTON_START);
985
986         FreeResources();
987         MultiForm::ClearErrorPopup();
988         Deactivate();
989
990 }
991
992 void
993 VideoRecorderPlayerForm::FreeVideoRecorderResource(void)
994 {
995         if (__pVideoRecorder != null)
996         {
997                 __pVideoRecorder->Cancel();
998                 __pVideoRecorder->Close();
999         }
1000 }
1001
1002 void
1003 VideoRecorderPlayerForm::FreeCameraResource(void)
1004 {
1005         TryReturnVoid(__pCamera != null, "Camera handle is null");
1006
1007         if (__pCamera->IsPoweredOn() == true)
1008         {
1009                 if (__pCamera->GetState() == CAMERA_STATE_PREVIEW)
1010                         __pCamera->StopPreview();
1011         }
1012
1013         if (__pCamera->IsPoweredOn() == true)
1014         {
1015                 __pCamera->PowerOff();
1016         }
1017 }
1018
1019 void
1020 VideoRecorderPlayerForm::FreePlayerResource(void)
1021 {
1022         StopPlayer();
1023 }
1024
1025 void
1026 VideoRecorderPlayerForm::FreeResources(void)
1027 {
1028         if (__pTimer != null)
1029         {
1030                 __pTimer->Cancel();
1031         }
1032         FreeVideoRecorderResource();
1033         FreeCameraResource();
1034         FreePlayerResource();
1035
1036         SAFE_DELETE(__pVideoRecorder);
1037         SAFE_DELETE(__pCamera);
1038         SAFE_DELETE(__pPlayer);
1039         SAFE_DELETE(__pCameraOverlay);
1040         SAFE_DELETE(__pPlayerOverlay);
1041         SAFE_DELETE(__pTimer);
1042 }
1043
1044 void
1045 VideoRecorderPlayerForm::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
1046 {
1047         AppLog("VideoRecorderPlayerForm::OnTimerExpired");
1048         if (&timer == __pTimer && __pVideoRecorder != null)
1049         {
1050                 long duration = __pVideoRecorder->GetRecordingTime();
1051                 long recordedSize = __pVideoRecorder->GetRecordingSize(); //size is in KB
1052                 if ( (__maxRecordingTime > 0) && (duration > 0) && (recordedSize > 0))
1053                 {
1054                         int currTimePer = (duration) / (__maxRecordingTime * 10);
1055
1056                         AppLog("Recorded Duration = %d current time percentage = %d recorded size = %d", duration, currTimePer, recordedSize);
1057
1058                         __pProgress->SetValue(currTimePer);
1059
1060                         __pProgress->Draw();
1061                         __pProgress->Show();
1062                 }
1063
1064                 timer.Start(TIMER_VALUE);
1065         }
1066 }
1067 void
1068 VideoRecorderPlayerForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
1069 {
1070         if (batteryLevel == BATTERY_CRITICAL || batteryLevel == BATTERY_EMPTY || batteryLevel == BATTERY_LOW)
1071         {
1072                 bool isCharging = false;
1073                 Tizen::System::RuntimeInfo::GetValue(String(L"IsCharging"), isCharging);
1074                 if (isCharging == false)
1075                 {
1076                         FreeResources();
1077                         Deactivate();
1078                 }
1079         }
1080         else
1081         {
1082                 if (__batteryLevelFlag == true)
1083                 {
1084                         Activate(null);
1085                 }
1086         }
1087 }
1088
1089 void
1090 VideoRecorderPlayerForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
1091 {
1092         switch (deviceType)
1093         {
1094         case DEVICE_TYPE_CHARGER:
1095         {
1096                 FreeResources();
1097                 Deactivate();
1098         }
1099         break;
1100         case DEVICE_TYPE_WIRED_HEADSET:
1101                 //fall through
1102         case DEVICE_TYPE_WIRED_HEADPHONE:
1103         {
1104                 __isHeadSetRemoved = true;
1105         }
1106         break;
1107         default:
1108         break;
1109         }
1110 }
1111
1112 result
1113 VideoRecorderPlayerForm::EnableFooterItem(int actionId, bool enable)
1114 {
1115         result r = E_SUCCESS;
1116         Footer* pFooter = GetFooter();
1117         TryReturn(pFooter != null, E_FAILURE, "GetFooter Failed");
1118
1119         pFooter->SetItemEnabled((actionId - ID_BUTTON_START), enable);
1120         pFooter->RequestRedraw();
1121         return r;
1122 }
1123
1124 void
1125 VideoRecorderPlayerForm::ShowError(result r, const char* pMethod, const char* pSrcfileName, int lineNo)
1126 {
1127         AppLog("method %s file name %s  line no. %d", pMethod, pSrcfileName, lineNo);
1128         ShowErrorMessagePopup(SECTION_NAME, L"VideoRecorderPlayerForm", pMethod, r, pSrcfileName, lineNo, GetErrorMessage(r));
1129 }
1130
1131 result
1132 VideoRecorderPlayerForm::ShowErrorResult(result r, const char* pMethod, const char* pSrcfileName, int lineNo)
1133 {
1134         AppLog("method %s file name %s  line no. %d", pMethod, pSrcfileName, lineNo);
1135         ShowErrorMessagePopup(SECTION_NAME, L"VideoRecorderPlayerForm", pMethod, r, pSrcfileName, lineNo, GetErrorMessage(r));
1136         return r;
1137 }
1138
1139 void
1140 VideoRecorderPlayerForm::DeletePopup(Popup** pPopup)
1141 {
1142         if (pPopup != null && *pPopup != null)
1143         {
1144                 (*pPopup)->RemoveAllControls();
1145                 delete (*pPopup);
1146                 *pPopup = null;
1147         }
1148 }
1149
1150 result
1151 VideoRecorderPlayerForm::CreatePopUp(Popup** pPopupCtrl, String title, Dimension dimension, bool hasTitle)
1152 {
1153         result r = E_SUCCESS;
1154         Popup* pCtrl = new (std::nothrow) Popup();
1155         TryReturn(pCtrl != null, E_OUT_OF_MEMORY, "Popup creation Failed");
1156
1157         *pPopupCtrl = pCtrl;
1158         r = pCtrl->Construct(hasTitle, dimension);
1159         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup Construct Failed", GetErrorMessage(r));
1160
1161         if (hasTitle == true)
1162         {
1163                 r = pCtrl->SetTitleText(String(title));
1164                 TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup SetTitleText Failed", GetErrorMessage(r));
1165         }
1166
1167         return r;
1168 }
1169
1170 result
1171 VideoRecorderPlayerForm::ShowPopUp(Popup* pPopUp)
1172 {
1173         result r = E_SUCCESS;
1174
1175         TryReturn(pPopUp != null, E_FAILURE, "Popup handle is null");
1176
1177         r = pPopUp->SetShowState(true);
1178         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup SetShowState", GetErrorMessage(r));
1179
1180         r = pPopUp->Show();
1181         TryReturn(r == E_SUCCESS, ShowErrorResult(r, METHOD_FILE_LINENO), "[%s] Popup show", GetErrorMessage(r));
1182
1183         return r;
1184 }
1185
1186
1187 void
1188 VideoRecorderPlayerForm::HidePopUp(Popup* pPopUp)
1189 {
1190         TryReturnVoid(pPopUp != null, "Popup handle is null");
1191
1192         pPopUp->SetShowState(false);
1193         Draw();
1194         return;
1195 }
1196
1197 result
1198 VideoRecorderPlayerForm::OnTerminating(void)
1199 {
1200         AppLog("OnTerminating");
1201         return E_SUCCESS;
1202 }
1203
1204 void
1205 VideoRecorderPlayerForm::OnCameraAutoFocused(bool completeCondition)
1206 {
1207
1208 }
1209
1210 void
1211 VideoRecorderPlayerForm::OnCameraCaptured(Tizen::Base::ByteBuffer& capturedData, result r)
1212 {
1213
1214 }
1215
1216 void
1217 VideoRecorderPlayerForm::OnCameraErrorOccurred(CameraErrorReason r)
1218 {
1219         AppLog("OnCameraErrorOccurred");
1220         __cameraErrorFlag = true;
1221 }
1222
1223 void
1224 VideoRecorderPlayerForm::OnCameraPreviewed(Tizen::Base::ByteBuffer& previewedData, result r)
1225 {
1226
1227 }
1228
1229 void
1230 VideoRecorderPlayerForm::OnPlayerOpened(result r)
1231 {
1232
1233 }
1234
1235 void
1236 VideoRecorderPlayerForm::OnPlayerEndOfClip(void)
1237 {
1238
1239 }
1240
1241 void
1242 VideoRecorderPlayerForm::OnPlayerBuffering(int percent)
1243 {
1244
1245 }
1246
1247 void
1248 VideoRecorderPlayerForm::OnPlayerErrorOccurred(Tizen::Media::PlayerErrorReason r)
1249 {
1250
1251 }
1252 void
1253 VideoRecorderPlayerForm::OnPlayerInterrupted(void)
1254 {
1255
1256 }
1257
1258 void
1259 VideoRecorderPlayerForm::OnPlayerReleased(void)
1260 {
1261
1262 }
1263
1264 void
1265 VideoRecorderPlayerForm::OnPlayerSeekCompleted(result r)
1266 {
1267
1268 }
1269
1270 void
1271 VideoRecorderPlayerForm::OnPlayerAudioFocusChanged(void)
1272 {
1273         AppLog("[rr]OnPlayerAudioFocusChanged");
1274         TryReturnVoid(__pPlayer != null, "Player handle is null");
1275         if ( __isHeadSetRemoved == true && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1276         {
1277                 AppLog("[rr]__isHeadSetRemoved is true");
1278                 result r = E_SUCCESS;
1279                 r = __pPlayer->Play();
1280                 TryReturnVoid(r == E_SUCCESS, "[%s] Player Play has failed", GetErrorMessage(r));
1281                 __isHeadSetRemoved = false;
1282         }
1283 }
1284
1285 void
1286 VideoRecorderPlayerForm::OnVideoRecorderCanceled(result r)
1287 {
1288         AppLog("OnVideoRecorderCanceled");
1289         __pTimer->Cancel();
1290 }
1291
1292 void
1293 VideoRecorderPlayerForm::OnVideoRecorderClosed(result r)
1294 {
1295         AppLog("OnVideoRecorderClosed __backGroundFlag is %d,__cameraErrorFlag is %d ",__backGroundFlag,__cameraErrorFlag);
1296
1297         if (!__backGroundFlag && __cameraErrorFlag == false)
1298         {
1299                 SendUserEvent(RECORDER_ON_CLOSE, null);
1300                 ShowFooterItem(0, true);
1301         }
1302         else
1303         {
1304                 FreeResources();
1305                 VideoRecorderPlayerForm::Activate(null);
1306                 AppLog("Could not launch the mediaplayer");
1307         }
1308 }
1309
1310 void
1311 VideoRecorderPlayerForm::OnVideoRecorderEndReached(Tizen::Media::RecordingEndCondition endCondition)
1312 {
1313         AppLog("OnVideoRecorderEndReached");
1314         __pVideoRecorder->Close();
1315         __pTimer->Cancel();
1316
1317         __pProgress->SetValue(100);
1318         __pProgress->Draw();
1319         __pProgress->Show();
1320
1321         SetFooterItem(0, L"Start", ID_BUTTON_START);
1322 }
1323
1324 result
1325 VideoRecorderPlayerForm::ConvertRecorderErrorToError(Tizen::Media::RecorderErrorReason r)
1326 {
1327         result res = E_SUCCESS;
1328         switch (r)
1329         {
1330                 case RECORDER_ERROR_OUT_OF_STORAGE:
1331                         //fall through
1332                 case RECORDER_ERROR_STORAGE_FAILED:
1333                         res = E_STORAGE_FULL;
1334                         break;
1335                 default:
1336                         break;
1337         }
1338
1339         return res;
1340 }
1341
1342 void
1343 VideoRecorderPlayerForm::OnVideoRecorderErrorOccurred(Tizen::Media::RecorderErrorReason r)
1344 {
1345         AppLog("OnVideoRecorderErrorOccurred");
1346
1347         result res = E_SUCCESS;
1348
1349         res = ConvertRecorderErrorToError(r);
1350         if (res != E_SUCCESS)
1351         {
1352                 __pCamera->StopPreview();
1353                 ShowErrorResult(res, METHOD_FILE_LINENO);
1354                 return;
1355         }
1356         else
1357         {
1358                 __pVideoRecorder->Close();
1359                 __pTimer->Cancel();
1360         }
1361
1362         return;
1363 }
1364
1365 void
1366 VideoRecorderPlayerForm::OnVideoRecorderPaused(result r)
1367 {
1368         AppLog("OnVideoRecorderPaused");
1369 }
1370
1371 void
1372 VideoRecorderPlayerForm::OnVideoRecorderStarted(result r)
1373 {
1374         AppLog("OnVideoRecorderStarted");
1375         ShowFooterItem(0, true);
1376 }
1377
1378 void
1379 VideoRecorderPlayerForm::OnVideoRecorderStopped(result r)
1380 {
1381         AppLog("OnVideoRecorderStopped");
1382         __pVideoRecorder->Close();
1383 }