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 || callStatus == CALL_STATUS_DIALING)
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 Tizen::Base::String* contentPath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
621 if (contentPath == null || File::IsFileExist(*contentPath) == false)
627 ContentInformation* pContentInfo = new (std::nothrow) ContentInformation();
628 TryReturn(pContentInfo != null, null, "pContentInfo is null.");
630 pAudioContentInfo = CommonUtil::GetAudioContentInfoN(*contentPath);
632 if (pAudioContentInfo != null)
634 if (pAudioContentInfo->GetArtist() == null)
636 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
640 pContentInfo->ArtistName = pAudioContentInfo->GetArtist();
643 if (pAudioContentInfo->GetTitle() == null)
645 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
649 pContentInfo->TitleName = pAudioContentInfo->GetTitle();
652 if (__pPlayer != null)
654 pContentInfo->Duration = __pPlayer->GetDuration();
658 pContentInfo->Duration = pAudioContentInfo->GetDuration();
660 pContentInfo->contentId = pAudioContentInfo->GetContentId();
662 if (pAudioContentInfo != __pCurrentAudioContentInfo)
664 delete pAudioContentInfo;
669 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
670 if (pAudioMeta == null)
676 if (pAudioMeta->GetArtist() == null)
678 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
682 pContentInfo->ArtistName = pAudioMeta->GetArtist();
685 if (pAudioMeta->GetTitle() == null)
687 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
691 pContentInfo->TitleName = pAudioMeta->GetTitle();
694 if (__pPlayer != null)
696 pContentInfo->Duration = __pPlayer->GetDuration();
698 pContentInfo->contentId = *__pUuIdForFileOnly;
706 Tizen::Graphics::Bitmap*
707 PlayerPresentationModel::GetContentAlbumArtN(int contentIndex)
709 AppLogDebug("ENTER");
710 Bitmap* pAlbumArtBitmap = null;
711 if (contentIndex <= -1)
713 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
715 return pAlbumArtBitmap;
718 String* path = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
721 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
723 return pAlbumArtBitmap;
726 pAlbumArtBitmap = CommonUtil::GetContentAlbumArtN(*path);
727 if (pAlbumArtBitmap == null)
729 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
732 return pAlbumArtBitmap;
736 PlayerPresentationModel::Play(int contentIndex, int sliderPosition, bool bPausePlay, bool bPlayPause)
738 AppLogDebug("ENTER");
739 result r = E_SUCCESS;
741 if (__pPlayer == null)
747 __seekCompleted = true;
748 /* if (__seekCompleted == false)
754 PlayerState playerState;
755 String currentDuration;
756 String* pPath = null;
758 if (bPausePlay == false)
760 if (GetContentListCount() == 0)
763 InitializeProgress();
765 TryCatch(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), , "contentIndex is invalid");
766 pPath = GetContentPath(contentIndex);
767 AppLogDebug("__pCurrentPlayContentPath = %ls", __pCurrentPlayContentPath->GetPointer());
768 if (__pPlayer->GetState() == PLAYER_STATE_ENDOFCLIP
769 || pPath->Equals(*__pCurrentPlayContentPath) == false || __currentContentIndex != contentIndex || __isForceChanged)
771 __isForceChanged = false;
773 InitializeProgress();
775 __previousPlayerState = PLAYER_STATE_INITIALIZED;
776 __currentContentIndex = contentIndex;
778 __pCurrentPlayContentPath->Clear();
779 __pCurrentPlayContentPath->Append(pPath->GetPointer());
781 if (__pCurrentAudioContentInfo != null)
783 delete __pCurrentAudioContentInfo;
784 __pCurrentAudioContentInfo = null;
787 __pCurrentAudioContentInfo = CommonUtil::GetAudioContentInfoN(*(__pCurrentPlayContentPath));
789 if (__pCurrentAudioContentInfo != null)
791 if (__pCurrentPlayContentTitle != null)
793 delete __pCurrentPlayContentTitle;
795 if(__pCurrentPlayContentThumbnail != null)
797 delete __pCurrentPlayContentThumbnail;
800 __pCurrentPlayContentTitle = new (std::nothrow) String(__pCurrentAudioContentInfo->GetTitle());
801 __pCurrentPlayContentThumbnail = __pCurrentAudioContentInfo->GetThumbnailN();
802 if (__pCurrentPlayContentThumbnail == null)
804 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
807 if (__pCurrentPlayContentArtist != null)
809 delete __pCurrentPlayContentArtist;
811 __pCurrentPlayContentArtist = new (std::nothrow) String(__pCurrentAudioContentInfo->GetArtist());
812 __currentPlayContentDuration = __pCurrentAudioContentInfo->GetDuration();
813 if (__currentPlayContentDuration == null)
815 __currentPlayContentDuration = __pPlayer->GetDuration();
820 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
821 if (__pCurrentPlayContentTitle != null)
823 delete __pCurrentPlayContentTitle;
825 if (__pCurrentPlayContentArtist != null)
827 delete __pCurrentPlayContentArtist;
830 if (pAudioMeta == null)
832 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
833 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
834 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
835 __currentPlayContentDuration = __pPlayer->GetDuration();
839 __pCurrentPlayContentTitle = new (std::nothrow) String(pAudioMeta->GetTitle());
840 if (__pCurrentPlayContentTitle == null)
842 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
845 __pCurrentPlayContentArtist = new (std::nothrow) String(pAudioMeta->GetArtist());
846 if (__pCurrentPlayContentArtist == null)
848 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
851 __pCurrentPlayContentThumbnail = pAudioMeta->GetThumbnailN();
852 if (__pCurrentPlayContentThumbnail == null)
854 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
857 __currentPlayContentDuration = pAudioMeta->GetDuration();
858 if (__currentPlayContentDuration == null)
860 __currentPlayContentDuration = __pPlayer->GetDuration();
869 /* IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
870 String* pFilePath = null;
875 while (pEnum->MoveNext() == E_SUCCESS)
877 pFilePath = static_cast<String*>(pEnum->GetCurrent());
879 if (pFilePath->Equals(*__pCurrentPlayContentPath))
881 __currentContentIndex = index;
890 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
892 CallOnPlayContentChanged(__currentContentIndex);
898 playerState = __pPlayer->GetState();
902 case PLAYER_STATE_PLAYING:
904 CallOnPlayContentChanged(__currentContentIndex);
908 case PLAYER_STATE_STOPPED:
910 case PLAYER_STATE_OPENED:
912 case PLAYER_STATE_PAUSED:
914 case PLAYER_STATE_ENDOFCLIP:
916 if (__pPauseAutoOffTimer != null)
918 r = __pPauseAutoOffTimer->Cancel();
919 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
922 AppLogDebug("%d", __pPlayer->GetState());
923 r = __pPlayer->Play();
924 TryCatch(r == E_SUCCESS, , "Play failed(%s)", GetErrorMessage(r));
925 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
927 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
928 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
929 __playposition = sliderPosition;
931 if (bPausePlay == false)
933 CallOnPlayContentChanged(__currentContentIndex);
935 if (__pPlayStateTimer != null)
937 __pPlayStateTimer->Cancel();
938 r = __pPlayStateTimer->Start(MESSAGE_BOX_DELAY/2);
939 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..error %s\n",GetErrorMessage(r));
941 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
942 // CallOnPlayTimeChanged(currentDuration, __playposition);
946 case PLAYER_STATE_ERROR:
948 AppLogDebug("PlayerState : %d", playerState);
950 TryCatch(r == E_SUCCESS, , "PLAYER_STATE_ERROR occured.\n");
954 case PLAYER_STATE_CLOSED:
956 case PLAYER_STATE_INITIALIZED:
958 TryCatch(__pPlayer != null && pPath != null, r = E_FAILURE, "Player is not initialized or pPath is null.");
959 r = __pPlayer->OpenFile(*pPath);
960 TryCatch(r == E_SUCCESS, , "[%ls] OpenFile failed\n(%s).", pPath->GetPointer(), GetErrorMessage(r));
962 if ((__previousPlayerState == PLAYER_STATE_PLAYING) || (__previousPlayerState == PLAYER_STATE_ENDOFCLIP)
963 || (__previousPlayerState == PLAYER_STATE_INITIALIZED))
965 if (__pPauseAutoOffTimer != null)
967 r = __pPauseAutoOffTimer->Cancel();
968 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
972 r = __pPlayer->SetMute(true);
973 TryLog(r == E_SUCCESS,"__pPlayer->SetMute(true) failed with %s",GetErrorMessage(r));
975 r = __pPlayer->Play();
976 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
977 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
979 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
980 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
981 __playposition = sliderPosition;
983 __currentContentTotalDuration = __pPlayer->GetDuration();
984 if (__pPlayStateTimer != null)
986 __pPlayStateTimer->Cancel();
987 r = __pPlayStateTimer->Start(MESSAGE_BOX_DELAY/2);
988 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed\n(%s)", GetErrorMessage(r));
992 r = UpdateContentDB();
993 if (r == E_STORAGE_FULL)
995 int messageResult = 0;
996 MessageBox messageBox;
997 messageBox.Construct(L"",IDS_STORAGE_FULL,MSGBOX_STYLE_NONE,COUNT_MESSAGE_BOX_TIMEOUT);
998 messageBox.ShowAndWait(messageResult);
999 App::GetInstance()->Terminate();
1002 if (bPausePlay == false)
1004 CallOnPlayContentChanged(__currentContentIndex);
1005 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1006 CallOnPlayTimeChanged(currentDuration, sliderPosition);
1011 case PLAYER_STATE_OPENING:
1020 CallOnPlayStateChanged(__pPlayer->GetState());
1021 AppLogDebug("EXIT");
1025 currentDuration = CommonUtil::GetFormatDate(MIN_SLIDER_COUNT);
1026 CallOnPlayTimeChanged(currentDuration,MIN_SLIDER_COUNT);
1027 CallOnPlayStateChanged(PLAYER_STATE_ERROR);
1028 StopForwardRewind();
1033 PlayerPresentationModel::Pause(void)
1035 AppLogDebug("ENTER");
1036 if (__pPlayer == null)
1038 AppLogDebug("EXIT");
1042 result r = E_SUCCESS;
1043 PlayerState playerState = __pPlayer->GetState() ;
1044 AppLogDebug("%d", playerState);
1045 if (playerState == PLAYER_STATE_PLAYING)
1047 r = __pPlayer->Pause();
1048 TryCatch(r == E_SUCCESS, , "__pPlayer pause failed..%s\n",GetErrorMessage(r));
1050 if (__pPlayer->GetState() == PLAYER_STATE_PAUSED)
1052 if (__pPlayStateTimer != null)
1054 r = __pPlayStateTimer->Cancel();
1055 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer cancel failed..\n");
1057 if (__pPauseAutoOffTimer != null)
1059 /*__pPauseAutoOffTimer->Start(3000);*/
1060 r = __pPauseAutoOffTimer->Start(PAUSE_AUTO_OFF_TIME);
1061 TryCatch(r == E_SUCCESS, , "__pPauseAutoOffTimer start failed..\n");
1064 CallOnPlayStateChanged(__pPlayer->GetState());
1065 AppLogDebug("EXIT");
1069 //AppLogException("[%ls]", GetErrorMessage(r));
1073 void PlayerPresentationModel::Mute(const bool isMute)
1075 AppLogDebug("ENTER");
1076 if (__pPlayer == null)
1078 AppLogDebug("EXIT");
1081 __pPlayer->SetMute(isMute);
1082 AppLogDebug("EXIT");
1086 PlayerPresentationModel::MovePreviousContent(bool forceMove)
1088 AppLogDebug("ENTER");
1089 if (__pPlayer == null)
1091 AppLogDebug("EXIT");
1095 result r = E_SUCCESS;
1096 String currentDuration;
1098 // if ((__pPlayer->GetState() == PLAYER_STATE_PLAYING || __pPlayer->GetState() == PLAYER_STATE_PAUSED) && (__playposition > MIN_REWIND_POSITION))
1099 if (__playposition > MIN_REWIND_POSITION && forceMove != true)
1101 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1102 TryCatch(r == E_SUCCESS, , "SeekTo failed. [%ls]", GetErrorMessage(r));
1103 __playposition = MIN_SLIDER_COUNT;
1104 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1105 CallOnPlayTimeChanged(currentDuration, __playposition);
1106 AppLogDebug("EXIT");
1111 __isForceChanged = true;
1115 // InitializeProgress();
1116 // InitializePlayer();
1117 /* if(IsShuffleEnable())
1119 srand(int(time(NULL)));
1120 __currentContentIndex = rand() % __pPlayContentList->GetCount();
1124 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1126 __currentContentIndex = __pPlayContentList->GetCount() - 1;
1130 __currentContentIndex--;
1133 __removedContentIndex = INIT_CONTENT_INDEX;
1136 __currentContentIndex = __previousContentIndex;
1137 GenerateNextIndex();
1138 __removedContentIndex = INIT_CONTENT_INDEX;
1140 if (__pPlayContentList->GetCount() > 0)
1142 CallOnPlayContentChanged(__currentContentIndex);
1143 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1145 __seekCompleted = false;
1146 Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
1148 __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1149 //need to unmute the player as it is mute in case of moved next in pause state
1150 __pPlayer->SetMute(false);
1151 InitializeProgress();
1154 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1156 AppLogDebug("EXIT");
1160 //AppLogException("[%s]", GetErrorMessage(r));
1165 PlayerPresentationModel::MoveNextContent(void)
1167 AppLogDebug("ENTER");
1168 if (__pPlayer == null)
1170 AppLogDebug("EXIT");
1173 __currentContentIndex = __nextContentIndex;
1174 GenerateNextIndex();
1175 __removedContentIndex = INIT_CONTENT_INDEX;
1176 __isForceChanged = true;
1177 if (__pPlayContentList->GetCount() > 0)
1179 CallOnPlayContentChanged(__currentContentIndex);
1181 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1183 __seekCompleted = false;
1184 Play(__currentContentIndex, MIN_SLIDER_COUNT,false,true);
1186 // __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1187 //need to unmute the player as it is mute in case of moved next in pause state
1188 __pPlayer->SetMute(false);
1189 InitializeProgress();
1192 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1194 AppLogDebug("EXIT");
1199 PlayerPresentationModel::SeekToRewind(void)
1201 AppLogDebug("ENTER");
1202 int playDuration = __pPlayer->GetDuration();
1203 if(playDuration != 0)
1205 //__playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1206 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1209 AppLogDebug("EXIT");
1213 PlayerPresentationModel::Rewind(void)
1215 AppLogDebug("ENTER");
1216 result r = E_SUCCESS;
1217 __pPlayStateTimer->Cancel();
1218 int newPosition = __playposition - __xTimesValue;
1220 if (__playposition != newPosition)
1222 __playposition = newPosition;
1223 r = SetPlayPosition(__playposition);
1226 StopForwardRewind();
1227 // if there is some error in reading from the content file
1228 // it needs to show the message and Update the Ui accordingly.
1229 if (r == E_INVALID_DATA)
1232 InitializeProgress();
1234 CallOnPlayStateChanged(PLAYER_STATE_ERROR);
1240 if (__playposition < MIN_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1242 StopForwardRewind();
1246 if (__pFastRewindTimer != null)
1248 r = __pFastRewindTimer->Start(PROGRESS_TIMER_DURATION);
1249 TryCatch(r == E_SUCCESS, , "__pFastRewindTimer start failed. [%ls]", GetErrorMessage(r));
1252 AppLogDebug("EXIT");
1256 //AppLogException("[%ls]", GetErrorMessage(r));
1261 PlayerPresentationModel::SeekToForward(void)
1263 AppLogDebug("ENTER");
1264 int playDuration = __pPlayer->GetDuration();
1265 if (playDuration > 0)
1267 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
1271 AppLogDebug("EXIT");
1275 PlayerPresentationModel::Forward(void)
1277 AppLogDebug("ENTER");
1278 result r = E_SUCCESS;
1279 __pPlayStateTimer->Cancel();
1280 int newPosition = __playposition - __xTimesValue;
1282 if (__playposition != newPosition)
1284 __playposition = newPosition;
1285 __playposition = __playposition - __xTimesValue;
1286 r = SetPlayPosition(__playposition);
1289 AppLogDebug("SetPlayPosition Failed %s",GetErrorMessage(r));
1290 StopForwardRewind();
1291 // if there is some error in reading from the content file
1292 // it needs to show the message and Update the Ui accordingly.
1293 if (r == E_INVALID_DATA)
1296 InitializeProgress();
1298 CallOnPlayStateChanged(PLAYER_STATE_ERROR);
1305 if (__pFastForwardTimer != null)
1307 r = __pFastForwardTimer->Start(PROGRESS_TIMER_DURATION);
1308 TryCatch(r == E_SUCCESS, , "__pFastForwardTimer start failed. [%ls]", GetErrorMessage(r));
1311 AppLogDebug("EXIT");
1315 //AppLogException("[%ls]", GetErrorMessage(r));
1320 PlayerPresentationModel::StopForwardRewind(void)
1322 AppLogDebug("ENTER");
1323 result r = E_SUCCESS;
1325 if (__pFastForwardTimer != null)
1327 r = __pFastForwardTimer->Cancel();
1328 TryLog(r == E_SUCCESS, "[%s] __pFastForwardTimer cancel failed", GetErrorMessage(r));
1331 if (__pFastRewindTimer != null)
1333 r = __pFastRewindTimer->Cancel();
1334 TryLog(r == E_SUCCESS, "[%s] __pFastRewindTimer cancel failed", GetErrorMessage(r));
1336 __xTimesValue = INIT_X_VALUE;
1337 __seekCompleted = true;
1338 __pPlayStateTimer->Cancel();
1339 r = __pPlayStateTimer->Start(MESSAGE_BOX_DELAY/2);
1341 AppLogDebug("EXIT");
1346 PlayerPresentationModel::SetPlayPosition(int playPosition)
1348 AppLogDebug("ENTER %d",playPosition);
1349 if (__pPlayer == null)
1351 AppLogDebug("EXIT");
1355 result r = E_SUCCESS;
1356 String currentDuration;
1357 if (/*(playPosition >= MIN_SLIDER_COUNT) && (playPosition <= TIMER_INTERVAL) &&*/ __seekCompleted == true)
1359 if (GetPlayerState() == PLAYER_STATE_PLAYING || GetPlayerState() == PLAYER_STATE_PAUSED || GetPlayerState() == PLAYER_STATE_OPENED)
1361 if (playPosition >= MAX_SLIDER_COUNT)
1363 r = __pPlayer->SeekTo(__pPlayer->GetDuration());
1364 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1365 __playposition = MAX_SLIDER_COUNT;
1366 // StopForwardRewind();
1367 // __seekCompleted = false;
1370 else if (playPosition <= MIN_SLIDER_COUNT)
1372 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1373 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1374 __playposition = MIN_SLIDER_COUNT;
1378 int position = playPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL);
1379 AppLogDebug("position(%d)", position);
1380 r = __pPlayer->SeekTo(position);
1381 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1382 __playposition = playPosition;
1384 TryCatch(r == E_SUCCESS, r = E_FAILURE, "Unable to seek to.\n");
1385 //currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1386 //CallOnPlayTimeChanged(currentDuration, __playposition);
1387 __seekCompleted = false;
1391 // __playposition = playPosition;
1392 // currentDuration = CommonUtil::GetFormatDate(playPosition * (__currentPlayContentDuration / TIMER_INTERVAL));
1393 // CallOnPlayTimeChanged(currentDuration, __playposition);
1394 __seekCompleted = true;
1398 AppLogDebug("EXIT");
1402 //AppLogException( "[%s]", GetErrorMessage(r));
1403 if (__pPlayer->GetDuration() > MIN_SLIDER_COUNT)
1405 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1406 CallOnPlayTimeChanged(currentDuration, __playposition);
1408 __seekCompleted = false;
1409 AppLogDebug("EXIT");
1414 PlayerPresentationModel::GetPlayPosition(void)
1416 AppLogDebug("ENTER");
1417 AppLogDebug("EXIT");
1418 return __playposition;
1422 PlayerPresentationModel::GetCurrentDuration(void)
1424 AppLogDebug("ENTER");
1425 String currentDuration;
1426 if (__pPlayer != null)
1428 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1432 currentDuration = CommonUtil::GetFormatDate(INIT_VALUE);
1434 AppLogDebug("EXIT");
1435 return currentDuration;
1439 PlayerPresentationModel::SetContentList(IList* pArgs)
1441 AppLogDebug("ENTER");
1442 TryReturn( pArgs != null && pArgs->GetCount() > 0, E_INVALID_ARG, "Invalid arguments");
1443 result r = E_SUCCESS;
1444 String* pTemp = null;
1446 if (__pPlayContentList == null)
1448 __pPlayContentList = new (std::nothrow) ArrayList();
1449 TryCatch(__pPlayContentList != null, r = E_OUT_OF_MEMORY, "Unable to create ArrayList.\n");
1451 r = __pPlayContentList->Construct();
1452 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Construct ArrayList.\n");
1456 __pPlayContentList->RemoveAll(true);
1459 pTemp = static_cast<String*>(pArgs->GetAt(0));
1460 if (pTemp->Equals(MUSIC, true))
1462 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(2));
1463 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(2) is null.")
1465 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1469 while (pEnum->MoveNext() == E_SUCCESS)
1471 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1472 AppLogDebug("%ls", pContentPath->GetPointer());
1473 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1480 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(0));
1481 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1483 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1486 while (pEnum->MoveNext() == E_SUCCESS)
1488 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1489 AppLogDebug("%ls", pContentPath->GetPointer());
1490 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1495 __isForceChanged = true;
1498 AppLogDebug("EXIT");
1502 //AppLogException("[%s].\n",GetErrorMessage(r));
1503 if (__pPlayContentList != null)
1505 delete __pPlayContentList;
1506 __pPlayContentList = null;
1512 PlayerPresentationModel::GetContentListCount(void)const
1514 AppLogDebug("ENTER");
1515 if (__pPlayContentList != null)
1517 AppLogDebug("EXIT");
1518 return __pPlayContentList->GetCount();
1522 AppLogDebug("EXIT");
1528 PlayerPresentationModel::SetVolume(int volume)
1530 AppLogDebug("ENTER");
1531 String key(MEDIA_VOLUME);
1532 result r = E_SUCCESS;
1534 if (__pVolumeBarStateTimer != null)
1536 r = __pVolumeBarStateTimer->Cancel();
1537 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel failed.", GetErrorMessage(r));
1538 r = __pVolumeBarStateTimer->Start(VOLUMEBAR_INTERVAL);
1539 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Start __pVolumeBarStateTimer.\n");
1542 if (volume >= 0 && volume <= 15)
1544 SettingInfo::SetValue(key, volume);
1546 AppLogDebug("EXIT");
1550 //AppLogException("[%ls]", GetErrorMessage(r));
1555 PlayerPresentationModel::GetVolume(void)
1557 AppLogDebug("ENTER");
1559 String key(MEDIA_VOLUME);
1560 SettingInfo::GetValue(key, volume);
1561 AppLogDebug("EXIT");
1566 PlayerPresentationModel::SetShuffleEnable(bool shuffleEnable)
1568 AppLogDebug("ENTER");
1569 /* int __totalCount = 0;
1571 if (__pPlayContentList != null)
1573 __totalCount = __pPlayContentList->GetCount();
1576 if (shuffleEnable == true)
1581 srand(int(time(NULL)));
1582 for (int i = 0; i < __totalCount; i++)
1584 nDust = rand() % __totalCount;
1585 nSour = rand() % __totalCount;
1587 nTemp = __pPlayContentIndexOrder[nDust];
1588 __pPlayContentIndexOrder[nDust] = __pPlayContentIndexOrder[nSour];
1589 __pPlayContentIndexOrder[nSour] = nTemp;
1592 for (int i = 0; i < __totalCount; i++)
1594 if (__pPlayContentIndexOrder[i] - 1 == __currentContentIndex)
1596 nTemp = __pPlayContentIndexOrder[i];
1597 __pPlayContentIndexOrder[i] = __pPlayContentIndexOrder[__currentContentIndex];
1598 __pPlayContentIndexOrder[__currentContentIndex] = nTemp;
1604 int currentIndex = __currentContentIndex;
1605 __currentContentIndex = __pPlayContentIndexOrder[currentIndex] - 1;
1606 for (int i=0; i<__totalCount; i++)
1608 __pPlayContentIndexOrder[i]=i + 1;
1611 __shuffleEnable = shuffleEnable;
1612 GenerateNextIndex();
1613 AppLogDebug("EXIT");
1617 PlayerPresentationModel::SetRepeatMode(int repeatMode)
1619 AppLogDebug("ENTER");
1620 __repeatMode = repeatMode;
1621 AppLogDebug("EXIT");
1625 PlayerPresentationModel::IsShuffleEnable(void)
1627 AppLogDebug("ENTER");
1628 AppLogDebug("EXIT");
1629 return __shuffleEnable;
1633 PlayerPresentationModel::IsFileExist(int contentIndex) const
1635 AppLogDebug("ENTER");
1636 TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), false, "contentIndex is invalid.")
1637 String* pFilePath = GetContentPath(contentIndex);
1641 result r = file.Construct(*pFilePath, "r");
1642 TryReturn(r == E_SUCCESS, false, "File construct was failed.")
1644 AppLogDebug("EXIT");
1645 return file.IsFileExist(*pFilePath);
1649 PlayerPresentationModel::GetRepeatState(void)
1651 AppLogDebug("ENTER");
1652 AppLogDebug("EXIT");
1653 return __repeatMode;
1657 PlayerPresentationModel::GetFileName(String* pFilePath)
1659 AppLogDebug("ENTER");
1660 String path = Tizen::Io::File::GetFileName(*pFilePath);
1661 String strRemoveTemp = IDS_BLANK;
1662 int removeIndex = -1 ;
1663 path.LastIndexOf(IDS_PERIOD, path.GetLength() - 1, removeIndex);
1664 path.SubString(removeIndex + 1, strRemoveTemp);
1665 String strTemp = IDS_BLANK;
1667 path.Remove(removeIndex, strRemoveTemp.GetLength() + 1);
1668 path.SubString(0, strTemp);
1669 AppLogDebug("EXIT");
1674 PlayerPresentationModel::InitializeProgress(void)
1676 AppLogDebug("ENTER");
1677 result r = E_SUCCESS;
1679 String currentDuration;
1680 if (__pPlayer != null)
1682 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1686 currentDuration = INITIAL_TIME;
1689 if (__pPlayStateTimer != null /*&& __previousPlayerState != PLAYER_STATE_INITIALIZED*/
1690 && __previousPlayerState != PLAYER_STATE_PAUSED
1691 && __previousPlayerState != PLAYER_STATE_CLOSED)
1693 r = __pPlayStateTimer->Cancel();
1694 TryLog(r == E_SUCCESS, "[%s] __pPlayStateTimer cancel failed.", GetErrorMessage(r));
1696 __playposition = MIN_SLIDER_COUNT;
1697 // __seekCompleted = true;
1698 __xTimesValue = INIT_VALUE;
1699 //CallOnPlayTimeChanged(currentDuration, __playposition);
1700 AppLogDebug("EXIT");
1705 PlayerPresentationModel::UpdateContentDB(void)
1707 AppLogDebug("ENTER");
1708 result r = E_SUCCESS;
1710 String contentIdString;
1711 ArrayList* pTempList = null;
1713 Tizen::Base::String contentPath = *static_cast<String*>(__pPlayContentList->GetAt(__currentContentIndex));
1714 if (File::IsFileExist(contentPath) == false)
1716 AppLogDebug("File not exist(%ls)", contentPath.GetPointer());
1717 return GetLastResult();
1720 ContentId contentId = CommonUtil::GetContentId(contentPath);
1721 if (IsFailed(GetLastResult()))
1723 AppLogDebug("CommonUtil::GetContentId(%ls) failed", contentPath.GetPointer());
1724 return GetLastResult();
1728 Tizen::System::SystemTime::GetCurrentTime(Tizen::System::TIME_MODE_STANDARD, playTime);
1729 Tizen::Base::String playTimeString = playTime.ToString();
1731 PlaylistDB* pPlaylistDB = new (std::nothrow) PlaylistDB();
1732 r = pPlaylistDB->CreatePlaylistDatabase();
1733 TryCatch(r == E_SUCCESS,,"CreatePlaylistDatabase() failed with error %s",GetErrorMessage(r));
1735 // pTempList = new (std::nothrow) ArrayList();
1736 // pTempList->Construct();
1738 contentIdString = contentId.ToString();
1739 if (pPlaylistDB->Read(contentIdString) != E_KEY_ALREADY_EXIST)
1741 r = pPlaylistDB->Insert(contentIdString, playCount + 1, playTimeString);
1745 pTempList = pPlaylistDB->ReadValueN(contentIdString);
1746 if (pTempList != null)
1748 playCount = static_cast<Integer*>(pTempList->GetAt(0))->ToInt();
1750 r = pPlaylistDB->Update(contentIdString, playCount + 1, playTimeString);
1755 if (pPlaylistDB != null)
1761 if (pTempList != null)
1763 pTempList->RemoveAll(true);
1767 AppLogDebug("EXIT %s",GetErrorMessage(r));
1772 PlayerPresentationModel::GenerateNextIndex(void)
1774 AppLogDebug("ENTER");
1775 if (IsShuffleEnable())
1777 int totalCount = __pPlayContentList->GetCount();
1781 __previousContentIndex = 0;
1782 __nextContentIndex = 0;
1786 srand(int(time(NULL)));
1787 __previousContentIndex = rand() % totalCount;
1788 while (__previousContentIndex == __currentContentIndex)
1790 __previousContentIndex = rand() % totalCount;
1793 __nextContentIndex = rand() % totalCount;
1794 while (__nextContentIndex == __currentContentIndex)
1796 __nextContentIndex = rand() % totalCount;
1802 if (__pPlayContentList->GetCount() == 0)
1804 __previousContentIndex = 0;
1805 __nextContentIndex = 0;
1809 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1811 __previousContentIndex = __pPlayContentList->GetCount() - 1;
1815 __previousContentIndex = __currentContentIndex - 1;
1818 if (__currentContentIndex == __pPlayContentList->GetCount() - 1
1819 || __removedContentIndex == __pPlayContentList->GetCount())
1821 __nextContentIndex = 0;
1825 if (__removedContentIndex != INIT_CONTENT_INDEX)
1827 __nextContentIndex = __previousContentIndex + 1;
1828 if (__nextContentIndex > __pPlayContentList->GetCount() - 1)
1830 __nextContentIndex = 0;
1835 __nextContentIndex = __currentContentIndex + 1;
1839 AppLogDebug("EXIT");
1843 PlayerPresentationModel::OnPlayerOpened(result r)
1845 AppLogDebug("ENTER");
1846 AppLogDebug("EXIT");
1850 PlayerPresentationModel::OnPlayerReleased(void)
1852 AppLogDebug("ENTER");
1853 if (__pPlayer != null && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1855 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1857 AppLogDebug("EXIT");
1861 PlayerPresentationModel::OnPlayerEndOfClip(void)
1863 AppLogDebug("ENTER");
1864 // StopForwardRewind();
1866 if (__pPlayer == null)
1868 AppLogDebug("EXIT");
1871 if (__seekCompleted)
1873 String totalDuration = CommonUtil::GetFormatDate(__currentContentTotalDuration);
1874 AppLogDebug("totalDuration(%ls), __currentContentTotalDuration(%d)", totalDuration.GetPointer(), __currentContentTotalDuration);
1875 CallOnPlayTimeChanged(totalDuration, MAX_SLIDER_COUNT);
1876 __playposition = MIN_PLAY_STATE_SLIDER_COUNT;
1879 __seekCompleted = true;
1880 AppLogDebug("GetRepeatState() : %d", GetRepeatState());
1881 switch (GetRepeatState())// 0 - 2 (OFF, ONE, ALL)
1885 AppLogDebug("Repeat State(%d)", 1);
1886 while (__pPlayContentList->GetCount() > 0 && __currentContentIndex < __pPlayContentList->GetCount() && IsFileExist(__currentContentIndex) == false)
1888 String* pContentPath = GetContentPath(__currentContentIndex);
1890 if (pContentPath != null)
1892 RemoveContent(*pContentPath);
1896 //Need to play the currently loaded song in case there is no other content available in "Now Playing List"
1897 if (__pPlayContentList->GetCount() == 0)
1899 InitializeProgress();
1900 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1905 InitializeProgress();
1907 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1913 AppLogDebug("Repeat State(%d)", 0);
1914 if (__pPlayContentList->GetCount() - 1 == __currentContentIndex)
1916 StopForwardRewind();
1917 InitializeProgress();
1918 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1923 while (__pPlayContentList->GetCount() > 0 && GetNextContentIndex() < __pPlayContentList->GetCount() && IsFileExist(GetNextContentIndex()) == false)
1925 String* pContentPath = GetContentPath(GetNextContentIndex());
1927 if (pContentPath != null)
1929 RemoveContent(*pContentPath);
1933 InitializeProgress();
1934 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1941 AppLogDebug("Repeat State(%d)", 2);
1943 while (__pPlayContentList->GetCount() > 0 && GetNextContentIndex() < __pPlayContentList->GetCount() && IsFileExist(GetNextContentIndex()) == false)
1945 String* pContentPath = GetContentPath(GetNextContentIndex());
1947 if (pContentPath != null)
1949 RemoveContent(*pContentPath);
1953 //Need to play the currently loaded song in case there is no other content available in "Now Playing List"
1954 if (__pPlayContentList->GetCount() == 0)
1956 InitializeProgress();
1957 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1962 InitializeProgress();
1963 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1970 AppLogDebug("EXIT");
1974 PlayerPresentationModel::OnPlayerBuffering(int percent)
1976 AppLogDebug("ENTER");
1977 if (__pPlayer == null)
1979 AppLogDebug("EXIT");
1982 CallOnPlayStateChanged(__pPlayer->GetState());
1983 AppLogDebug("EXIT");
1987 PlayerPresentationModel::OnPlayerErrorOccurred(PlayerErrorReason r)
1989 AppLogDebug("ENTER Error Reason = %d", r);
1990 if (__pPlayer == null)
1992 AppLogDebug("EXIT");
1995 // in case of Device failed stop the player and reinitialize for next content
1996 PlayerState playerState = __pPlayer->GetState();
1997 if (r == PLAYER_ERROR_DEVICE_FAILED)
2000 InitializeProgress();
2004 CallOnPlayStateChanged(playerState);
2005 AppLogDebug("EXIT");
2009 PlayerPresentationModel::OnPlayerInterrupted(void)
2011 AppLogDebug("ENTER");
2013 AppLogDebug("EXIT");
2018 PlayerPresentationModel::OnPlayerSeekCompleted(result r)
2020 AppLogDebug("ENTER %s",GetErrorMessage(r));
2022 if (!__seekCompleted)
2024 String currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
2025 CallOnPlayTimeChanged(currentDuration, __playposition);
2026 AppLogDebug("current duration %ls",currentDuration.GetPointer());
2031 __seekCompleted = true;
2035 __seekCompleted = false;
2037 AppLogDebug("EXIT");
2041 PlayerPresentationModel::OnPlayerAudioFocusChanged(void)
2043 AppLogDebug("ENTER");
2044 /*__audioFocusChanged = true;*/
2046 AppLogDebug("EXIT");
2050 PlayerPresentationModel::OnAudioSessionInterrupted(void)
2052 AppLogDebug("ENTER");
2053 AppLogDebug("EXIT");
2057 PlayerPresentationModel::OnAudioSessionInterruptReleased(void)
2059 AppLogDebug("ENTER");
2060 AppLogDebug("EXIT");
2064 PlayerPresentationModel::OnAudioSessionAudioFocusChanged(void)
2066 AppLogDebug("ENTER");
2067 AppLogDebug("EXIT");
2071 PlayerPresentationModel::OnTimerExpired(Timer& timer)
2073 // AppLogDebug("ENTER");
2074 if (__pPlayer == null)
2076 AppLogDebug("EXIT player is null");
2080 result r = E_SUCCESS;
2081 if (__pPlayStateTimer == &timer)
2083 String currentDuration;
2084 PlayerState playerState = __pPlayer->GetState() ;
2085 long playDuration = __pPlayer->GetDuration();
2086 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2088 switch (playerState)
2090 case PLAYER_STATE_PLAYING:
2092 if ( playDuration < 2000)
2094 currentDuration = CommonUtil::GetFormatDate(playDuration);
2095 CallOnPlayTimeChanged(currentDuration, TIMER_INTERVAL);
2099 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
2101 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..\n");
2102 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
2103 //AppLogDebug("GetPosition(%d), playDuration(%d)", __pPlayer->GetPosition(), playDuration);
2105 if (__pPlayer->GetPosition() <= playDuration)
2107 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
2108 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
2109 // AppLogDebug("currentDuration(%s), __playposition(%d)", currentDuration.GetPointer(), __playposition);
2110 CallOnPlayTimeChanged(currentDuration, __playposition);
2115 case PLAYER_STATE_PAUSED:
2117 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
2118 TryReturnVoid(playDuration != 0, "playDuration is zero.");
2119 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
2120 __playposition = static_cast<int>(__pPlayer->GetPosition() * TIMER_INTERVAL / playDuration);
2121 CallOnPlayTimeChanged(currentDuration, __playposition);
2129 else if (__pFastForwardTimer == &timer)
2134 else if (__pFastRewindTimer == &timer)
2139 else if (__pAutoOffTimer == &timer)
2141 Application::GetInstance()->Terminate();
2143 else if (__pPauseAutoOffTimer == &timer)
2145 Application::GetInstance()->Terminate();
2147 else if (__pVolumeBarStateTimer == &timer)
2149 r = __pVolumeBarStateTimer->Cancel();
2150 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel Failed.", GetErrorMessage(r));
2151 CallOnPlayVolumeBarStateChanged();
2155 //AppLogDebug("Timer is invalid value.");
2157 // AppLogDebug("EXIT");
2162 //AppLogException("[%ls]", GetErrorMessage(r));
2167 PlayerPresentationModel::AddMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2169 AppLogDebug("ENTER");
2170 __musicPlayerEventListener.Add(const_cast<IMusicPlayerEventListener*>(&listener));
2171 AppLogDebug("EXIT");
2175 PlayerPresentationModel::RemoveMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
2177 AppLogDebug("ENTER");
2178 __musicPlayerEventListener.Remove(const_cast<IMusicPlayerEventListener*>(&listener));
2179 AppLogDebug("EXIT");
2183 PlayerPresentationModel::CallOnPlayStateChanged(PlayerState playerState)
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->OnPlayStateChanged(playerState);
2197 AppLogDebug("EXIT");
2201 PlayerPresentationModel::CallOnPlayContentChanged(int currentContentIndex)
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->OnPlayContentChanged(currentContentIndex);
2215 AppLogDebug("EXIT");
2219 PlayerPresentationModel::CallOnPlayContentRemoved(int removedContentIndex)
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->OnPlayContentRemoved(removedContentIndex);
2233 AppLogDebug("EXIT");
2237 PlayerPresentationModel::CallOnPlayTimeChanged(Tizen::Base::String& currentDuration, int currentPosition)
2239 // AppLogDebug("ENTER");
2240 IMusicPlayerEventListener* pListener = null;
2241 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2242 while (pEnum->MoveNext() == E_SUCCESS)
2244 pEnum->GetCurrent(pListener);
2245 if (pListener != null)
2247 pListener->OnPlayTimeChanged(currentDuration, currentPosition);
2251 // AppLogDebug("EXIT");
2255 PlayerPresentationModel::CallOnPlayVolumeBarStateChanged(void)
2257 AppLogDebug("ENTER");
2258 IMusicPlayerEventListener* pListener = null;
2259 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2260 while (pEnum->MoveNext() == E_SUCCESS)
2262 pEnum->GetCurrent(pListener);
2263 if (pListener != null)
2265 pListener->OnPlayVolumeBarStateChanged();
2269 AppLogDebug("EXIT");
2273 PlayerPresentationModel::CallOnPlayPresentationModelDestroying(void)
2275 AppLogDebug("ENTER");
2276 IMusicPlayerEventListener* pListener = null;
2277 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2278 while (pEnum->MoveNext() == E_SUCCESS)
2280 pEnum->GetCurrent(pListener);
2281 if (pListener != null)
2283 pListener->OnPlayPresentationModelDestroying();
2287 AppLogDebug("EXIT");