2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file MpMusicPlayerPresentationModel.cpp
19 * @brief This is the implementation file for MusicPlayerPresentationModel class.
24 #include <FGraphics.h>
28 #include "MpCommonUtil.h"
29 #include "MpIMusicPlayerEventListener.h"
30 #include "MpMusicPlayerPresentationModel.h"
31 #include "MpPlaylistDB.h"
32 #include "MpResourceManager.h"
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;
48 #define BUFFER_INFO_OF_PLAYER 0
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;
59 PlayerPresentationModel* PlayerPresentationModel::pPlayerPresentationModel = null;
61 PlayerPresentationModel*
62 PlayerPresentationModel::GetInstance(void)
65 if (pPlayerPresentationModel == null)
67 pPlayerPresentationModel = new (std::nothrow) PlayerPresentationModel();
68 TryReturn(pPlayerPresentationModel != null, null, "PlayerPresentationModel instance is not created.");
70 result r = pPlayerPresentationModel->Construct();
71 TryCatch(r == E_SUCCESS, , null, "PlayerPresentationModel instance is not constructed.");
74 return pPlayerPresentationModel;
77 if (pPlayerPresentationModel != null)
79 delete pPlayerPresentationModel;
85 PlayerPresentationModel::PlayerPresentationModel(void)
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)
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)
115 AppLogDebug("ENTER");
119 PlayerPresentationModel::~PlayerPresentationModel(void)
121 AppLogDebug("ENTER");
122 result r = E_SUCCESS;
124 if (__repeatMode != CommonUtil::GetValue(REPEAT_MODE))
126 CommonUtil::SetValue(REPEAT_MODE, __repeatMode);
128 if (__shuffleEnable != static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE)))
130 CommonUtil::SetValue(SHUFFLE_MODE, static_cast<int>(__shuffleEnable));
132 if (__pPlayContentList != null)
134 __pPlayContentList->RemoveAll(true);
135 delete __pPlayContentList;
136 __pPlayContentList = null;
138 if (__pPlayStateTimer != null)
140 __pPlayStateTimer->Cancel();
141 delete __pPlayStateTimer;
142 __pPlayStateTimer = null;
144 if (__pFastForwardTimer != null)
146 __pFastForwardTimer->Cancel();
147 delete __pFastForwardTimer;
148 __pFastForwardTimer = null;
150 if (__pFastRewindTimer != null)
152 __pFastRewindTimer->Cancel();
153 delete __pFastRewindTimer;
154 __pFastRewindTimer = null;
156 if (__pAutoOffTimer != null)
158 __pAutoOffTimer->Cancel();
159 delete __pAutoOffTimer;
160 __pAutoOffTimer = null;
162 if (__pPauseAutoOffTimer != null)
164 __pPauseAutoOffTimer->Cancel();
165 delete __pPauseAutoOffTimer;
166 __pPauseAutoOffTimer = null;
168 if (__pVolumeBarStateTimer != null)
170 __pVolumeBarStateTimer->Cancel();
171 delete __pVolumeBarStateTimer;
174 delete __pCurrentPlayContentPath;
175 delete __pCurrentPlayContentTitle;
176 delete __pCurrentPlayContentThumbnail;
177 delete __pCurrentPlayContentArtist;
178 delete __pUuIdForFileOnly;
179 delete __pCurrentAudioContentInfo;
181 if (__pCallManager != null)
183 delete __pCallManager;
186 if (__pPlayer == null)
191 if (__pPlayer != null)
193 PlayerState state = __pPlayer->GetState();
196 case PLAYER_STATE_PLAYING:
198 case PLAYER_STATE_PAUSED:
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));
207 case PLAYER_STATE_ENDOFCLIP:
209 case PLAYER_STATE_OPENED:
211 case PLAYER_STATE_STOPPED:
213 r = __pPlayer->Close();
214 TryLog(r == E_SUCCESS, "[%s] Failed Close",GetErrorMessage(r));
218 case PLAYER_STATE_CLOSED:
233 PlayerPresentationModel::DestroyPlayerPresentationModel(void)
235 AppLogDebug("ENTER");
236 if (pPlayerPresentationModel != null)
238 CallOnPlayPresentationModelDestroying();
240 delete pPlayerPresentationModel;
241 pPlayerPresentationModel = null;
247 PlayerPresentationModel::OnTelephonyCallStatusChangedN(Tizen::Telephony::CallStatus callStatus, Tizen::Telephony::CallInfo* pCallInfo)
249 AppLogDebug("ENTER");
250 AppLogDebug("callStatus : %d", callStatus);
251 if (callStatus == CALL_STATUS_IDLE || callStatus == CALL_STATUS_COMMUNICATING)
253 CallOnPlayContentChanged(__currentContentIndex);
259 PlayerPresentationModel::Construct(void)
261 AppLogDebug("ENTER");
262 result r = E_SUCCESS;
264 /*AudioSessionManager::GetInstance()->SetAudioSessionEventListener(this);
265 AudioSessionManager::GetInstance()->SetMode(AUDIO_SESSION_MODE_EXCLUSIVE);*/
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");
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");
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");
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");
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");
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");
291 __pCurrentPlayContentPath = new (std::nothrow) String(L"");
293 __repeatMode = CommonUtil::GetValue(REPEAT_MODE);
294 __shuffleEnable = static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE));
296 __pCallManager = new (std::nothrow) CallManager();
297 __pCallManager->Construct(*this);
299 __pUuIdForFileOnly = Tizen::Base::UuId::GenerateN();
307 //AppLogException( "[%s]", GetErrorMessage(r));
308 if (__pPlayStateTimer != null)
310 __pPlayStateTimer->Cancel();
311 delete __pPlayStateTimer;
312 __pPlayStateTimer = null;
314 if (__pFastForwardTimer != null)
316 __pFastForwardTimer->Cancel();
317 delete __pFastForwardTimer;
318 __pFastForwardTimer = null;
320 if (__pFastRewindTimer != null)
322 __pFastRewindTimer->Cancel();
323 delete __pFastRewindTimer;
324 __pFastRewindTimer = null;
326 if (__pAutoOffTimer != null)
328 __pAutoOffTimer->Cancel();
329 delete __pAutoOffTimer;
330 __pAutoOffTimer = null;
332 if (__pPauseAutoOffTimer != null)
334 __pPauseAutoOffTimer->Cancel();
335 delete __pPauseAutoOffTimer;
336 __pPauseAutoOffTimer = null;
338 if (__pVolumeBarStateTimer != null)
340 __pVolumeBarStateTimer->Cancel();
341 delete __pVolumeBarStateTimer;
347 PlayerPresentationModel::InitializePlayer(void)
349 AppLogDebug("ENTER");
350 result r = E_SUCCESS;
352 if (__pPlayer != null)
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");
373 PlayerPresentationModel::StartAutoOffTimer(int autoOffValue)
375 AppLogDebug("ENTER");
376 result r = E_SUCCESS;
377 if (__pAutoOffTimer != null)
379 if (autoOffValue == 0)
381 r = __pAutoOffTimer->Cancel();
382 AppLogDebug("%s", GetErrorMessage(r));
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");
398 //AppLogException( "[%s]", GetErrorMessage(r));
403 PlayerPresentationModel::RemoveContent(const Tizen::Base::String& filePath)
405 AppLogDebug("ENTER");
406 TryReturnVoid(__pPlayContentList != null, "There is not a playlist");
407 IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
408 String* pFilePath = null;
411 while (pEnum->MoveNext() == E_SUCCESS)
413 pFilePath = static_cast<String*>(pEnum->GetCurrent());
415 if (pFilePath->Equals(filePath))
417 __pPlayContentList->Remove(filePath);
419 if (index < __currentContentIndex)
421 __currentContentIndex--;
423 else if (index == __currentContentIndex)
425 if (index == __pPlayContentList->GetCount())
427 __currentContentIndex--;
429 __removedContentIndex = index;
433 if (__pPlayContentList->GetCount() > 0)
435 CallOnPlayContentRemoved(index);
447 PlayerPresentationModel::GetPlayerState(void)
449 AppLogDebug("ENTER");
450 if (__pPlayer == null)
453 return PLAYER_STATE_ERROR;
456 return __pPlayer->GetState();
460 PlayerPresentationModel::IsDuringCall(void)
462 AppLogDebug("ENTER");
463 CallStatus callStatus = CALL_STATUS_UNDEFINED;
464 callStatus = __pCallManager->GetCurrentCallStatus();
465 AppLogDebug("callStatus = %d", callStatus);
467 if (callStatus == CALL_STATUS_IDLE)
480 PlayerPresentationModel::ClosePlayer(void)
482 AppLogDebug("ENTER");
483 result r = E_SUCCESS;
485 if (__pPlayer == null)
491 __previousPlayerState = __pPlayer->GetState();
493 switch (__previousPlayerState)
495 case PLAYER_STATE_PLAYING:
497 case PLAYER_STATE_PAUSED:
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));
506 case PLAYER_STATE_OPENED:
508 case PLAYER_STATE_STOPPED:
510 r = __pPlayer->Close();
511 TryLog(r == E_SUCCESS, "[%s] Failed Close", GetErrorMessage(r));
515 case PLAYER_STATE_CLOSED:
520 case PLAYER_STATE_ENDOFCLIP:
532 PlayerPresentationModel::GetPlayContentPath(void)
534 AppLogDebug("ENTER");
536 return __pCurrentPlayContentPath;
540 PlayerPresentationModel::GetPlayContentTitle(void)
542 AppLogDebug("ENTER");
544 return __pCurrentPlayContentTitle;
548 PlayerPresentationModel::GetPlayContentArtist(void)
550 AppLogDebug("ENTER");
552 return __pCurrentPlayContentArtist;
555 Tizen::Graphics::Bitmap*
556 PlayerPresentationModel::GetPlayContentThumbnail(void)
558 AppLogDebug("ENTER");
560 return __pCurrentPlayContentThumbnail;
564 PlayerPresentationModel::GetPlayContentDuration(void)
566 AppLogDebug("ENTER");
568 return __currentPlayContentDuration;
572 PlayerPresentationModel::GetContentPath(int contentIndex)const
574 AppLogDebug("ENTER");
575 String* pFilePath = null;
577 TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), null, "contentIndex is invalid.");
578 pFilePath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
585 PlayerPresentationModel::GetPreviousContentIndex(void) const
587 AppLogDebug("ENTER");
589 return __previousContentIndex;
593 PlayerPresentationModel::GetCurrentContentIndex(void) const
595 AppLogDebug("ENTER");
597 return __currentContentIndex;
601 PlayerPresentationModel::GetNextContentIndex(void) const
603 AppLogDebug("ENTER");
605 return __nextContentIndex;
609 PlayerPresentationModel::GetContentInfoN(int contentIndex)
611 AppLogDebug("ENTER");
612 AudioContentInfo* pAudioContentInfo = null;
614 if (__pPlayContentList == null || contentIndex < INIT_VALUE)
616 AppLogDebug("EXIT(index(%d) MUST be greater than or equal to 0 OR __pPlayContentList is null)", contentIndex);
620 ContentInformation* pContentInfo = new (std::nothrow) ContentInformation();
621 TryReturn(pContentInfo != null, null, "pContentInfo is null.");
623 if ( __pCurrentAudioContentInfo != null && contentIndex == __currentContentIndex)
625 pAudioContentInfo = __pCurrentAudioContentInfo;
629 Tizen::Base::String* contentPath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
630 if (contentPath == null || File::IsFileExist(*contentPath) == false)
636 pAudioContentInfo = CommonUtil::GetAudioContentInfoN(*contentPath);
639 if (pAudioContentInfo != null)
641 if (pAudioContentInfo->GetArtist() == null)
643 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
647 pContentInfo->ArtistName = pAudioContentInfo->GetArtist();
650 if (pAudioContentInfo->GetTitle() == null)
652 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
656 pContentInfo->TitleName = pAudioContentInfo->GetTitle();
659 if (__pPlayer != null)
661 pContentInfo->Duration = __pPlayer->GetDuration();
665 pContentInfo->Duration = pAudioContentInfo->GetDuration();
667 pContentInfo->contentId = pAudioContentInfo->GetContentId();
669 if (pAudioContentInfo != __pCurrentAudioContentInfo)
671 delete pAudioContentInfo;
676 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
677 if (pAudioMeta == null)
683 if (pAudioMeta->GetArtist() == null)
685 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
689 pContentInfo->ArtistName = pAudioMeta->GetArtist();
692 if (pAudioMeta->GetTitle() == null)
694 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
698 pContentInfo->TitleName = pAudioMeta->GetTitle();
701 if (__pPlayer != null)
703 pContentInfo->Duration = __pPlayer->GetDuration();
705 pContentInfo->contentId = *__pUuIdForFileOnly;
713 Tizen::Graphics::Bitmap*
714 PlayerPresentationModel::GetContentAlbumArtN(int contentIndex)
716 AppLogDebug("ENTER");
717 Bitmap* pAlbumArtBitmap = null;
718 if (contentIndex <= -1)
720 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
722 return pAlbumArtBitmap;
725 String* path = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
728 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
730 return pAlbumArtBitmap;
733 pAlbumArtBitmap = CommonUtil::GetContentAlbumArtN(*path);
734 if (pAlbumArtBitmap == null)
736 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
739 return pAlbumArtBitmap;
743 PlayerPresentationModel::Play(int contentIndex, int sliderPosition, bool bPausePlay, bool bPlayPause)
745 AppLogDebug("ENTER");
746 result r = E_SUCCESS;
748 if (__pPlayer == null)
754 __seekCompleted = true;
755 /* if (__seekCompleted == false)
761 if (GetContentListCount() == 0)
764 InitializeProgress();
767 PlayerState playerState;
768 String currentDuration = null;
769 String* pPath = null;
771 if (bPausePlay == false)
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)
779 __isForceChanged = false;
781 InitializeProgress();
783 __previousPlayerState = PLAYER_STATE_INITIALIZED;
784 __currentContentIndex = contentIndex;
786 __pCurrentPlayContentPath->Clear();
787 __pCurrentPlayContentPath->Append(pPath->GetPointer());
789 if (__pCurrentAudioContentInfo != null)
791 delete __pCurrentAudioContentInfo;
792 __pCurrentAudioContentInfo = null;
795 __pCurrentAudioContentInfo = CommonUtil::GetAudioContentInfoN(*(__pCurrentPlayContentPath));
797 if (__pCurrentAudioContentInfo != null)
799 if (__pCurrentPlayContentTitle != null)
801 delete __pCurrentPlayContentTitle;
803 if(__pCurrentPlayContentThumbnail != null)
805 delete __pCurrentPlayContentThumbnail;
808 __pCurrentPlayContentTitle = new (std::nothrow) String(__pCurrentAudioContentInfo->GetTitle());
809 __pCurrentPlayContentThumbnail = __pCurrentAudioContentInfo->GetThumbnailN();
810 if (__pCurrentPlayContentThumbnail == null)
812 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
815 if (__pCurrentPlayContentArtist != null)
817 delete __pCurrentPlayContentArtist;
819 __pCurrentPlayContentArtist = new (std::nothrow) String(__pCurrentAudioContentInfo->GetArtist());
820 __currentPlayContentDuration = __pCurrentAudioContentInfo->GetDuration();
821 if (__currentPlayContentDuration == null)
823 __currentPlayContentDuration = __pPlayer->GetDuration();
828 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
829 if (__pCurrentPlayContentTitle != null)
831 delete __pCurrentPlayContentTitle;
833 if (__pCurrentPlayContentArtist != null)
835 delete __pCurrentPlayContentArtist;
838 if (pAudioMeta == null)
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();
847 __pCurrentPlayContentTitle = new (std::nothrow) String(pAudioMeta->GetTitle());
848 if (__pCurrentPlayContentTitle == null)
850 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
853 __pCurrentPlayContentArtist = new (std::nothrow) String(pAudioMeta->GetArtist());
854 if (__pCurrentPlayContentArtist == null)
856 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
859 __pCurrentPlayContentThumbnail = pAudioMeta->GetThumbnailN();
860 if (__pCurrentPlayContentThumbnail == null)
862 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
865 __currentPlayContentDuration = pAudioMeta->GetDuration();
866 if (__currentPlayContentDuration == null)
868 __currentPlayContentDuration = __pPlayer->GetDuration();
877 /* IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
878 String* pFilePath = null;
883 while (pEnum->MoveNext() == E_SUCCESS)
885 pFilePath = static_cast<String*>(pEnum->GetCurrent());
887 if (pFilePath->Equals(*__pCurrentPlayContentPath))
889 __currentContentIndex = index;
898 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
900 CallOnPlayContentChanged(__currentContentIndex);
906 playerState = __pPlayer->GetState();
910 case PLAYER_STATE_PLAYING:
912 CallOnPlayContentChanged(__currentContentIndex);
916 case PLAYER_STATE_STOPPED:
918 case PLAYER_STATE_OPENED:
920 case PLAYER_STATE_PAUSED:
922 case PLAYER_STATE_ENDOFCLIP:
924 if (__pPauseAutoOffTimer != null)
926 r = __pPauseAutoOffTimer->Cancel();
927 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
929 if (__pPlayStateTimer != null)
931 __pPlayStateTimer->Cancel();
932 if (__pPlayer->GetDuration() < PROGRESS_BAR_DURATION_TIMER)
934 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER/10);
938 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
940 // r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
941 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..error %s\n",GetErrorMessage(r));
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)
949 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
950 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
951 __playposition = sliderPosition;
953 if (bPausePlay == false)
955 CallOnPlayContentChanged(__currentContentIndex);
958 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
959 // CallOnPlayTimeChanged(currentDuration, __playposition);
963 case PLAYER_STATE_ERROR:
965 AppLogDebug("PlayerState : %d", playerState);
967 TryCatch(r == E_SUCCESS, , "PLAYER_STATE_ERROR occured.\n");
971 case PLAYER_STATE_CLOSED:
973 case PLAYER_STATE_INITIALIZED:
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));
979 if ((__previousPlayerState == PLAYER_STATE_PLAYING) || (__previousPlayerState == PLAYER_STATE_ENDOFCLIP)
980 || (__previousPlayerState == PLAYER_STATE_INITIALIZED))
982 if (__pPauseAutoOffTimer != null)
984 r = __pPauseAutoOffTimer->Cancel();
985 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
987 if (__pPlayStateTimer != null)
989 r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
990 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed\n(%s)", GetErrorMessage(r));
994 r = __pPlayer->SetMute(true);
995 TryLog(r == E_SUCCESS,"__pPlayer->SetMute(true) failed with %s",GetErrorMessage(r));
997 r = __pPlayer->Play();
998 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
999 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
1001 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
1002 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
1003 __playposition = sliderPosition;
1005 __currentContentTotalDuration = __pPlayer->GetDuration();
1009 if (bPausePlay == false)
1011 CallOnPlayContentChanged(__currentContentIndex);
1014 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1015 // CallOnPlayTimeChanged(currentDuration, __playposition);
1019 case PLAYER_STATE_OPENING:
1028 CallOnPlayStateChanged(__pPlayer->GetState());
1029 AppLogDebug("EXIT");
1033 currentDuration = CommonUtil::GetFormatDate(MIN_SLIDER_COUNT);
1034 CallOnPlayTimeChanged(currentDuration,MIN_SLIDER_COUNT);
1035 CallOnPlayStateChanged(PLAYER_STATE_ERROR);
1041 PlayerPresentationModel::Pause(void)
1043 AppLogDebug("ENTER");
1044 if (__pPlayer == null)
1046 AppLogDebug("EXIT");
1050 result r = E_SUCCESS;
1051 PlayerState playerState = __pPlayer->GetState() ;
1052 AppLogDebug("%d", playerState);
1053 if (playerState == PLAYER_STATE_PLAYING)
1055 r = __pPlayer->Pause();
1056 TryCatch(r == E_SUCCESS, , "__pPlayer pause failed..%s\n",GetErrorMessage(r));
1058 if (__pPlayStateTimer != null)
1060 r = __pPlayStateTimer->Cancel();
1061 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer cancel failed..\n");
1063 if (__pPauseAutoOffTimer != null)
1065 /*__pPauseAutoOffTimer->Start(3000);*/
1066 r = __pPauseAutoOffTimer->Start(PAUSE_AUTO_OFF_TIME);
1067 TryCatch(r == E_SUCCESS, , "__pPauseAutoOffTimer start failed..\n");
1070 CallOnPlayStateChanged(__pPlayer->GetState());
1071 AppLogDebug("EXIT");
1075 //AppLogException("[%ls]", GetErrorMessage(r));
1080 PlayerPresentationModel::MovePreviousContent(bool forceMove)
1082 AppLogDebug("ENTER");
1083 if (__pPlayer == null)
1085 AppLogDebug("EXIT");
1089 result r = E_SUCCESS;
1090 String currentDuration = null;
1092 // if ((__pPlayer->GetState() == PLAYER_STATE_PLAYING || __pPlayer->GetState() == PLAYER_STATE_PAUSED) && (__playposition > MIN_REWIND_POSITION))
1093 if (__playposition > MIN_REWIND_POSITION && forceMove != true)
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");
1105 __isForceChanged = true;
1109 // InitializeProgress();
1110 // InitializePlayer();
1111 /* if(IsShuffleEnable())
1113 srand(int(time(NULL)));
1114 __currentContentIndex = rand() % __pPlayContentList->GetCount();
1118 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1120 __currentContentIndex = __pPlayContentList->GetCount() - 1;
1124 __currentContentIndex--;
1127 __removedContentIndex = INIT_CONTENT_INDEX;
1130 __currentContentIndex = __previousContentIndex;
1131 GenerateNextIndex();
1132 __removedContentIndex = INIT_CONTENT_INDEX;
1134 if (__pPlayContentList->GetCount() > 0)
1136 CallOnPlayContentChanged(__currentContentIndex);
1137 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1139 __seekCompleted = false;
1140 Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
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();
1148 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1150 AppLogDebug("EXIT");
1154 //AppLogException("[%s]", GetErrorMessage(r));
1159 PlayerPresentationModel::MoveNextContent(void)
1161 AppLogDebug("ENTER");
1162 if (__pPlayer == null)
1164 AppLogDebug("EXIT");
1167 __currentContentIndex = __nextContentIndex;
1168 GenerateNextIndex();
1169 __removedContentIndex = INIT_CONTENT_INDEX;
1170 __isForceChanged = true;
1171 if (__pPlayContentList->GetCount() > 0)
1173 CallOnPlayContentChanged(__currentContentIndex);
1175 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1177 __seekCompleted = false;
1178 Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
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();
1186 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1188 AppLogDebug("EXIT");
1193 PlayerPresentationModel::SeekToRewind(void)
1195 AppLogDebug("ENTER");
1196 int playDuration = __pPlayer->GetDuration();
1197 if(playDuration != 0)
1199 //__playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1200 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1203 AppLogDebug("EXIT");
1207 PlayerPresentationModel::Rewind(void)
1209 AppLogDebug("ENTER");
1211 __pPlayStateTimer->Cancel();
1212 __playposition = __playposition - __xTimesValue;
1213 result r = SetPlayPosition(__playposition);
1216 StopForwardRewind();
1220 if (__playposition < MIN_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1222 StopForwardRewind();
1226 if (__pFastRewindTimer != null)
1228 r = __pFastRewindTimer->Start(PROGRESS_TIMER_DURATION);
1229 TryCatch(r == E_SUCCESS, , "__pFastRewindTimer start failed. [%ls]", GetErrorMessage(r));
1232 AppLogDebug("EXIT");
1236 //AppLogException("[%ls]", GetErrorMessage(r));
1241 PlayerPresentationModel::SeekToForward(void)
1243 AppLogDebug("ENTER");
1244 int playDuration = __pPlayer->GetDuration();
1245 if(playDuration != 0)
1247 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1250 AppLogDebug("EXIT");
1254 PlayerPresentationModel::Forward(void)
1256 AppLogDebug("ENTER");
1258 __pPlayStateTimer->Cancel();
1259 __playposition = __playposition - __xTimesValue;
1260 result r = SetPlayPosition(__playposition);
1263 AppLogDebug("SetPlayPosition Failed %s",GetErrorMessage(r));
1264 StopForwardRewind();
1268 if (__playposition > MAX_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1270 StopForwardRewind();
1274 if (__pFastForwardTimer != null)
1276 r = __pFastForwardTimer->Start(PROGRESS_TIMER_DURATION);
1277 TryCatch(r == E_SUCCESS, , "__pFastForwardTimer start failed. [%ls]", GetErrorMessage(r));
1280 AppLogDebug("EXIT");
1284 //AppLogException("[%ls]", GetErrorMessage(r));
1289 PlayerPresentationModel::StopForwardRewind(void)
1291 AppLogDebug("ENTER");
1292 result r = E_SUCCESS;
1294 if (__pFastForwardTimer != null)
1296 r = __pFastForwardTimer->Cancel();
1297 TryLog(r == E_SUCCESS, "[%s] __pFastForwardTimer cancel failed", GetErrorMessage(r));
1300 if (__pFastRewindTimer != null)
1302 r = __pFastRewindTimer->Cancel();
1303 TryLog(r == E_SUCCESS, "[%s] __pFastRewindTimer cancel failed", GetErrorMessage(r));
1306 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
1307 __xTimesValue = INIT_X_VALUE;
1308 __seekCompleted = true;
1309 AppLogDebug("EXIT");
1314 PlayerPresentationModel::SetPlayPosition(int playPosition)
1316 AppLogDebug("ENTER %d",playPosition);
1317 if (__pPlayer == null)
1319 AppLogDebug("EXIT");
1323 result r = E_SUCCESS;
1324 String currentDuration = null;
1325 if (/*(playPosition >= MIN_SLIDER_COUNT) && (playPosition <= TIMER_INTERVAL) &&*/ __seekCompleted == true)
1327 if (GetPlayerState() == PLAYER_STATE_PLAYING || GetPlayerState() == PLAYER_STATE_PAUSED || GetPlayerState() == PLAYER_STATE_OPENED)
1329 if (playPosition >= MAX_SLIDER_COUNT)
1331 r = __pPlayer->SeekTo(__pPlayer->GetDuration());
1332 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1333 // StopForwardRewind();
1334 // __seekCompleted = false;
1337 else if (playPosition <= MIN_SLIDER_COUNT)
1339 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1340 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
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");
1349 TryCatch(r == E_SUCCESS, r = E_FAILURE, "Unable to seek to.\n");
1351 __playposition = playPosition;
1352 //currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1353 //CallOnPlayTimeChanged(currentDuration, __playposition);
1354 __seekCompleted = false;
1358 // __playposition = playPosition;
1359 // currentDuration = CommonUtil::GetFormatDate(playPosition * (__currentPlayContentDuration / TIMER_INTERVAL));
1360 // CallOnPlayTimeChanged(currentDuration, __playposition);
1361 __seekCompleted = true;
1365 AppLogDebug("EXIT");
1369 //AppLogException( "[%s]", GetErrorMessage(r));
1370 if (__pPlayer->GetDuration() > MIN_SLIDER_COUNT)
1372 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1373 CallOnPlayTimeChanged(currentDuration, __playposition);
1375 __seekCompleted = false;
1376 AppLogDebug("EXIT");
1381 PlayerPresentationModel::GetPlayPosition(void)
1383 AppLogDebug("ENTER");
1384 AppLogDebug("EXIT");
1385 return __playposition;
1389 PlayerPresentationModel::GetCurrentDuration(void)
1391 AppLogDebug("ENTER");
1392 String currentDuration;
1393 if (__pPlayer != null)
1395 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1399 currentDuration = CommonUtil::GetFormatDate(INIT_VALUE);
1401 AppLogDebug("EXIT");
1402 return currentDuration;
1406 PlayerPresentationModel::SetContentList(IList* pArgs)
1408 AppLogDebug("ENTER");
1409 TryReturn( pArgs != null && pArgs->GetCount() > 0, E_INVALID_ARG, "Invalid arguments");
1410 result r = E_SUCCESS;
1411 String* temp = null;
1413 if (__pPlayContentList == null)
1415 __pPlayContentList = new (std::nothrow) ArrayList();
1416 TryCatch(__pPlayContentList != null, r = E_OUT_OF_MEMORY, "Unable to create ArrayList.\n");
1418 r = __pPlayContentList->Construct();
1419 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Construct ArrayList.\n");
1423 __pPlayContentList->RemoveAll(true);
1426 temp = static_cast<String*>(pArgs->GetAt(0));
1427 if (temp->Equals(MUSIC, true))
1429 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(2));
1430 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1432 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1436 while (pEnum->MoveNext() == E_SUCCESS)
1438 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1439 AppLogDebug("%ls", pContentPath->GetPointer());
1440 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1447 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(0));
1448 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1450 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1453 while (pEnum->MoveNext() == E_SUCCESS)
1455 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1456 AppLogDebug("%ls", pContentPath->GetPointer());
1457 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1464 AppLogDebug("EXIT");
1468 //AppLogException("[%s].\n",GetErrorMessage(r));
1469 if (__pPlayContentList != null)
1471 delete __pPlayContentList;
1472 __pPlayContentList = null;
1478 PlayerPresentationModel::GetContentListCount(void)const
1480 AppLogDebug("ENTER");
1481 if (__pPlayContentList != null)
1483 AppLogDebug("EXIT");
1484 return __pPlayContentList->GetCount();
1488 AppLogDebug("EXIT");
1494 PlayerPresentationModel::SetVolume(int volume)
1496 AppLogDebug("ENTER");
1497 String key(MEDIA_VOLUME);
1498 result r = E_SUCCESS;
1500 if (__pVolumeBarStateTimer != null)
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");
1508 if (volume >= 0 && volume <= 15)
1510 SettingInfo::SetValue(key, volume);
1512 AppLogDebug("EXIT");
1516 //AppLogException("[%ls]", GetErrorMessage(r));
1521 PlayerPresentationModel::GetVolume(void)
1523 AppLogDebug("ENTER");
1525 String key(MEDIA_VOLUME);
1526 SettingInfo::GetValue(key, volume);
1527 AppLogDebug("EXIT");
1532 PlayerPresentationModel::SetShuffleEnable(bool shuffleEnable)
1534 AppLogDebug("ENTER");
1535 /* int __totalCount = 0;
1537 if (__pPlayContentList != null)
1539 __totalCount = __pPlayContentList->GetCount();
1542 if (shuffleEnable == true)
1547 srand(int(time(NULL)));
1548 for (int i = 0; i < __totalCount; i++)
1550 nDust = rand() % __totalCount;
1551 nSour = rand() % __totalCount;
1553 nTemp = __pPlayContentIndexOrder[nDust];
1554 __pPlayContentIndexOrder[nDust] = __pPlayContentIndexOrder[nSour];
1555 __pPlayContentIndexOrder[nSour] = nTemp;
1558 for (int i = 0; i < __totalCount; i++)
1560 if (__pPlayContentIndexOrder[i] - 1 == __currentContentIndex)
1562 nTemp = __pPlayContentIndexOrder[i];
1563 __pPlayContentIndexOrder[i] = __pPlayContentIndexOrder[__currentContentIndex];
1564 __pPlayContentIndexOrder[__currentContentIndex] = nTemp;
1570 int currentIndex = __currentContentIndex;
1571 __currentContentIndex = __pPlayContentIndexOrder[currentIndex] - 1;
1572 for (int i=0; i<__totalCount; i++)
1574 __pPlayContentIndexOrder[i]=i + 1;
1577 __shuffleEnable = shuffleEnable;
1578 GenerateNextIndex();
1579 AppLogDebug("EXIT");
1583 PlayerPresentationModel::SetRepeatMode(int repeatMode)
1585 AppLogDebug("ENTER");
1586 __repeatMode = repeatMode;
1587 AppLogDebug("EXIT");
1591 PlayerPresentationModel::IsShuffleEnable(void)
1593 AppLogDebug("ENTER");
1594 AppLogDebug("EXIT");
1595 return __shuffleEnable;
1599 PlayerPresentationModel::IsFileExist(int contentIndex) const
1601 AppLogDebug("ENTER");
1602 TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), false, "contentIndex is invalid.")
1603 String* pFilePath = GetContentPath(contentIndex);
1607 result r = file.Construct(*pFilePath, "r");
1608 TryReturn(r == E_SUCCESS, false, "File construct was failed.")
1610 AppLogDebug("EXIT");
1611 return file.IsFileExist(*pFilePath);
1615 PlayerPresentationModel::GetRepeatState(void)
1617 AppLogDebug("ENTER");
1618 AppLogDebug("EXIT");
1619 return __repeatMode;
1623 PlayerPresentationModel::GetFileName(String* pFilePath)
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;
1633 path.Remove(removeIndex, strRemoveTemp.GetLength() + 1);
1634 path.SubString(0, strTemp);
1635 AppLogDebug("EXIT");
1640 PlayerPresentationModel::InitializeProgress(void)
1642 AppLogDebug("ENTER");
1643 result r = E_SUCCESS;
1645 String currentDuration = null;
1646 if (__pPlayer != null)
1648 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1652 currentDuration = INITIAL_TIME;
1655 if (__pPlayStateTimer != null /*&& __previousPlayerState != PLAYER_STATE_INITIALIZED*/
1656 && __previousPlayerState != PLAYER_STATE_PAUSED
1657 && __previousPlayerState != PLAYER_STATE_CLOSED)
1659 r = __pPlayStateTimer->Cancel();
1660 TryLog(r == E_SUCCESS, "[%s] __pPlayStateTimer cancel failed.", GetErrorMessage(r));
1662 __playposition = MIN_SLIDER_COUNT;
1663 // __seekCompleted = true;
1664 __xTimesValue = INIT_VALUE;
1665 //CallOnPlayTimeChanged(currentDuration, __playposition);
1666 AppLogDebug("EXIT");
1671 PlayerPresentationModel::UpdateContentDB(void)
1673 AppLogDebug("ENTER");
1674 result r = E_SUCCESS;
1676 String contentIdString;
1677 ArrayList* pTempList = null;
1679 Tizen::Base::String contentPath = *static_cast<String*>(__pPlayContentList->GetAt(__currentContentIndex));
1680 if (File::IsFileExist(contentPath) == false)
1682 AppLogDebug("File not exist(%ls)", contentPath.GetPointer());
1686 ContentId contentId = CommonUtil::GetContentId(contentPath);
1687 if (IsFailed(GetLastResult()))
1689 AppLogDebug("CommonUtil::GetContentId(%ls) failed", contentPath.GetPointer());
1694 Tizen::System::SystemTime::GetCurrentTime(Tizen::System::TIME_MODE_STANDARD, playTime);
1695 Tizen::Base::String playTimeString = playTime.ToString();
1697 PlaylistDB* pPlaylistDB = new (std::nothrow) PlaylistDB();
1698 r = pPlaylistDB->CreatePlaylistDatabase();
1699 TryCatch(r == E_SUCCESS,,"CreatePlaylistDatabase() failed with error %s",GetErrorMessage(r));
1701 // pTempList = new (std::nothrow) ArrayList();
1702 // pTempList->Construct();
1704 contentIdString = contentId.ToString();
1705 if (pPlaylistDB->Read(contentIdString) != E_KEY_ALREADY_EXIST)
1707 pPlaylistDB->Insert(contentIdString, playCount + 1, playTimeString);
1711 pTempList = pPlaylistDB->ReadValueN(contentIdString);
1712 if (pTempList != null)
1714 playCount = static_cast<Integer*>(pTempList->GetAt(0))->ToInt();
1716 pPlaylistDB->Update(contentIdString, playCount + 1, playTimeString);
1721 if (pPlaylistDB != null)
1727 if (pTempList != null)
1729 pTempList->RemoveAll(true);
1733 AppLogDebug("EXIT");
1737 PlayerPresentationModel::GenerateNextIndex(void)
1739 AppLogDebug("ENTER");
1740 if (IsShuffleEnable())
1742 int totalCount = __pPlayContentList->GetCount();
1746 __previousContentIndex = 0;
1747 __nextContentIndex = 0;
1751 srand(int(time(NULL)));
1752 __previousContentIndex = rand() % totalCount;
1753 while (__previousContentIndex == __currentContentIndex)
1755 __previousContentIndex = rand() % totalCount;
1758 __nextContentIndex = rand() % totalCount;
1759 while (__nextContentIndex == __currentContentIndex)
1761 __nextContentIndex = rand() % totalCount;
1767 if (__pPlayContentList->GetCount() == 0)
1769 __previousContentIndex = 0;
1770 __nextContentIndex = 0;
1774 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1776 __previousContentIndex = __pPlayContentList->GetCount() - 1;
1780 __previousContentIndex = __currentContentIndex - 1;
1783 if (__currentContentIndex == __pPlayContentList->GetCount() - 1
1784 || __removedContentIndex == __pPlayContentList->GetCount())
1786 __nextContentIndex = 0;
1790 if (__removedContentIndex != INIT_CONTENT_INDEX)
1792 __nextContentIndex = __previousContentIndex + 1;
1793 if (__nextContentIndex > __pPlayContentList->GetCount() - 1)
1795 __nextContentIndex = 0;
1800 __nextContentIndex = __currentContentIndex + 1;
1804 AppLogDebug("EXIT");
1808 PlayerPresentationModel::OnPlayerOpened(result r)
1810 AppLogDebug("ENTER");
1811 AppLogDebug("EXIT");
1815 PlayerPresentationModel::OnPlayerReleased(void)
1817 AppLogDebug("ENTER");
1818 if (__pPlayer != null && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1820 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1822 AppLogDebug("EXIT");
1826 PlayerPresentationModel::OnPlayerEndOfClip(void)
1828 AppLogDebug("ENTER");
1829 // StopForwardRewind();
1831 if (__pPlayer == null)
1833 AppLogDebug("EXIT");
1836 __seekCompleted = true;
1837 AppLogDebug("GetRepeatState() : %d", GetRepeatState());
1839 String totalDuration = CommonUtil::GetFormatDate(__currentContentTotalDuration);
1840 AppLogDebug("totalDuration(%ls), __currentContentTotalDuration(%d)", totalDuration.GetPointer(), __currentContentTotalDuration);
1841 CallOnPlayTimeChanged(totalDuration, MAX_SLIDER_COUNT);
1843 switch (GetRepeatState())// 0 - 2 (OFF, ONE, ALL)
1847 AppLogDebug("Repeat State(%d)", 1);
1848 while (__pPlayContentList->GetCount() > 0 && IsFileExist(__currentContentIndex) == false)
1850 RemoveContent(*GetContentPath(__currentContentIndex));
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)
1856 StopForwardRewind();
1857 InitializeProgress();
1858 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1863 InitializeProgress();
1865 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1871 AppLogDebug("Repeat State(%d)", 0);
1872 if (__pPlayContentList->GetCount() - 1 == __currentContentIndex)
1874 StopForwardRewind();
1875 InitializeProgress();
1876 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1881 while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1883 RemoveContent(*GetContentPath(GetNextContentIndex()));
1886 InitializeProgress();
1887 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1894 AppLogDebug("Repeat State(%d)", 2);
1896 while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1898 RemoveContent(*GetContentPath(GetNextContentIndex()));
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)
1904 StopForwardRewind();
1905 InitializeProgress();
1906 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1911 InitializeProgress();
1912 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1919 AppLogDebug("EXIT");
1923 PlayerPresentationModel::OnPlayerBuffering(int percent)
1925 AppLogDebug("ENTER");
1926 if (__pPlayer == null)
1928 AppLogDebug("EXIT");
1931 CallOnPlayStateChanged(__pPlayer->GetState());
1932 AppLogDebug("EXIT");
1936 PlayerPresentationModel::OnPlayerErrorOccurred(PlayerErrorReason r)
1938 AppLogDebug("ENTER");
1939 if (__pPlayer == null)
1941 AppLogDebug("EXIT");
1944 CallOnPlayStateChanged(__pPlayer->GetState());
1945 AppLogDebug("EXIT");
1949 PlayerPresentationModel::OnPlayerInterrupted(void)
1951 AppLogDebug("ENTER");
1953 AppLogDebug("EXIT");
1958 PlayerPresentationModel::OnPlayerSeekCompleted(result r)
1960 AppLogDebug("ENTER %s",GetErrorMessage(r));
1963 __seekCompleted = true;
1967 __seekCompleted = false;
1970 String currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1971 CallOnPlayTimeChanged(currentDuration, __playposition);
1972 AppLogDebug("EXIT current duration %ls",currentDuration.GetPointer());
1976 PlayerPresentationModel::OnPlayerAudioFocusChanged(void)
1978 AppLogDebug("ENTER");
1979 /*__audioFocusChanged = true;*/
1981 AppLogDebug("EXIT");
1985 PlayerPresentationModel::OnAudioSessionInterrupted(void)
1987 AppLogDebug("ENTER");
1988 AppLogDebug("EXIT");
1992 PlayerPresentationModel::OnAudioSessionInterruptReleased(void)
1994 AppLogDebug("ENTER");
1995 AppLogDebug("EXIT");
1999 PlayerPresentationModel::OnAudioSessionAudioFocusChanged(void)
2001 AppLogDebug("ENTER");
2002 AppLogDebug("EXIT");
2006 PlayerPresentationModel::OnTimerExpired(Timer& timer)
2008 // AppLogDebug("ENTER");
2009 if (__pPlayer == null)
2011 AppLogDebug("EXIT player is null");
2015 result r = E_SUCCESS;
2016 if (__pPlayStateTimer == &timer)
2018 PlayerState playerState = __pPlayer->GetState() ;
2019 String currentDuration = null;
2020 int playDuration = __pPlayer->GetDuration();
2021 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2023 switch (playerState)
2025 case PLAYER_STATE_PLAYING:
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.");
2031 if ( playDuration < 2000)
2033 currentDuration = CommonUtil::GetFormatDate(playDuration);
2034 CallOnPlayTimeChanged(currentDuration, TIMER_INTERVAL);
2038 if (playDuration < PROGRESS_BAR_DURATION_TIMER)
2040 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER/10);
2044 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
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);
2051 if (__pPlayer->GetPosition() <= playDuration)
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);
2061 case PLAYER_STATE_PAUSED:
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);
2075 else if (__pFastForwardTimer == &timer)
2080 else if (__pFastRewindTimer == &timer)
2085 else if (__pAutoOffTimer == &timer)
2087 Application::GetInstance()->Terminate();
2089 else if (__pPauseAutoOffTimer == &timer)
2091 Application::GetInstance()->Terminate();
2093 else if (__pVolumeBarStateTimer == &timer)
2095 r = __pVolumeBarStateTimer->Cancel();
2096 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel Failed.", GetErrorMessage(r));
2097 CallOnPlayVolumeBarStateChanged();
2101 //AppLogDebug("Timer is invalid value.");
2103 // AppLogDebug("EXIT");
2108 //AppLogException("[%ls]", GetErrorMessage(r));
2113 PlayerPresentationModel::AddMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2115 AppLogDebug("ENTER");
2116 __musicPlayerEventListener.Add(const_cast<IMusicPlayerEventListener*>(&listener));
2117 AppLogDebug("EXIT");
2121 PlayerPresentationModel::RemoveMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2123 AppLogDebug("ENTER");
2124 __musicPlayerEventListener.Remove(const_cast<IMusicPlayerEventListener*>(&listener));
2125 AppLogDebug("EXIT");
2129 PlayerPresentationModel::CallOnPlayStateChanged(PlayerState playerState)
2131 AppLogDebug("ENTER");
2132 IMusicPlayerEventListener* pListener = null;
2133 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2134 while (pEnum->MoveNext() == E_SUCCESS)
2136 pEnum->GetCurrent(pListener);
2137 if (pListener != null)
2139 pListener->OnPlayStateChanged(playerState);
2143 AppLogDebug("EXIT");
2147 PlayerPresentationModel::CallOnPlayContentChanged(int currentContentIndex)
2149 AppLogDebug("ENTER");
2150 IMusicPlayerEventListener* pListener = null;
2151 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2152 while (pEnum->MoveNext() == E_SUCCESS)
2154 pEnum->GetCurrent(pListener);
2155 if (pListener != null)
2157 pListener->OnPlayContentChanged(currentContentIndex);
2161 AppLogDebug("EXIT");
2165 PlayerPresentationModel::CallOnPlayContentRemoved(int removedContentIndex)
2167 AppLogDebug("ENTER");
2168 IMusicPlayerEventListener* pListener = null;
2169 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2170 while (pEnum->MoveNext() == E_SUCCESS)
2172 pEnum->GetCurrent(pListener);
2173 if (pListener != null)
2175 pListener->OnPlayContentRemoved(removedContentIndex);
2179 AppLogDebug("EXIT");
2183 PlayerPresentationModel::CallOnPlayTimeChanged(Tizen::Base::String& currentDuration, int currentPosition)
2185 // AppLogDebug("ENTER");
2186 IMusicPlayerEventListener* pListener = null;
2187 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2188 while (pEnum->MoveNext() == E_SUCCESS)
2190 pEnum->GetCurrent(pListener);
2191 if (pListener != null)
2193 pListener->OnPlayTimeChanged(currentDuration, currentPosition);
2197 // AppLogDebug("EXIT");
2201 PlayerPresentationModel::CallOnPlayVolumeBarStateChanged(void)
2203 AppLogDebug("ENTER");
2204 IMusicPlayerEventListener* pListener = null;
2205 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2206 while (pEnum->MoveNext() == E_SUCCESS)
2208 pEnum->GetCurrent(pListener);
2209 if (pListener != null)
2211 pListener->OnPlayVolumeBarStateChanged();
2215 AppLogDebug("EXIT");
2219 PlayerPresentationModel::CallOnPlayPresentationModelDestroying(void)
2221 AppLogDebug("ENTER");
2222 IMusicPlayerEventListener* pListener = null;
2223 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2224 while (pEnum->MoveNext() == E_SUCCESS)
2226 pEnum->GetCurrent(pListener);
2227 if (pListener != null)
2229 pListener->OnPlayPresentationModelDestroying();
2233 AppLogDebug("EXIT");