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