Fixed jira issues:N_SE-46569,N_SE-46541, N_SE-46483 etc
[apps/osp/MusicPlayer.git] / src / MpMusicPlayerPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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                MpMusicPlayerPresentationModel.cpp
19  * @brief               This is the implementation file for MusicPlayerPresentationModel class.
20  */
21
22 #include <time.h>
23 #include <FBase.h>
24 #include <FGraphics.h>
25 #include <FIo.h>
26 #include <FSystem.h>
27 #include <FUi.h>
28 #include "MpCommonUtil.h"
29 #include "MpIMusicPlayerEventListener.h"
30 #include "MpMusicPlayerPresentationModel.h"
31 #include "MpPlaylistDB.h"
32 #include "MpResourceManager.h"
33 #include "MpTypes.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Content;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Io;
43 using namespace Tizen::Media;
44 using namespace Tizen::System;
45 using namespace Tizen::Telephony;
46 using namespace Tizen::Ui::Controls;
47
48 #define BUFFER_INFO_OF_PLAYER   0
49
50 static const int PROGRESS_TIMER_DURATION = 150;
51 static const int PROGRESS_BAR_DURATION_TIMER = 1000;
52 static const int MIN_SLIDER_COUNT = 0;
53 static const int MAX_SLIDER_COUNT = 100;
54 static const int INIT_X_VALUE = 0;
55 static const int INIT_CONTENT_INDEX = -1;
56 static const int VOLUMEBAR_INTERVAL = 3000;
57 static const int PAUSE_AUTO_OFF_TIME = 1000 * 60 * 2;
58
59 PlayerPresentationModel* PlayerPresentationModel::pPlayerPresentationModel = null;
60
61 PlayerPresentationModel*
62 PlayerPresentationModel::GetInstance(void)
63 {
64         AppLogDebug("ENTER");
65         if (pPlayerPresentationModel == null)
66         {
67                 pPlayerPresentationModel = new (std::nothrow) PlayerPresentationModel();
68                 TryReturn(pPlayerPresentationModel != null, null, "PlayerPresentationModel instance is not created.");
69
70                 result r = pPlayerPresentationModel->Construct();
71                 TryCatch(r == E_SUCCESS, , null, "PlayerPresentationModel instance is not constructed.");
72         }
73         AppLogDebug("EXIT");
74         return pPlayerPresentationModel;
75
76 CATCH:
77         if (pPlayerPresentationModel != null)
78         {
79                 delete pPlayerPresentationModel;
80         }
81
82         return null;
83 }
84
85 PlayerPresentationModel::PlayerPresentationModel(void)
86         : __pPlayer(null)
87         , __pPlayStateTimer(null)
88         , __pFastForwardTimer(null)
89         , __pFastRewindTimer(null)
90         , __pAutoOffTimer(null)
91         , __pPauseAutoOffTimer(null)
92         , __pVolumeBarStateTimer(null)
93         , __pPlayContentList(null)
94         , __previousContentIndex(INIT_CONTENT_INDEX)
95         , __currentContentIndex(INIT_CONTENT_INDEX)
96         , __nextContentIndex(INIT_CONTENT_INDEX)
97         , __removedContentIndex(INIT_CONTENT_INDEX)
98         , __pCurrentPlayContentPath(null)
99         , __pCurrentPlayContentTitle(null)
100         , __pCurrentPlayContentThumbnail(null)
101         , __pCurrentPlayContentArtist(null)
102         , __pUuIdForFileOnly(null)
103         , __pCurrentAudioContentInfo(null)
104         , __currentPlayContentDuration(null)
105         , __repeatMode(null)
106         , __shuffleEnable(false)
107         , __seekCompleted(true)
108         , __isForceChanged(false)
109         , __playposition(MIN_SLIDER_COUNT)
110         , __previousPlayerState(PLAYER_STATE_ERROR)
111         , __xTimesValue(INIT_X_VALUE)
112         , __currentContentTotalDuration(0)
113         , __pCallManager(null)
114 {
115         AppLogDebug("ENTER");
116         AppLogDebug("EXIT");
117 }
118
119 PlayerPresentationModel::~PlayerPresentationModel(void)
120 {
121         AppLogDebug("ENTER");
122         result r = E_SUCCESS;
123
124         if (__repeatMode != CommonUtil::GetValue(REPEAT_MODE))
125         {
126                 CommonUtil::SetValue(REPEAT_MODE, __repeatMode);
127         }
128         if (__shuffleEnable != static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE)))
129         {
130                 CommonUtil::SetValue(SHUFFLE_MODE, static_cast<int>(__shuffleEnable));
131         }
132         if (__pPlayContentList != null)
133         {
134                 __pPlayContentList->RemoveAll(true);
135                 delete __pPlayContentList;
136                 __pPlayContentList = null;
137         }
138         if (__pPlayStateTimer != null)
139         {
140                 __pPlayStateTimer->Cancel();
141                 delete __pPlayStateTimer;
142                 __pPlayStateTimer = null;
143         }
144         if (__pFastForwardTimer != null)
145         {
146                 __pFastForwardTimer->Cancel();
147                 delete __pFastForwardTimer;
148                 __pFastForwardTimer = null;
149         }
150         if (__pFastRewindTimer != null)
151         {
152                 __pFastRewindTimer->Cancel();
153                 delete __pFastRewindTimer;
154                 __pFastRewindTimer = null;
155         }
156         if (__pAutoOffTimer != null)
157         {
158                 __pAutoOffTimer->Cancel();
159                 delete __pAutoOffTimer;
160                 __pAutoOffTimer = null;
161         }
162         if (__pPauseAutoOffTimer != null)
163         {
164                 __pPauseAutoOffTimer->Cancel();
165                 delete __pPauseAutoOffTimer;
166                 __pPauseAutoOffTimer = null;
167         }
168         if (__pVolumeBarStateTimer != null)
169         {
170                 __pVolumeBarStateTimer->Cancel();
171                 delete __pVolumeBarStateTimer;
172         }
173
174         delete __pCurrentPlayContentPath;
175         delete __pCurrentPlayContentTitle;
176         delete __pCurrentPlayContentThumbnail;
177         delete __pCurrentPlayContentArtist;
178         delete __pUuIdForFileOnly;
179         delete __pCurrentAudioContentInfo;
180
181         if (__pCallManager != null)
182         {
183                 delete __pCallManager;
184         }
185
186         if (__pPlayer == null)
187         {
188                 AppLogDebug("EXIT");
189                         return;
190         }
191         if (__pPlayer != null)
192         {
193                 PlayerState state = __pPlayer->GetState();
194                 switch (state)
195                 {
196                 case PLAYER_STATE_PLAYING:
197                         // fall through
198                 case PLAYER_STATE_PAUSED:
199                         {
200                                 r = __pPlayer->Stop();
201                                 TryLog(r == E_SUCCESS, "[%s] Failed Stop",GetErrorMessage(r));
202                                 r = __pPlayer->Close();
203                                 TryLog(r == E_SUCCESS, "[%s] Failed Close",GetErrorMessage(r));
204                         }
205                         break;
206
207                 case PLAYER_STATE_ENDOFCLIP:
208                         // fall through
209                 case PLAYER_STATE_OPENED:
210                         // fall through                 
211                 case PLAYER_STATE_STOPPED:
212                         {
213                                 r = __pPlayer->Close();
214                                 TryLog(r == E_SUCCESS, "[%s] Failed Close",GetErrorMessage(r));
215                         }
216                         break;
217
218                 case PLAYER_STATE_CLOSED:
219                         {
220                         }
221                         break;
222
223                 default:
224                         break;
225                 }
226                 delete __pPlayer;
227                 __pPlayer = null;
228         }
229         AppLogDebug("EXIT");
230 }
231
232 void
233 PlayerPresentationModel::DestroyPlayerPresentationModel(void)
234 {
235         AppLogDebug("ENTER");
236         if (pPlayerPresentationModel != null)
237         {
238                 CallOnPlayPresentationModelDestroying();
239
240                 delete pPlayerPresentationModel;
241                 pPlayerPresentationModel = null;
242         }
243         AppLogDebug("EXIT");
244 }
245
246 void
247 PlayerPresentationModel::OnTelephonyCallStatusChangedN(Tizen::Telephony::CallStatus callStatus, Tizen::Telephony::CallInfo* pCallInfo)
248 {
249         AppLogDebug("ENTER");
250         AppLogDebug("callStatus : %d", callStatus);
251         if (callStatus == CALL_STATUS_IDLE || callStatus == CALL_STATUS_COMMUNICATING)
252         {
253                 CallOnPlayContentChanged(__currentContentIndex);
254         }
255         AppLogDebug("EXIT");
256 }
257
258 result
259 PlayerPresentationModel::Construct(void)
260 {
261         AppLogDebug("ENTER");
262         result r = E_SUCCESS;
263
264         /*AudioSessionManager::GetInstance()->SetAudioSessionEventListener(this);
265         AudioSessionManager::GetInstance()->SetMode(AUDIO_SESSION_MODE_EXCLUSIVE);*/
266
267         __pPlayStateTimer = new (std::nothrow) Timer();
268         r = __pPlayStateTimer->Construct(*this);
269         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Timer.\n");
270
271         __pFastForwardTimer = new (std::nothrow) Timer();
272         r = __pFastForwardTimer->Construct(*this) ;
273         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct FastForwardTimer.\n");
274
275         __pFastRewindTimer = new (std::nothrow) Timer();
276         r = __pFastRewindTimer->Construct(*this) ;
277         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct FastRewindTimer.\n");
278
279         __pAutoOffTimer = new (std::nothrow) Timer();
280         r = __pAutoOffTimer->Construct(*this);
281         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct __pAutoOffTimer.\n");
282
283         __pPauseAutoOffTimer = new (std::nothrow) Timer();
284         r = __pPauseAutoOffTimer->Construct(*this);
285         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct __pPauseAutoOffTimer.\n");
286
287         __pVolumeBarStateTimer = new (std::nothrow) Timer();
288         r = __pVolumeBarStateTimer->Construct(*this);
289         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Timer.\n");
290
291         __pCurrentPlayContentPath = new (std::nothrow) String(L"");
292
293         __repeatMode = CommonUtil::GetValue(REPEAT_MODE);
294         __shuffleEnable = static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE));
295
296         __pCallManager = new (std::nothrow) CallManager();
297         __pCallManager->Construct(*this);
298
299         __pUuIdForFileOnly = Tizen::Base::UuId::GenerateN();
300
301         InitializePlayer();
302
303         AppLogDebug("EXIT");
304         return r;
305
306 CATCH:
307         //AppLogException( "[%s]", GetErrorMessage(r));
308         if (__pPlayStateTimer != null)
309         {
310                 __pPlayStateTimer->Cancel();
311                 delete __pPlayStateTimer;
312                 __pPlayStateTimer = null;
313         }
314         if (__pFastForwardTimer != null)
315         {
316                 __pFastForwardTimer->Cancel();
317                 delete __pFastForwardTimer;
318                 __pFastForwardTimer = null;
319         }
320         if (__pFastRewindTimer != null)
321         {
322                 __pFastRewindTimer->Cancel();
323                 delete __pFastRewindTimer;
324                 __pFastRewindTimer = null;
325         }
326         if (__pAutoOffTimer != null)
327         {
328                 __pAutoOffTimer->Cancel();
329                 delete __pAutoOffTimer;
330                 __pAutoOffTimer = null;
331         }
332         if (__pPauseAutoOffTimer != null)
333         {
334                 __pPauseAutoOffTimer->Cancel();
335                 delete __pPauseAutoOffTimer;
336                 __pPauseAutoOffTimer = null;
337         }
338         if (__pVolumeBarStateTimer != null)
339         {
340         __pVolumeBarStateTimer->Cancel();
341                 delete __pVolumeBarStateTimer;
342         }
343         return r;
344 }
345
346 result
347 PlayerPresentationModel::InitializePlayer(void)
348 {
349         AppLogDebug("ENTER");
350         result r = E_SUCCESS;
351
352         if (__pPlayer != null)
353         {
354                 delete __pPlayer;
355                 __pPlayer = null;
356         }
357
358         __pPlayer = new (std::nothrow) Player();
359         r = __pPlayer->Construct(*this, BUFFER_INFO_OF_PLAYER);
360         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Player.\n");
361
362         AppLogDebug("EXIT");
363         return r;
364
365 CATCH:
366         delete __pPlayer;
367         __pPlayer = null;
368
369         return r;
370 }
371
372 result
373 PlayerPresentationModel::StartAutoOffTimer(int autoOffValue)
374 {
375         AppLogDebug("ENTER");
376         result r = E_SUCCESS;
377         if (__pAutoOffTimer != null)
378         {
379                 if (autoOffValue == 0)
380                 {
381                         r = __pAutoOffTimer->Cancel();
382                         AppLogDebug("%s", GetErrorMessage(r));
383                 }
384                 else
385                 {
386                         __pAutoOffTimer->Cancel();
387                         r = __pAutoOffTimer->Start(autoOffValue);
388                         AppLogDebug("%s", GetErrorMessage(r));
389                         TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Start __pAutoOffTimer.\n");
390                 }
391                 AppLogDebug("EXIT");
392                 return r;
393         }
394         AppLogDebug("EXIT");
395         return r;
396
397 CATCH:
398         //AppLogException( "[%s]", GetErrorMessage(r));
399         return r;
400 }
401
402 void
403 PlayerPresentationModel::RemoveContent(const Tizen::Base::String& filePath)
404 {
405         AppLogDebug("ENTER");
406         TryReturnVoid(__pPlayContentList != null, "There is not a playlist");
407         IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
408         String* pFilePath = null;
409         int index = 0;
410
411         while (pEnum->MoveNext() == E_SUCCESS)
412         {
413                 pFilePath = static_cast<String*>(pEnum->GetCurrent());
414
415                 if (pFilePath->Equals(filePath))
416                 {
417                         __pPlayContentList->Remove(filePath);
418
419                         if (index < __currentContentIndex)
420                         {
421                                 __currentContentIndex--;
422                         }
423                         else if (index == __currentContentIndex)
424                         {
425                                 if (index == __pPlayContentList->GetCount())
426                                 {
427                                         __currentContentIndex--;
428                                 }
429                                 __removedContentIndex = index;
430                         }
431
432                         GenerateNextIndex();
433                         if (__pPlayContentList->GetCount() > 0)
434                         {
435                                 CallOnPlayContentRemoved(index);
436                         }
437                         break;
438                 }
439                 index++;
440         }
441         delete pEnum;
442         AppLogDebug("EXIT");
443         return;
444 }
445
446 PlayerState
447 PlayerPresentationModel::GetPlayerState(void)
448 {
449         AppLogDebug("ENTER");
450         if (__pPlayer == null)
451         {
452                 AppLogDebug("EXIT");
453                 return PLAYER_STATE_ERROR;
454         }
455         AppLogDebug("EXIT");
456         return __pPlayer->GetState();
457 }
458
459 bool
460 PlayerPresentationModel::IsDuringCall(void)
461 {
462         AppLogDebug("ENTER");
463         CallStatus callStatus = CALL_STATUS_UNDEFINED;
464         callStatus = __pCallManager->GetCurrentCallStatus();
465         AppLogDebug("callStatus = %d", callStatus);
466
467         if (callStatus == CALL_STATUS_IDLE)
468         {
469                 AppLogDebug("EXIT");
470                 return false;
471         }
472         else
473         {
474                 AppLogDebug("EXIT");
475                 return true;
476         }
477 }
478
479 void
480 PlayerPresentationModel::ClosePlayer(void)
481 {
482         AppLogDebug("ENTER");
483         result r = E_SUCCESS;
484
485         if (__pPlayer == null)
486         {
487                 AppLogDebug("EXIT");
488                 return;
489         }
490
491         __previousPlayerState = __pPlayer->GetState();
492
493         switch (__previousPlayerState)
494         {
495         case PLAYER_STATE_PLAYING:
496                 // fall through
497         case PLAYER_STATE_PAUSED:
498                 {
499                         r = __pPlayer->Stop();
500                         TryLog(r == E_SUCCESS, "[%s] Failed Stop", GetErrorMessage(r));
501                         r = __pPlayer->Close();
502                         TryLog(r == E_SUCCESS, "[%s] Failed Close", GetErrorMessage(r));
503                 }
504                 break;
505
506         case PLAYER_STATE_OPENED:
507                 // fall through
508         case PLAYER_STATE_STOPPED:
509                 {
510                         r = __pPlayer->Close();
511                         TryLog(r == E_SUCCESS, "[%s] Failed Close", GetErrorMessage(r));
512                 }
513                 break;
514
515         case PLAYER_STATE_CLOSED:
516                 {
517                 }
518                 break;
519
520         case PLAYER_STATE_ENDOFCLIP:
521                 {
522                 }
523                 break;
524
525         default:
526                 break;
527         }
528         AppLogDebug("EXIT");
529 }
530
531 Tizen::Base::String*
532 PlayerPresentationModel::GetPlayContentPath(void)
533 {
534         AppLogDebug("ENTER");
535         AppLogDebug("EXIT");
536         return __pCurrentPlayContentPath;
537 }
538
539 Tizen::Base::String*
540 PlayerPresentationModel::GetPlayContentTitle(void)
541 {
542         AppLogDebug("ENTER");
543         AppLogDebug("EXIT");
544         return __pCurrentPlayContentTitle;
545 }
546
547 Tizen::Base::String*
548 PlayerPresentationModel::GetPlayContentArtist(void)
549 {
550         AppLogDebug("ENTER");
551         AppLogDebug("EXIT");
552         return __pCurrentPlayContentArtist;
553 }
554
555 Tizen::Graphics::Bitmap*
556 PlayerPresentationModel::GetPlayContentThumbnail(void)
557 {
558         AppLogDebug("ENTER");
559         AppLogDebug("EXIT");
560         return __pCurrentPlayContentThumbnail;
561 }
562
563 long
564 PlayerPresentationModel::GetPlayContentDuration(void)
565 {
566         AppLogDebug("ENTER");
567         AppLogDebug("EXIT");
568         return __currentPlayContentDuration;
569 }
570
571 Tizen::Base::String*
572 PlayerPresentationModel::GetContentPath(int contentIndex)const
573 {
574         AppLogDebug("ENTER");
575         String* pFilePath = null;
576
577         TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), null, "contentIndex is invalid.");
578         pFilePath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
579
580         AppLogDebug("EXIT");
581         return pFilePath;
582 }
583
584 int
585 PlayerPresentationModel::GetPreviousContentIndex(void) const
586 {
587         AppLogDebug("ENTER");
588         AppLogDebug("EXIT");
589         return __previousContentIndex;
590 }
591
592 int
593 PlayerPresentationModel::GetCurrentContentIndex(void) const
594 {
595         AppLogDebug("ENTER");
596         AppLogDebug("EXIT");
597         return __currentContentIndex;
598 }
599
600 int
601 PlayerPresentationModel::GetNextContentIndex(void) const
602 {
603         AppLogDebug("ENTER");
604         AppLogDebug("EXIT");
605         return __nextContentIndex;
606 }
607
608 ContentInformation*
609 PlayerPresentationModel::GetContentInfoN(int contentIndex)
610 {
611         AppLogDebug("ENTER");
612         AudioContentInfo* pAudioContentInfo = null;
613
614         if (__pPlayContentList == null || contentIndex < INIT_VALUE)
615         {
616                 AppLogDebug("EXIT(index(%d) MUST be greater than or equal to 0 OR __pPlayContentList is null)", contentIndex);
617                 return null;
618         }
619
620         ContentInformation* pContentInfo = new (std::nothrow) ContentInformation();
621         TryReturn(pContentInfo != null, null, "pContentInfo is null.");
622
623         if ( __pCurrentAudioContentInfo != null && contentIndex == __currentContentIndex)
624         {
625                 pAudioContentInfo = __pCurrentAudioContentInfo;
626         }
627         else
628         {
629                 Tizen::Base::String* contentPath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
630                 if (contentPath == null || File::IsFileExist(*contentPath) == false)
631                 {
632                         AppLogDebug("EXIT");
633                         return null;
634                 }
635
636                 pAudioContentInfo = CommonUtil::GetAudioContentInfoN(*contentPath);
637         }
638
639         if (pAudioContentInfo != null)
640         {
641                 if (pAudioContentInfo->GetArtist() == null)
642                 {
643                         pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
644                 }
645                 else
646                 {
647                         pContentInfo->ArtistName = pAudioContentInfo->GetArtist();
648                 }
649
650                 if (pAudioContentInfo->GetTitle() == null)
651                 {
652                         pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
653                 }
654                 else
655                 {
656                         pContentInfo->TitleName = pAudioContentInfo->GetTitle();
657                 }
658
659                 if (__pPlayer != null)
660                 {
661                         pContentInfo->Duration  = __pPlayer->GetDuration();
662                 }
663                 else
664                 {
665                         pContentInfo->Duration  = pAudioContentInfo->GetDuration();
666                 }
667                 pContentInfo->contentId = pAudioContentInfo->GetContentId();
668
669                 if (pAudioContentInfo != __pCurrentAudioContentInfo)
670                 {
671                         delete pAudioContentInfo;
672                 }
673         }
674         else
675         {
676                 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
677                 if (pAudioMeta == null)
678                 {
679                         delete pContentInfo;
680                         return null;
681                 }
682
683                 if (pAudioMeta->GetArtist() == null)
684                 {
685                         pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
686                 }
687                 else
688                 {
689                         pContentInfo->ArtistName = pAudioMeta->GetArtist();
690                 }
691
692                 if (pAudioMeta->GetTitle() == null)
693                 {
694                         pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
695                 }
696                 else
697                 {
698                         pContentInfo->TitleName = pAudioMeta->GetTitle();
699                 }
700
701                 if (__pPlayer != null)
702                 {
703                         pContentInfo->Duration = __pPlayer->GetDuration();
704                 }
705                 pContentInfo->contentId = *__pUuIdForFileOnly;
706                 delete pAudioMeta;
707         }
708
709         AppLogDebug("EXIT");
710         return pContentInfo;
711 }
712
713 Tizen::Graphics::Bitmap*
714 PlayerPresentationModel::GetContentAlbumArtN(int contentIndex)
715 {
716         AppLogDebug("ENTER");
717         Bitmap* pAlbumArtBitmap = null;
718         if (contentIndex <= -1)
719         {
720                 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
721                 AppLogDebug("EXIT");
722                 return pAlbumArtBitmap;
723         }
724
725         String* path = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
726         if (path == null)
727         {
728                 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
729                 AppLogDebug("EXIT");
730                 return pAlbumArtBitmap;
731         }
732
733         pAlbumArtBitmap = CommonUtil::GetContentAlbumArtN(*path);
734         if (pAlbumArtBitmap == null)
735         {
736                 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
737         }
738         AppLogDebug("EXIT");
739         return pAlbumArtBitmap;
740 }
741
742 result
743 PlayerPresentationModel::Play(int contentIndex, int sliderPosition, bool bPausePlay, bool bPlayPause)
744 {
745         AppLogDebug("ENTER");
746         result r = E_SUCCESS;
747
748         if (__pPlayer == null)
749         {
750                 AppLogDebug("EXIT");
751                 return E_FAILURE;
752         }
753
754         __seekCompleted = true;
755 /*      if (__seekCompleted == false)
756         {
757                 AppLogDebug("EXIT");
758                 return E_FAILURE;
759         }
760 */
761         if (GetContentListCount() == 0)
762         {
763                 ClosePlayer();
764                 InitializeProgress();
765         }
766
767         PlayerState playerState;
768         String currentDuration = null;
769         String* pPath = null;
770
771         if (bPausePlay == false)
772         {
773                 TryCatch(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), , "contentIndex is invalid");
774                 pPath = GetContentPath(contentIndex);
775                 AppLogDebug("__pCurrentPlayContentPath = %ls", __pCurrentPlayContentPath->GetPointer());
776                 if (__pPlayer->GetState() == PLAYER_STATE_ENDOFCLIP
777                         || pPath->Equals(*__pCurrentPlayContentPath) == false || __currentContentIndex != contentIndex || __isForceChanged)
778                 {
779                         __isForceChanged = false;
780                         ClosePlayer();
781                         InitializeProgress();
782                         InitializePlayer();
783                         __previousPlayerState = PLAYER_STATE_INITIALIZED;
784                         __currentContentIndex = contentIndex;
785                         GenerateNextIndex();
786                         __pCurrentPlayContentPath->Clear();
787                         __pCurrentPlayContentPath->Append(pPath->GetPointer());
788
789                         if (__pCurrentAudioContentInfo != null)
790                         {
791                                 delete __pCurrentAudioContentInfo;
792                                 __pCurrentAudioContentInfo = null;
793                         }
794
795                         __pCurrentAudioContentInfo = CommonUtil::GetAudioContentInfoN(*(__pCurrentPlayContentPath));
796
797                         if (__pCurrentAudioContentInfo != null)
798                         {
799                                 if (__pCurrentPlayContentTitle != null)
800                                 {
801                                         delete __pCurrentPlayContentTitle;
802                                 }
803                                 if(__pCurrentPlayContentThumbnail != null)
804                                 {
805                                         delete __pCurrentPlayContentThumbnail;
806                                 }
807
808                                 __pCurrentPlayContentTitle = new (std::nothrow) String(__pCurrentAudioContentInfo->GetTitle());
809                                 __pCurrentPlayContentThumbnail = __pCurrentAudioContentInfo->GetThumbnailN();
810                                 if (__pCurrentPlayContentThumbnail == null)
811                                 {
812                                         __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
813                                 }
814
815                                 if (__pCurrentPlayContentArtist != null)
816                                 {
817                                         delete __pCurrentPlayContentArtist;
818                                 }
819                                 __pCurrentPlayContentArtist = new (std::nothrow) String(__pCurrentAudioContentInfo->GetArtist());
820                                 __currentPlayContentDuration = __pCurrentAudioContentInfo->GetDuration();
821                                 if (__currentPlayContentDuration == null)
822                                 {
823                                         __currentPlayContentDuration = __pPlayer->GetDuration();
824                                 }
825                         }
826                         else
827                         {
828                                 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
829                                 if (__pCurrentPlayContentTitle != null)
830                                 {
831                                         delete __pCurrentPlayContentTitle;
832                                 }
833                                 if (__pCurrentPlayContentArtist != null)
834                                 {
835                                         delete __pCurrentPlayContentArtist;
836                                 }
837
838                                 if (pAudioMeta == null)
839                                 {
840                                         __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
841                                         __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
842                                         __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
843                                         __currentPlayContentDuration = __pPlayer->GetDuration();
844                                 }
845                                 else
846                                 {
847                                         __pCurrentPlayContentTitle = new (std::nothrow) String(pAudioMeta->GetTitle());
848                                         if (__pCurrentPlayContentTitle == null)
849                                         {
850                                                 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
851                                         }
852
853                                         __pCurrentPlayContentArtist = new (std::nothrow) String(pAudioMeta->GetArtist());
854                                         if (__pCurrentPlayContentArtist == null)
855                                         {
856                                                 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
857                                         }
858
859                                         __pCurrentPlayContentThumbnail = pAudioMeta->GetThumbnailN();
860                                         if (__pCurrentPlayContentThumbnail == null)
861                                         {
862                                                 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
863                                         }
864
865                                         __currentPlayContentDuration = pAudioMeta->GetDuration();
866                                         if (__currentPlayContentDuration == null)
867                                         {
868                                                 __currentPlayContentDuration = __pPlayer->GetDuration();
869                                         }
870
871                                         delete pAudioMeta;
872                                 }
873                         }
874                 }
875                 else
876                 {
877                 /*      IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
878                         String* pFilePath = null;
879                         int index = 0;
880
881                         if(pEnum != null)
882                         {
883                                 while (pEnum->MoveNext() == E_SUCCESS)
884                                 {
885                                         pFilePath = static_cast<String*>(pEnum->GetCurrent());
886
887                                         if (pFilePath->Equals(*__pCurrentPlayContentPath))
888                                         {
889                                                 __currentContentIndex = index;
890                                                 GenerateNextIndex();
891                                                 break;
892                                         }
893                                         index++;
894                                 }
895
896                                 delete pEnum;
897                         }*/
898                         if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
899                         {
900                                 CallOnPlayContentChanged(__currentContentIndex);
901                                 return E_SUCCESS;
902                         }
903                 }
904         }
905
906         playerState = __pPlayer->GetState();
907
908         switch (playerState)
909         {
910         case PLAYER_STATE_PLAYING:
911                 {
912                         CallOnPlayContentChanged(__currentContentIndex);
913                 }
914                 break;
915
916         case PLAYER_STATE_STOPPED:
917                 // fall through
918         case PLAYER_STATE_OPENED:
919                 // fall through
920         case PLAYER_STATE_PAUSED:
921                 // fall through
922         case PLAYER_STATE_ENDOFCLIP:
923                 {
924                         if (__pPauseAutoOffTimer != null)
925                         {
926                                 r = __pPauseAutoOffTimer->Cancel();
927                                 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
928                         }
929                         if (__pPlayStateTimer != null)
930                         {
931                                 __pPlayStateTimer->Cancel();
932                                 if (__pPlayer->GetDuration() < PROGRESS_BAR_DURATION_TIMER)
933                                 {
934                                         r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER/10);
935                                 }
936                                 else
937                                 {
938                                         r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
939                                 }
940 //                              r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
941                                 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..error %s\n",GetErrorMessage(r));
942                         }
943
944                         AppLogDebug("%d", __pPlayer->GetState());
945                         r = __pPlayer->Play();
946                         TryCatch(r == E_SUCCESS, , "Play failed(%s)", GetErrorMessage(r));
947                         if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
948                         {
949                                 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
950                                 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
951                                 __playposition = sliderPosition;
952                         }
953                         if (bPausePlay == false)
954                         {
955                                 CallOnPlayContentChanged(__currentContentIndex);
956                         }
957
958                         currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
959                 //      CallOnPlayTimeChanged(currentDuration, __playposition);
960                 }
961                 break;
962
963         case PLAYER_STATE_ERROR:
964                 {
965                         AppLogDebug("PlayerState : %d", playerState);
966                         r = E_FAILURE;
967                         TryCatch(r == E_SUCCESS, , "PLAYER_STATE_ERROR occured.\n");
968                 }
969                 break;
970
971         case PLAYER_STATE_CLOSED:
972                 // fall through
973         case PLAYER_STATE_INITIALIZED:
974                 {
975                         TryCatch(__pPlayer != null && pPath != null, r = E_FAILURE, "Player is not initialized or pPath is null.");
976                         r = __pPlayer->OpenFile(*pPath);
977                         TryCatch(r == E_SUCCESS, , "[%ls] OpenFile failed\n(%s).", pPath->GetPointer(), GetErrorMessage(r));
978
979                         if ((__previousPlayerState == PLAYER_STATE_PLAYING) || (__previousPlayerState == PLAYER_STATE_ENDOFCLIP)
980                                 || (__previousPlayerState == PLAYER_STATE_INITIALIZED))
981                         {
982                                 if (__pPauseAutoOffTimer != null)
983                                 {
984                                         r = __pPauseAutoOffTimer->Cancel();
985                                         TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
986                                 }
987                                 if (__pPlayStateTimer != null)
988                                 {
989                                         r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
990                                         TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed\n(%s)", GetErrorMessage(r));
991                                 }
992                                 if (bPlayPause)
993                                 {
994                                         r = __pPlayer->SetMute(true);
995                                         TryLog(r == E_SUCCESS,"__pPlayer->SetMute(true) failed with %s",GetErrorMessage(r));
996                                 }
997                                 r = __pPlayer->Play();
998                                 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
999                                 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
1000                                 {
1001                                         r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
1002                                         TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
1003                                         __playposition = sliderPosition;
1004                                 }
1005                                 __currentContentTotalDuration = __pPlayer->GetDuration();
1006                         }
1007
1008                         UpdateContentDB();
1009                         if (bPausePlay == false)
1010                         {
1011                                 CallOnPlayContentChanged(__currentContentIndex);
1012                         }
1013
1014                         currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1015                 //      CallOnPlayTimeChanged(currentDuration, __playposition);
1016                 }
1017                 break;
1018
1019         case PLAYER_STATE_OPENING:
1020                 {
1021                 }
1022                 break;
1023
1024         default:
1025                 break;
1026         }
1027
1028         CallOnPlayStateChanged(__pPlayer->GetState());
1029         AppLogDebug("EXIT");
1030         return E_SUCCESS;
1031
1032 CATCH:
1033         currentDuration = CommonUtil::GetFormatDate(MIN_SLIDER_COUNT);
1034         CallOnPlayTimeChanged(currentDuration,MIN_SLIDER_COUNT);
1035         CallOnPlayStateChanged(PLAYER_STATE_ERROR);
1036
1037         return E_FAILURE;
1038 }
1039
1040 void
1041 PlayerPresentationModel::Pause(void)
1042 {
1043         AppLogDebug("ENTER");
1044         if (__pPlayer == null)
1045         {
1046                 AppLogDebug("EXIT");
1047                 return;
1048         }
1049
1050         result r = E_SUCCESS;
1051         PlayerState playerState = __pPlayer->GetState() ;
1052         AppLogDebug("%d", playerState);
1053         if (playerState == PLAYER_STATE_PLAYING)
1054         {
1055                 r = __pPlayer->Pause();
1056                 TryCatch(r == E_SUCCESS, , "__pPlayer pause failed..%s\n",GetErrorMessage(r));
1057
1058                 if (__pPlayStateTimer != null)
1059                 {
1060                         r = __pPlayStateTimer->Cancel();
1061                         TryCatch(r == E_SUCCESS, , "__pPlayStateTimer cancel failed..\n");
1062                 }
1063                 if (__pPauseAutoOffTimer != null)
1064                 {
1065                         /*__pPauseAutoOffTimer->Start(3000);*/
1066                         r = __pPauseAutoOffTimer->Start(PAUSE_AUTO_OFF_TIME);
1067                         TryCatch(r == E_SUCCESS, , "__pPauseAutoOffTimer start failed..\n");
1068                 }
1069         }
1070         CallOnPlayStateChanged(__pPlayer->GetState());
1071         AppLogDebug("EXIT");
1072         return;
1073
1074 CATCH:
1075         //AppLogException("[%ls]", GetErrorMessage(r));
1076         return;
1077 }
1078
1079 void
1080 PlayerPresentationModel::MovePreviousContent(bool forceMove)
1081 {
1082         AppLogDebug("ENTER");
1083         if (__pPlayer == null)
1084         {
1085                 AppLogDebug("EXIT");
1086                 return;
1087         }
1088
1089         result r = E_SUCCESS;
1090         String currentDuration = null;
1091
1092 //      if ((__pPlayer->GetState() == PLAYER_STATE_PLAYING || __pPlayer->GetState() == PLAYER_STATE_PAUSED) && (__playposition > MIN_REWIND_POSITION))
1093         if (__playposition > MIN_REWIND_POSITION && forceMove != true)
1094         {
1095                 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1096                 TryCatch(r == E_SUCCESS, , "SeekTo failed. [%ls]", GetErrorMessage(r));
1097                 __playposition = MIN_SLIDER_COUNT;
1098                 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1099                 CallOnPlayTimeChanged(currentDuration, __playposition);
1100                 AppLogDebug("EXIT");
1101                 return;
1102         }
1103         else
1104         {
1105                 __isForceChanged = true;
1106         }
1107
1108 //      ClosePlayer();
1109 //      InitializeProgress();
1110 //      InitializePlayer();
1111 /*      if(IsShuffleEnable())
1112         {
1113                 srand(int(time(NULL)));
1114                 __currentContentIndex = rand() % __pPlayContentList->GetCount();
1115         }
1116         else
1117         {
1118                 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1119         {
1120                 __currentContentIndex = __pPlayContentList->GetCount() - 1;
1121         }
1122         else
1123         {
1124                 __currentContentIndex--;
1125         }
1126
1127                 __removedContentIndex = INIT_CONTENT_INDEX;
1128         }*/
1129
1130         __currentContentIndex = __previousContentIndex;
1131         GenerateNextIndex();
1132         __removedContentIndex = INIT_CONTENT_INDEX;
1133
1134         if (__pPlayContentList->GetCount() > 0)
1135         {
1136                 CallOnPlayContentChanged(__currentContentIndex);
1137                 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1138                 {
1139                         __seekCompleted = false;
1140                         Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
1141                         Pause();
1142                         __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1143                         //need to unmute the player as it is mute in case of moved next in pause state
1144                         __pPlayer->SetMute(false);
1145                         InitializeProgress();
1146                 }
1147         }
1148 //      Play(__currentContentIndex, MIN_SLIDER_COUNT);
1149
1150         AppLogDebug("EXIT");
1151         return;
1152
1153 CATCH:
1154         //AppLogException("[%s]", GetErrorMessage(r));
1155         return;
1156 }
1157
1158 void
1159 PlayerPresentationModel::MoveNextContent(void)
1160 {
1161         AppLogDebug("ENTER");
1162         if (__pPlayer == null)
1163         {
1164                 AppLogDebug("EXIT");
1165                 return;
1166         }
1167         __currentContentIndex = __nextContentIndex;
1168         GenerateNextIndex();
1169         __removedContentIndex = INIT_CONTENT_INDEX;
1170         __isForceChanged = true;
1171         if (__pPlayContentList->GetCount() > 0)
1172         {
1173                 CallOnPlayContentChanged(__currentContentIndex);
1174
1175                 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1176                 {
1177                         __seekCompleted = false;
1178                         Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
1179                         Pause();
1180                         __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1181                         //need to unmute the player as it is mute in case of moved next in pause state
1182                         __pPlayer->SetMute(false);
1183                         InitializeProgress();
1184                 }
1185         }
1186 //      Play(__currentContentIndex, MIN_SLIDER_COUNT);
1187
1188         AppLogDebug("EXIT");
1189         return;
1190 }
1191
1192 void
1193 PlayerPresentationModel::SeekToRewind(void)
1194 {
1195         AppLogDebug("ENTER");
1196         int playDuration = __pPlayer->GetDuration();
1197         if(playDuration != 0)
1198         {
1199                 //__playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1200                 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1201                 Rewind();
1202         }
1203         AppLogDebug("EXIT");
1204 }
1205
1206 void
1207 PlayerPresentationModel::Rewind(void)
1208 {
1209         AppLogDebug("ENTER");
1210
1211         __pPlayStateTimer->Cancel();
1212         __playposition = __playposition - __xTimesValue;
1213         result r = SetPlayPosition(__playposition);
1214         if (IsFailed(r))
1215         {
1216                 StopForwardRewind();
1217                 return;
1218         }
1219
1220         if (__playposition < MIN_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1221         {
1222                 StopForwardRewind();
1223                 return;
1224         }
1225
1226         if (__pFastRewindTimer != null)
1227         {
1228                 r = __pFastRewindTimer->Start(PROGRESS_TIMER_DURATION);
1229                 TryCatch(r == E_SUCCESS, , "__pFastRewindTimer start failed. [%ls]", GetErrorMessage(r));
1230         }
1231
1232         AppLogDebug("EXIT");
1233         return;
1234
1235 CATCH:
1236         //AppLogException("[%ls]", GetErrorMessage(r));
1237         return;
1238 }
1239
1240 void
1241 PlayerPresentationModel::SeekToForward(void)
1242 {
1243         AppLogDebug("ENTER");
1244         int playDuration = __pPlayer->GetDuration();
1245         if(playDuration != 0)
1246         {
1247                 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1248                 Forward();
1249         }
1250         AppLogDebug("EXIT");
1251 }
1252
1253 void
1254 PlayerPresentationModel::Forward(void)
1255 {
1256         AppLogDebug("ENTER");
1257
1258         __pPlayStateTimer->Cancel();
1259         __playposition = __playposition - __xTimesValue;
1260         result r = SetPlayPosition(__playposition);
1261         if (IsFailed(r))
1262         {
1263                 AppLogDebug("SetPlayPosition Failed %s",GetErrorMessage(r));
1264                 StopForwardRewind();
1265                 return;
1266         }
1267
1268         if (__playposition > MAX_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1269         {
1270                 StopForwardRewind();
1271                 return;
1272         }
1273
1274         if (__pFastForwardTimer != null)
1275         {
1276                 r = __pFastForwardTimer->Start(PROGRESS_TIMER_DURATION);
1277                 TryCatch(r == E_SUCCESS, , "__pFastForwardTimer start failed. [%ls]", GetErrorMessage(r));
1278         }
1279
1280         AppLogDebug("EXIT");
1281         return;
1282
1283 CATCH:
1284         //AppLogException("[%ls]", GetErrorMessage(r));
1285         return;
1286 }
1287
1288 void
1289 PlayerPresentationModel::StopForwardRewind(void)
1290 {
1291         AppLogDebug("ENTER");
1292         result r = E_SUCCESS;
1293
1294         if (__pFastForwardTimer != null)
1295         {
1296                 r = __pFastForwardTimer->Cancel();
1297                 TryLog(r == E_SUCCESS, "[%s] __pFastForwardTimer cancel failed", GetErrorMessage(r));
1298         }
1299
1300         if (__pFastRewindTimer != null)
1301         {
1302                 r = __pFastRewindTimer->Cancel();
1303                 TryLog(r == E_SUCCESS, "[%s] __pFastRewindTimer cancel failed", GetErrorMessage(r));
1304         }
1305
1306         r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
1307         __xTimesValue = INIT_X_VALUE;
1308         __seekCompleted = true;
1309         AppLogDebug("EXIT");
1310         return;
1311 }
1312
1313 result
1314 PlayerPresentationModel::SetPlayPosition(int playPosition)
1315 {
1316         AppLogDebug("ENTER %d",playPosition);
1317         if (__pPlayer == null)
1318         {
1319                 AppLogDebug("EXIT");
1320                 return E_FAILURE;
1321         }
1322
1323         result r = E_SUCCESS;
1324         String currentDuration = null;
1325         if (/*(playPosition >= MIN_SLIDER_COUNT) && (playPosition <= TIMER_INTERVAL) &&*/ __seekCompleted == true)
1326         {
1327                 if (GetPlayerState() == PLAYER_STATE_PLAYING || GetPlayerState() == PLAYER_STATE_PAUSED || GetPlayerState() == PLAYER_STATE_OPENED)
1328                 {
1329                         if (playPosition >= MAX_SLIDER_COUNT)
1330                         {
1331                                 r = __pPlayer->SeekTo(__pPlayer->GetDuration());
1332                                 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1333 //                              StopForwardRewind();
1334 //                              __seekCompleted = false;
1335 //                              return;
1336                         }
1337                         else if (playPosition <= MIN_SLIDER_COUNT)
1338                         {
1339                                 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1340                                 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1341                         }
1342                         else
1343                         {
1344                                 int position = playPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL);
1345                                 AppLogDebug("position(%d)", position);
1346                                 r = __pPlayer->SeekTo(position);
1347                                 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1348                         }
1349                         TryCatch(r == E_SUCCESS, r = E_FAILURE, "Unable to seek to.\n");
1350
1351                         __playposition = playPosition;
1352                 //currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1353                 //CallOnPlayTimeChanged(currentDuration, __playposition);
1354                         __seekCompleted = false;
1355                 }
1356                 else
1357                 {
1358 //                      __playposition = playPosition;
1359 //                      currentDuration = CommonUtil::GetFormatDate(playPosition * (__currentPlayContentDuration / TIMER_INTERVAL));
1360 //                      CallOnPlayTimeChanged(currentDuration, __playposition);
1361                         __seekCompleted = true;
1362                 }
1363         }
1364
1365         AppLogDebug("EXIT");
1366         return r;
1367
1368 CATCH:
1369         //AppLogException( "[%s]", GetErrorMessage(r));
1370         if (__pPlayer->GetDuration() > MIN_SLIDER_COUNT)
1371         {
1372                 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1373                 CallOnPlayTimeChanged(currentDuration, __playposition);
1374         }
1375         __seekCompleted = false;
1376         AppLogDebug("EXIT");
1377         return r;
1378 }
1379
1380 int
1381 PlayerPresentationModel::GetPlayPosition(void)
1382 {
1383         AppLogDebug("ENTER");
1384         AppLogDebug("EXIT");
1385         return __playposition;
1386 }
1387
1388 String
1389 PlayerPresentationModel::GetCurrentDuration(void)
1390 {
1391         AppLogDebug("ENTER");
1392         String currentDuration;
1393         if (__pPlayer != null)
1394         {
1395                 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1396         }
1397         else
1398         {
1399                 currentDuration = CommonUtil::GetFormatDate(INIT_VALUE);
1400         }
1401         AppLogDebug("EXIT");
1402         return currentDuration;
1403 }
1404
1405 result
1406 PlayerPresentationModel::SetContentList(IList* pArgs)
1407 {
1408         AppLogDebug("ENTER");
1409         TryReturn( pArgs != null && pArgs->GetCount() > 0, E_INVALID_ARG, "Invalid arguments");
1410         result r = E_SUCCESS;
1411         String* temp = null;
1412
1413         if (__pPlayContentList == null)
1414         {
1415                 __pPlayContentList = new (std::nothrow) ArrayList();
1416                 TryCatch(__pPlayContentList != null, r = E_OUT_OF_MEMORY, "Unable to create ArrayList.\n");
1417
1418                 r = __pPlayContentList->Construct();
1419                 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Construct ArrayList.\n");
1420         }
1421         else
1422         {
1423                 __pPlayContentList->RemoveAll(true);
1424         }
1425
1426         temp = static_cast<String*>(pArgs->GetAt(0));
1427         if (temp->Equals(MUSIC, true))
1428         {
1429                 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(2));
1430                 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1431
1432                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1433
1434                 if (pEnum != null)
1435                 {
1436                         while (pEnum->MoveNext() == E_SUCCESS)
1437                         {
1438                                 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1439                                 AppLogDebug("%ls", pContentPath->GetPointer());
1440                                 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1441                         }
1442                         delete pEnum;
1443                 }
1444         }
1445         else
1446         {
1447                 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(0));
1448                 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1449
1450                 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1451                 if (pEnum != null)
1452                 {
1453                         while (pEnum->MoveNext() == E_SUCCESS)
1454                         {
1455                                 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1456                                 AppLogDebug("%ls", pContentPath->GetPointer());
1457                                 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1458                         }
1459
1460                         delete pEnum;
1461                 }
1462         }
1463
1464         AppLogDebug("EXIT");
1465         return r;
1466
1467 CATCH:
1468         //AppLogException("[%s].\n",GetErrorMessage(r));
1469         if (__pPlayContentList != null)
1470         {
1471                 delete __pPlayContentList;
1472                 __pPlayContentList = null;
1473         }
1474         return r;
1475 }
1476
1477 int
1478 PlayerPresentationModel::GetContentListCount(void)const
1479 {
1480         AppLogDebug("ENTER");
1481         if (__pPlayContentList != null)
1482         {
1483                 AppLogDebug("EXIT");
1484                 return __pPlayContentList->GetCount();
1485         }
1486         else
1487         {
1488                 AppLogDebug("EXIT");
1489                 return INIT_VALUE;
1490         }
1491 }
1492
1493 result
1494 PlayerPresentationModel::SetVolume(int volume)
1495 {
1496         AppLogDebug("ENTER");
1497         String key(MEDIA_VOLUME);
1498         result r = E_SUCCESS;
1499
1500         if (__pVolumeBarStateTimer != null)
1501         {
1502                 r = __pVolumeBarStateTimer->Cancel();
1503                 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel failed.", GetErrorMessage(r));
1504                 r = __pVolumeBarStateTimer->Start(VOLUMEBAR_INTERVAL);
1505                 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Start __pVolumeBarStateTimer.\n");
1506         }
1507
1508         if (volume >= 0 && volume <= 15)
1509         {
1510                 SettingInfo::SetValue(key, volume);
1511         }
1512         AppLogDebug("EXIT");
1513         return r;
1514
1515 CATCH:
1516         //AppLogException("[%ls]", GetErrorMessage(r));
1517         return r;
1518 }
1519
1520 int
1521 PlayerPresentationModel::GetVolume(void)
1522 {
1523         AppLogDebug("ENTER");
1524         int volume = 0;
1525         String key(MEDIA_VOLUME);
1526         SettingInfo::GetValue(key, volume);
1527         AppLogDebug("EXIT");
1528         return volume;
1529 }
1530
1531 void
1532 PlayerPresentationModel::SetShuffleEnable(bool shuffleEnable)
1533 {
1534         AppLogDebug("ENTER");
1535 /*      int __totalCount = 0;
1536
1537         if (__pPlayContentList != null)
1538         {
1539                 __totalCount = __pPlayContentList->GetCount();
1540         }
1541
1542         if (shuffleEnable == true)
1543         {// 0 - 1 (OFF, ON)
1544                 int nDust;
1545                 int nSour;
1546                 int nTemp;
1547                 srand(int(time(NULL)));
1548                 for (int i = 0; i < __totalCount; i++)
1549                 {
1550                         nDust = rand() % __totalCount;
1551                         nSour = rand() % __totalCount;
1552
1553                         nTemp = __pPlayContentIndexOrder[nDust];
1554                         __pPlayContentIndexOrder[nDust] = __pPlayContentIndexOrder[nSour];
1555                         __pPlayContentIndexOrder[nSour] = nTemp;
1556                 }
1557
1558                 for (int i = 0; i < __totalCount; i++)
1559                 {
1560                         if (__pPlayContentIndexOrder[i] - 1 == __currentContentIndex)
1561                         {
1562                                 nTemp = __pPlayContentIndexOrder[i];
1563                                 __pPlayContentIndexOrder[i] = __pPlayContentIndexOrder[__currentContentIndex];
1564                                 __pPlayContentIndexOrder[__currentContentIndex] = nTemp;
1565                         }
1566                 }
1567         }
1568         else
1569         {
1570                 int currentIndex = __currentContentIndex;
1571                 __currentContentIndex = __pPlayContentIndexOrder[currentIndex] - 1;
1572                 for (int i=0; i<__totalCount; i++)
1573                 {
1574                         __pPlayContentIndexOrder[i]=i + 1;
1575                 }
1576         }*/
1577         __shuffleEnable = shuffleEnable;
1578         GenerateNextIndex();
1579         AppLogDebug("EXIT");
1580 }
1581
1582 void
1583 PlayerPresentationModel::SetRepeatMode(int repeatMode)
1584 {
1585         AppLogDebug("ENTER");
1586         __repeatMode = repeatMode;
1587         AppLogDebug("EXIT");
1588 }
1589
1590 bool
1591 PlayerPresentationModel::IsShuffleEnable(void)
1592 {
1593         AppLogDebug("ENTER");
1594         AppLogDebug("EXIT");
1595         return __shuffleEnable;
1596 }
1597
1598 bool
1599 PlayerPresentationModel::IsFileExist(int contentIndex) const
1600 {
1601         AppLogDebug("ENTER");
1602         TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), false, "contentIndex is invalid.")
1603         String* pFilePath = GetContentPath(contentIndex);
1604
1605         File file;
1606
1607         result r = file.Construct(*pFilePath, "r");
1608         TryReturn(r == E_SUCCESS, false, "File construct was failed.")
1609
1610         AppLogDebug("EXIT");
1611         return file.IsFileExist(*pFilePath);
1612 }
1613
1614 int
1615 PlayerPresentationModel::GetRepeatState(void)
1616 {
1617         AppLogDebug("ENTER");
1618         AppLogDebug("EXIT");
1619         return __repeatMode;
1620 }
1621
1622 String
1623 PlayerPresentationModel::GetFileName(String* pFilePath)
1624 {
1625         AppLogDebug("ENTER");
1626         String path = Tizen::Io::File::GetFileName(*pFilePath);
1627         String strRemoveTemp = IDS_BLANK;
1628         int removeIndex = -1 ;
1629         path.LastIndexOf(IDS_PERIOD, path.GetLength() - 1, removeIndex);
1630         path.SubString(removeIndex + 1, strRemoveTemp);
1631         String strTemp = IDS_BLANK;
1632
1633         path.Remove(removeIndex, strRemoveTemp.GetLength() + 1);
1634         path.SubString(0, strTemp);
1635         AppLogDebug("EXIT");
1636         return strTemp;
1637 }
1638
1639 void
1640 PlayerPresentationModel::InitializeProgress(void)
1641 {
1642         AppLogDebug("ENTER");
1643         result r = E_SUCCESS;
1644
1645         String currentDuration = null;
1646         if (__pPlayer != null)
1647         {
1648                 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1649         }
1650         else
1651         {
1652                 currentDuration = INITIAL_TIME;
1653         }
1654
1655         if (__pPlayStateTimer != null /*&& __previousPlayerState != PLAYER_STATE_INITIALIZED*/
1656                 && __previousPlayerState != PLAYER_STATE_PAUSED
1657                 && __previousPlayerState != PLAYER_STATE_CLOSED)
1658         {
1659                 r = __pPlayStateTimer->Cancel();
1660                 TryLog(r == E_SUCCESS, "[%s] __pPlayStateTimer cancel failed.", GetErrorMessage(r));
1661         }
1662         __playposition = MIN_SLIDER_COUNT;
1663 //      __seekCompleted = true;
1664         __xTimesValue = INIT_VALUE;
1665         //CallOnPlayTimeChanged(currentDuration, __playposition);
1666         AppLogDebug("EXIT");
1667         return;
1668 }
1669
1670 void
1671 PlayerPresentationModel::UpdateContentDB(void)
1672 {
1673         AppLogDebug("ENTER");
1674         result r = E_SUCCESS;
1675         int playCount = 0;
1676         String contentIdString;
1677         ArrayList* pTempList = null;
1678
1679         Tizen::Base::String contentPath = *static_cast<String*>(__pPlayContentList->GetAt(__currentContentIndex));
1680         if (File::IsFileExist(contentPath) == false)
1681         {
1682                 AppLogDebug("File not exist(%ls)", contentPath.GetPointer());
1683                 return;
1684         }
1685
1686         ContentId contentId = CommonUtil::GetContentId(contentPath);
1687         if (IsFailed(GetLastResult()))
1688         {
1689                 AppLogDebug("CommonUtil::GetContentId(%ls) failed", contentPath.GetPointer());
1690                 return;
1691         }
1692
1693         DateTime playTime;
1694         Tizen::System::SystemTime::GetCurrentTime(Tizen::System::TIME_MODE_STANDARD, playTime);
1695         Tizen::Base::String playTimeString = playTime.ToString();
1696
1697         PlaylistDB* pPlaylistDB = new (std::nothrow) PlaylistDB();
1698         r = pPlaylistDB->CreatePlaylistDatabase();
1699         TryCatch(r == E_SUCCESS,,"CreatePlaylistDatabase() failed with error %s",GetErrorMessage(r));
1700
1701 //      pTempList = new (std::nothrow) ArrayList();
1702 //      pTempList->Construct();
1703
1704         contentIdString = contentId.ToString();
1705         if (pPlaylistDB->Read(contentIdString) != E_KEY_ALREADY_EXIST)
1706         {
1707                 pPlaylistDB->Insert(contentIdString, playCount + 1, playTimeString);
1708         }
1709         else
1710         {
1711                 pTempList = pPlaylistDB->ReadValueN(contentIdString);
1712                 if (pTempList != null)
1713                 {
1714                         playCount = static_cast<Integer*>(pTempList->GetAt(0))->ToInt();
1715                 }
1716                 pPlaylistDB->Update(contentIdString, playCount + 1, playTimeString);
1717         }
1718
1719 CATCH:
1720
1721         if (pPlaylistDB != null)
1722         {
1723                 delete pPlaylistDB;
1724                 pPlaylistDB = null;
1725         }
1726
1727         if (pTempList != null)
1728         {
1729                 pTempList->RemoveAll(true);
1730                 delete pTempList;
1731                 pTempList = null;
1732         }
1733         AppLogDebug("EXIT");
1734 }
1735
1736 void
1737 PlayerPresentationModel::GenerateNextIndex(void)
1738 {
1739         AppLogDebug("ENTER");
1740         if (IsShuffleEnable())
1741         {
1742                 int totalCount = __pPlayContentList->GetCount();
1743
1744                 if (totalCount < 2)
1745                 {
1746                         __previousContentIndex = 0;
1747                         __nextContentIndex = 0;
1748                 }
1749                 else
1750                 {
1751                         srand(int(time(NULL)));
1752                         __previousContentIndex = rand() % totalCount;
1753                         while (__previousContentIndex == __currentContentIndex)
1754                         {
1755                                 __previousContentIndex = rand() % totalCount;
1756                         }
1757
1758                         __nextContentIndex = rand() % totalCount;
1759                         while (__nextContentIndex == __currentContentIndex)
1760                         {
1761                                 __nextContentIndex = rand() % totalCount;
1762                         }
1763                 }
1764         }
1765         else
1766         {
1767                 if (__pPlayContentList->GetCount() == 0)
1768                 {
1769                         __previousContentIndex = 0;
1770                         __nextContentIndex = 0;
1771                         return;
1772                 }
1773
1774                 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1775                 {
1776                         __previousContentIndex = __pPlayContentList->GetCount() - 1;
1777                 }
1778                 else
1779                 {
1780                         __previousContentIndex = __currentContentIndex - 1;
1781                 }
1782
1783                 if (__currentContentIndex == __pPlayContentList->GetCount() - 1
1784                         || __removedContentIndex == __pPlayContentList->GetCount())
1785                 {
1786                         __nextContentIndex = 0;
1787                 }
1788                 else
1789                 {
1790                         if (__removedContentIndex != INIT_CONTENT_INDEX)
1791                         {
1792                                 __nextContentIndex = __previousContentIndex + 1;
1793                                 if (__nextContentIndex > __pPlayContentList->GetCount() - 1)
1794                                 {
1795                                         __nextContentIndex = 0;
1796                                 }
1797                         }
1798                         else
1799                         {
1800                                 __nextContentIndex = __currentContentIndex + 1;
1801                         }
1802                 }
1803         }
1804         AppLogDebug("EXIT");
1805 }
1806
1807 void
1808 PlayerPresentationModel::OnPlayerOpened(result r)
1809 {
1810         AppLogDebug("ENTER");
1811         AppLogDebug("EXIT");
1812 }
1813
1814 void
1815 PlayerPresentationModel::OnPlayerReleased(void)
1816 {
1817         AppLogDebug("ENTER");
1818         if (__pPlayer != null && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1819         {
1820                 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1821         }
1822         AppLogDebug("EXIT");
1823 }
1824
1825 void
1826 PlayerPresentationModel::OnPlayerEndOfClip(void)
1827 {
1828         AppLogDebug("ENTER");
1829 //      StopForwardRewind();
1830
1831         if (__pPlayer == null)
1832         {
1833                 AppLogDebug("EXIT");
1834                 return;
1835         }
1836         __seekCompleted = true;
1837         AppLogDebug("GetRepeatState() : %d", GetRepeatState());
1838
1839         String totalDuration = CommonUtil::GetFormatDate(__currentContentTotalDuration);
1840         AppLogDebug("totalDuration(%ls), __currentContentTotalDuration(%d)", totalDuration.GetPointer(), __currentContentTotalDuration);
1841         CallOnPlayTimeChanged(totalDuration, MAX_SLIDER_COUNT);
1842
1843         switch (GetRepeatState())// 0 - 2 (OFF, ONE, ALL)
1844         {
1845         case 1:
1846                 {
1847                         AppLogDebug("Repeat State(%d)", 1);
1848                         while (__pPlayContentList->GetCount() > 0 && IsFileExist(__currentContentIndex) == false)
1849                         {
1850                                 RemoveContent(*GetContentPath(__currentContentIndex));
1851                         }
1852
1853                         //Need to play the currently loaded song in case there is no other content available in "Now Playing List"
1854                         if (__pPlayContentList->GetCount() == 0)
1855                         {
1856                                 StopForwardRewind();
1857                                 InitializeProgress();
1858                                 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1859                                 break;
1860                         }
1861
1862                         ClosePlayer();
1863                         InitializeProgress();
1864                         InitializePlayer();
1865                         Play(__currentContentIndex, MIN_SLIDER_COUNT);
1866                 }
1867                 break;
1868
1869         case 0:
1870                 {
1871                         AppLogDebug("Repeat State(%d)", 0);
1872                         if (__pPlayContentList->GetCount() - 1 == __currentContentIndex)
1873                         {
1874                                 StopForwardRewind();
1875                                 InitializeProgress();
1876                                 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1877                                 Pause();
1878                         }
1879                         else
1880                         {
1881                                 while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1882                                 {
1883                                         RemoveContent(*GetContentPath(GetNextContentIndex()));
1884                                 }
1885                                 MoveNextContent();
1886                                 InitializeProgress();
1887                                 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1888                         }
1889                 }
1890                 break;
1891
1892         case 2:
1893                 {
1894                         AppLogDebug("Repeat State(%d)", 2);
1895
1896                         while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1897                         {
1898                                 RemoveContent(*GetContentPath(GetNextContentIndex()));
1899                         }
1900
1901                         //Need to play the currently loaded song in case there is no other content available in "Now Playing List"
1902                         if (__pPlayContentList->GetCount() == 0)
1903                         {
1904                                 StopForwardRewind();
1905                                 InitializeProgress();
1906                                 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1907                                 break;
1908                         }
1909
1910                         MoveNextContent();
1911                         InitializeProgress();
1912                         Play(__currentContentIndex, MIN_SLIDER_COUNT);
1913                 }
1914                 break;
1915
1916         default:
1917                 break;
1918         }
1919         AppLogDebug("EXIT");
1920 }
1921
1922 void
1923 PlayerPresentationModel::OnPlayerBuffering(int percent)
1924 {
1925         AppLogDebug("ENTER");
1926         if (__pPlayer == null)
1927         {
1928                 AppLogDebug("EXIT");
1929                 return;
1930         }
1931         CallOnPlayStateChanged(__pPlayer->GetState());
1932         AppLogDebug("EXIT");
1933 }
1934
1935 void
1936 PlayerPresentationModel::OnPlayerErrorOccurred(PlayerErrorReason r)
1937 {
1938         AppLogDebug("ENTER");
1939         if (__pPlayer == null)
1940         {
1941                 AppLogDebug("EXIT");
1942                 return;
1943         }
1944         CallOnPlayStateChanged(__pPlayer->GetState());
1945         AppLogDebug("EXIT");
1946 }
1947
1948 void
1949 PlayerPresentationModel::OnPlayerInterrupted(void)
1950 {
1951         AppLogDebug("ENTER");
1952         Pause();
1953         AppLogDebug("EXIT");
1954         return;
1955 }
1956
1957 void
1958 PlayerPresentationModel::OnPlayerSeekCompleted(result r)
1959 {
1960         AppLogDebug("ENTER %s",GetErrorMessage(r));
1961         if (r == E_SUCCESS)
1962         {
1963                 __seekCompleted = true;
1964         }
1965         else
1966         {
1967                 __seekCompleted = false;
1968         }
1969
1970         String currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1971         CallOnPlayTimeChanged(currentDuration, __playposition);
1972         AppLogDebug("EXIT current duration %ls",currentDuration.GetPointer());
1973 }
1974
1975 void
1976 PlayerPresentationModel::OnPlayerAudioFocusChanged(void)
1977 {
1978         AppLogDebug("ENTER");
1979         /*__audioFocusChanged = true;*/
1980         Pause();
1981         AppLogDebug("EXIT");
1982 }
1983
1984 /*void
1985 PlayerPresentationModel::OnAudioSessionInterrupted(void)
1986 {
1987         AppLogDebug("ENTER");
1988         AppLogDebug("EXIT");
1989 }
1990
1991 void
1992 PlayerPresentationModel::OnAudioSessionInterruptReleased(void)
1993 {
1994         AppLogDebug("ENTER");
1995         AppLogDebug("EXIT");
1996 }
1997
1998 void
1999 PlayerPresentationModel::OnAudioSessionAudioFocusChanged(void)
2000 {
2001         AppLogDebug("ENTER");
2002         AppLogDebug("EXIT");
2003 }*/
2004
2005 void
2006 PlayerPresentationModel::OnTimerExpired(Timer& timer)
2007 {
2008 //      AppLogDebug("ENTER");
2009         if (__pPlayer == null)
2010         {
2011                 AppLogDebug("EXIT player is null");
2012                 return;
2013         }
2014
2015         result r = E_SUCCESS;
2016         if (__pPlayStateTimer == &timer)
2017         {
2018                 PlayerState playerState = __pPlayer->GetState() ;
2019                 String currentDuration = null;
2020                 int playDuration = __pPlayer->GetDuration();
2021                 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2022
2023                 switch (playerState)
2024                 {
2025                 case PLAYER_STATE_PLAYING:
2026                         {
2027                         //      long int totalDuration = __pPlayer->GetDuration();
2028                 //              AppLogDebug("totalDuration(%d), PROGRESS_BAR_DURATION_TIMER(%d)", totalDuration, PROGRESS_BAR_DURATION_TIMER);
2029                                 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2030
2031                                 if ( playDuration < 2000)
2032                                 {
2033                                         currentDuration = CommonUtil::GetFormatDate(playDuration);
2034                                         CallOnPlayTimeChanged(currentDuration, TIMER_INTERVAL);
2035                                         return;
2036                                 }
2037
2038                                 if (playDuration < PROGRESS_BAR_DURATION_TIMER)
2039                                 {
2040                                         r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER/10);
2041                                 }
2042                                 else
2043                                 {
2044                                         r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
2045                                 }
2046
2047                                 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..\n");
2048                                 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
2049                                 //AppLogDebug("GetPosition(%d), playDuration(%d)", __pPlayer->GetPosition(), playDuration);
2050
2051                                 if (__pPlayer->GetPosition() <= playDuration)
2052                                 {
2053                                         currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
2054                                         __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
2055 //                                      AppLogDebug("currentDuration(%s), __playposition(%d)", currentDuration.GetPointer(), __playposition);
2056                                         CallOnPlayTimeChanged(currentDuration, __playposition);
2057                                 }
2058                         }
2059                         break;
2060
2061                 case PLAYER_STATE_PAUSED:
2062                         {
2063                                 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
2064                                 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2065                                 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
2066                                 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
2067                                 CallOnPlayTimeChanged(currentDuration, __playposition);
2068                         }
2069                         break;
2070
2071                 default:
2072                         break;
2073                 }
2074         }
2075         else if (__pFastForwardTimer == &timer)
2076         {
2077                 __xTimesValue--;
2078                 Forward();
2079         }
2080         else if (__pFastRewindTimer == &timer)
2081         {
2082                 __xTimesValue++;
2083                 Rewind();
2084         }
2085         else if (__pAutoOffTimer == &timer)
2086         {
2087                 Application::GetInstance()->Terminate();
2088         }
2089         else if (__pPauseAutoOffTimer == &timer)
2090         {
2091                 Application::GetInstance()->Terminate();
2092         }
2093         else if (__pVolumeBarStateTimer == &timer)
2094         {
2095                 r = __pVolumeBarStateTimer->Cancel();
2096                 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel Failed.", GetErrorMessage(r));
2097                 CallOnPlayVolumeBarStateChanged();
2098         }
2099         else
2100         {
2101                 //AppLogDebug("Timer is invalid value.");
2102         }
2103 //      AppLogDebug("EXIT");
2104
2105         return;
2106
2107 CATCH:
2108         //AppLogException("[%ls]", GetErrorMessage(r));
2109         return;
2110 }
2111
2112 void
2113 PlayerPresentationModel::AddMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2114 {
2115         AppLogDebug("ENTER");
2116         __musicPlayerEventListener.Add(const_cast<IMusicPlayerEventListener*>(&listener));
2117         AppLogDebug("EXIT");
2118 }
2119
2120 void
2121 PlayerPresentationModel::RemoveMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2122 {
2123         AppLogDebug("ENTER");
2124         __musicPlayerEventListener.Remove(const_cast<IMusicPlayerEventListener*>(&listener));
2125         AppLogDebug("EXIT");
2126 }
2127
2128 void
2129 PlayerPresentationModel::CallOnPlayStateChanged(PlayerState playerState)
2130 {
2131         AppLogDebug("ENTER");
2132         IMusicPlayerEventListener* pListener = null;
2133         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2134         while (pEnum->MoveNext() == E_SUCCESS)
2135         {
2136                 pEnum->GetCurrent(pListener);
2137                 if (pListener != null)
2138                 {
2139                         pListener->OnPlayStateChanged(playerState);
2140                 }
2141         }
2142         delete pEnum;
2143         AppLogDebug("EXIT");
2144 }
2145
2146 void
2147 PlayerPresentationModel::CallOnPlayContentChanged(int currentContentIndex)
2148 {
2149         AppLogDebug("ENTER");
2150         IMusicPlayerEventListener* pListener = null;
2151         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2152         while (pEnum->MoveNext() == E_SUCCESS)
2153         {
2154                 pEnum->GetCurrent(pListener);
2155                 if (pListener != null)
2156                 {
2157                         pListener->OnPlayContentChanged(currentContentIndex);
2158                 }
2159         }
2160         delete pEnum;
2161         AppLogDebug("EXIT");
2162 }
2163
2164 void
2165 PlayerPresentationModel::CallOnPlayContentRemoved(int removedContentIndex)
2166 {
2167         AppLogDebug("ENTER");
2168         IMusicPlayerEventListener* pListener = null;
2169         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2170         while (pEnum->MoveNext() == E_SUCCESS)
2171         {
2172                 pEnum->GetCurrent(pListener);
2173                 if (pListener != null)
2174                 {
2175                         pListener->OnPlayContentRemoved(removedContentIndex);
2176                 }
2177         }
2178         delete pEnum;
2179         AppLogDebug("EXIT");
2180 }
2181
2182 void
2183 PlayerPresentationModel::CallOnPlayTimeChanged(Tizen::Base::String& currentDuration, int currentPosition)
2184 {
2185 //      AppLogDebug("ENTER");
2186         IMusicPlayerEventListener* pListener = null;
2187         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2188         while (pEnum->MoveNext() == E_SUCCESS)
2189         {
2190                 pEnum->GetCurrent(pListener);
2191                 if (pListener != null)
2192                 {
2193                         pListener->OnPlayTimeChanged(currentDuration, currentPosition);
2194                 }
2195         }
2196         delete pEnum;
2197 //      AppLogDebug("EXIT");
2198 }
2199
2200 void
2201 PlayerPresentationModel::CallOnPlayVolumeBarStateChanged(void)
2202 {
2203         AppLogDebug("ENTER");
2204         IMusicPlayerEventListener* pListener = null;
2205         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2206         while (pEnum->MoveNext() == E_SUCCESS)
2207         {
2208                 pEnum->GetCurrent(pListener);
2209                 if (pListener != null)
2210                 {
2211                         pListener->OnPlayVolumeBarStateChanged();
2212                 }
2213         }
2214         delete pEnum;
2215         AppLogDebug("EXIT");
2216 }
2217
2218 void
2219 PlayerPresentationModel::CallOnPlayPresentationModelDestroying(void)
2220 {
2221         AppLogDebug("ENTER");
2222         IMusicPlayerEventListener* pListener = null;
2223         IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2224         while (pEnum->MoveNext() == E_SUCCESS)
2225         {
2226                 pEnum->GetCurrent(pListener);
2227                 if (pListener != null)
2228                 {
2229                         pListener->OnPlayPresentationModelDestroying();
2230                 }
2231         }
2232         delete pEnum;
2233         AppLogDebug("EXIT");
2234 }