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 = 250;
51 static const int PROGRESS_BAR_DURATION_TIMER = 1000;
52 static const int MIN_SLIDER_COUNT = 0;
53 static const int MAX_SLIDER_COUNT = 100;
54 static const int INIT_X_VALUE = 0;
55 static const int INIT_CONTENT_INDEX = -1;
56 static const int VOLUMEBAR_INTERVAL = 3000;
57 static const int PAUSE_AUTO_OFF_TIME = 1000 * 60 * 2;
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 , __currentPlayContentDuration(null)
104 , __shuffleEnable(false)
105 , __seekCompleted(true)
106 , __playposition(MIN_SLIDER_COUNT)
107 , __lastPosition(MIN_SLIDER_COUNT)
108 , __previousPlayerState(PLAYER_STATE_ERROR)
109 , __xTimesValue(INIT_X_VALUE)
110 , __pCallManager(null)
112 AppLogDebug("ENTER");
116 PlayerPresentationModel::~PlayerPresentationModel(void)
118 AppLogDebug("ENTER");
119 result r = E_SUCCESS;
121 if (__repeatMode != CommonUtil::GetValue(REPEAT_MODE))
123 CommonUtil::SetValue(REPEAT_MODE, __repeatMode);
125 if (__shuffleEnable != static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE)))
127 CommonUtil::SetValue(SHUFFLE_MODE, static_cast<int>(__shuffleEnable));
129 if (__pPlayContentList != null)
131 __pPlayContentList->RemoveAll(true);
132 delete __pPlayContentList;
133 __pPlayContentList = null;
135 if (__pPlayStateTimer != null)
137 __pPlayStateTimer->Cancel();
138 delete __pPlayStateTimer;
139 __pPlayStateTimer = null;
141 if (__pFastForwardTimer != null)
143 __pFastForwardTimer->Cancel();
144 delete __pFastForwardTimer;
145 __pFastForwardTimer = null;
147 if (__pFastRewindTimer != null)
149 __pFastRewindTimer->Cancel();
150 delete __pFastRewindTimer;
151 __pFastRewindTimer = null;
153 if (__pAutoOffTimer != null)
155 __pAutoOffTimer->Cancel();
156 delete __pAutoOffTimer;
157 __pAutoOffTimer = null;
159 if (__pPauseAutoOffTimer != null)
161 __pPauseAutoOffTimer->Cancel();
162 delete __pPauseAutoOffTimer;
163 __pPauseAutoOffTimer = null;
165 if (__pVolumeBarStateTimer != null)
167 __pVolumeBarStateTimer->Cancel();
168 delete __pVolumeBarStateTimer;
171 delete __pCurrentPlayContentPath;
172 delete __pCurrentPlayContentTitle;
173 delete __pCurrentPlayContentThumbnail;
174 delete __pCurrentPlayContentArtist;
176 if (__pCallManager != null)
178 delete __pCallManager;
181 if (__pPlayer == null)
186 if (__pPlayer != null)
188 PlayerState state = __pPlayer->GetState();
191 case PLAYER_STATE_PLAYING:
193 case PLAYER_STATE_PAUSED:
195 r = __pPlayer->Stop();
196 TryLog(r == E_SUCCESS, "[%s] Failed Stop",GetErrorMessage(r));
197 r = __pPlayer->Close();
198 TryLog(r == E_SUCCESS, "[%s] Failed Close",GetErrorMessage(r));
202 case PLAYER_STATE_ENDOFCLIP:
204 case PLAYER_STATE_OPENED:
206 case PLAYER_STATE_STOPPED:
208 r = __pPlayer->Close();
209 TryLog(r == E_SUCCESS, "[%s] Failed Close",GetErrorMessage(r));
213 case PLAYER_STATE_CLOSED:
228 PlayerPresentationModel::DestroyPlayerPresentationModel(void)
230 AppLogDebug("ENTER");
231 if (pPlayerPresentationModel != null)
233 CallOnPlayPresentationModelDestroying();
235 delete pPlayerPresentationModel;
236 pPlayerPresentationModel = null;
242 PlayerPresentationModel::OnTelephonyCallStatusChangedN(Tizen::Telephony::CallStatus callStatus, Tizen::Telephony::CallInfo* pCallInfo)
244 AppLogDebug("ENTER");
245 AppLogDebug("callStatus : %d", callStatus);
246 if (callStatus == CALL_STATUS_IDLE || callStatus == CALL_STATUS_COMMUNICATING)
248 CallOnPlayContentChanged(__currentContentIndex);
254 PlayerPresentationModel::Construct(void)
256 AppLogDebug("ENTER");
257 result r = E_SUCCESS;
259 /*AudioSessionManager::GetInstance()->SetAudioSessionEventListener(this);
260 AudioSessionManager::GetInstance()->SetMode(AUDIO_SESSION_MODE_EXCLUSIVE);*/
262 __pPlayStateTimer = new (std::nothrow) Timer();
263 r = __pPlayStateTimer->Construct(*this);
264 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Timer.\n");
266 __pFastForwardTimer = new (std::nothrow) Timer();
267 r = __pFastForwardTimer->Construct(*this) ;
268 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct FastForwardTimer.\n");
270 __pFastRewindTimer = new (std::nothrow) Timer();
271 r = __pFastRewindTimer->Construct(*this) ;
272 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct FastRewindTimer.\n");
274 __pAutoOffTimer = new (std::nothrow) Timer();
275 r = __pAutoOffTimer->Construct(*this);
276 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct __pAutoOffTimer.\n");
278 __pPauseAutoOffTimer = new (std::nothrow) Timer();
279 r = __pPauseAutoOffTimer->Construct(*this);
280 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct __pPauseAutoOffTimer.\n");
282 __pVolumeBarStateTimer = new (std::nothrow) Timer();
283 r = __pVolumeBarStateTimer->Construct(*this);
284 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Timer.\n");
286 __pCurrentPlayContentPath = new (std::nothrow) String(L"");
288 __repeatMode = CommonUtil::GetValue(REPEAT_MODE);
289 __shuffleEnable = static_cast<bool>(CommonUtil::GetValue(SHUFFLE_MODE));
291 __pCallManager = new (std::nothrow) CallManager();
292 __pCallManager->Construct(*this);
300 //AppLogException( "[%s]", GetErrorMessage(r));
301 if (__pPlayStateTimer != null)
303 __pPlayStateTimer->Cancel();
304 delete __pPlayStateTimer;
305 __pPlayStateTimer = null;
307 if (__pFastForwardTimer != null)
309 __pFastForwardTimer->Cancel();
310 delete __pFastForwardTimer;
311 __pFastForwardTimer = null;
313 if (__pFastRewindTimer != null)
315 __pFastRewindTimer->Cancel();
316 delete __pFastRewindTimer;
317 __pFastRewindTimer = null;
319 if (__pAutoOffTimer != null)
321 __pAutoOffTimer->Cancel();
322 delete __pAutoOffTimer;
323 __pAutoOffTimer = null;
325 if (__pPauseAutoOffTimer != null)
327 __pPauseAutoOffTimer->Cancel();
328 delete __pPauseAutoOffTimer;
329 __pPauseAutoOffTimer = null;
331 if (__pVolumeBarStateTimer != null)
333 __pVolumeBarStateTimer->Cancel();
334 delete __pVolumeBarStateTimer;
340 PlayerPresentationModel::InitializePlayer(void)
342 AppLogDebug("ENTER");
343 result r = E_SUCCESS;
345 if (__pPlayer != null)
351 __pPlayer = new (std::nothrow) Player();
352 r = __pPlayer->Construct(*this, BUFFER_INFO_OF_PLAYER);
353 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct Player.\n");
366 PlayerPresentationModel::StartAutoOffTimer(int autoOffValue)
368 AppLogDebug("ENTER");
369 result r = E_SUCCESS;
370 if (__pAutoOffTimer != null)
372 if (autoOffValue == 0)
374 r = __pAutoOffTimer->Cancel();
375 AppLogDebug("%s", GetErrorMessage(r));
379 __pAutoOffTimer->Cancel();
380 r = __pAutoOffTimer->Start(autoOffValue);
381 AppLogDebug("%s", GetErrorMessage(r));
382 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Start __pAutoOffTimer.\n");
391 //AppLogException( "[%s]", GetErrorMessage(r));
396 PlayerPresentationModel::RemoveContent(const Tizen::Base::String& filePath)
398 AppLogDebug("ENTER");
399 TryReturnVoid(__pPlayContentList != null, "There is not a playlist");
400 IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
401 String* pFilePath = null;
404 while (pEnum->MoveNext() == E_SUCCESS)
406 pFilePath = static_cast<String*>(pEnum->GetCurrent());
408 if (pFilePath->Equals(filePath))
410 __pPlayContentList->Remove(filePath);
412 if (index < __currentContentIndex)
414 __currentContentIndex--;
416 else if (index == __currentContentIndex)
418 if (index == __pPlayContentList->GetCount())
420 __currentContentIndex--;
422 __removedContentIndex = index;
426 if (__pPlayContentList->GetCount() > 0)
428 CallOnPlayContentRemoved(index);
439 PlayerPresentationModel::GetPlayerState(void)
441 AppLogDebug("ENTER");
442 if (__pPlayer == null)
445 return PLAYER_STATE_ERROR;
448 return __pPlayer->GetState();
452 PlayerPresentationModel::IsDuringCall(void)
454 AppLogDebug("ENTER");
455 CallStatus callStatus = CALL_STATUS_UNDEFINED;
456 callStatus = __pCallManager->GetCurrentCallStatus();
457 AppLogDebug("callStatus = %d", callStatus);
459 if (callStatus == CALL_STATUS_IDLE)
472 PlayerPresentationModel::ClosePlayer(void)
474 AppLogDebug("ENTER");
475 result r = E_SUCCESS;
477 if (__pPlayer == null)
483 __previousPlayerState = __pPlayer->GetState();
485 switch (__previousPlayerState)
487 case PLAYER_STATE_PLAYING:
489 case PLAYER_STATE_PAUSED:
491 r = __pPlayer->Stop();
492 TryLog(r == E_SUCCESS, "[%s] Failed Stop", GetErrorMessage(r));
493 r = __pPlayer->Close();
494 TryLog(r == E_SUCCESS, "[%s] Failed Close", GetErrorMessage(r));
498 case PLAYER_STATE_OPENED:
500 case PLAYER_STATE_STOPPED:
502 r = __pPlayer->Close();
503 TryLog(r == E_SUCCESS, "[%s] Failed Close", GetErrorMessage(r));
507 case PLAYER_STATE_CLOSED:
512 case PLAYER_STATE_ENDOFCLIP:
524 PlayerPresentationModel::GetPlayContentPath(void)
526 AppLogDebug("ENTER");
528 return __pCurrentPlayContentPath;
532 PlayerPresentationModel::GetPlayContentTitle(void)
534 AppLogDebug("ENTER");
536 return __pCurrentPlayContentTitle;
540 PlayerPresentationModel::GetPlayContentArtist(void)
542 AppLogDebug("ENTER");
544 return __pCurrentPlayContentArtist;
547 Tizen::Graphics::Bitmap*
548 PlayerPresentationModel::GetPlayContentThumbnail(void)
550 AppLogDebug("ENTER");
552 return __pCurrentPlayContentThumbnail;
556 PlayerPresentationModel::GetPlayContentDuration(void)
558 AppLogDebug("ENTER");
560 return __currentPlayContentDuration;
564 PlayerPresentationModel::GetContentPath(int contentIndex)const
566 AppLogDebug("ENTER");
567 String* pFilePath = null;
569 TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), null, "contentIndex is invalid.");
570 pFilePath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
577 PlayerPresentationModel::GetPreviousContentIndex(void) const
579 AppLogDebug("ENTER");
581 return __previousContentIndex;
585 PlayerPresentationModel::GetCurrentContentIndex(void) const
587 AppLogDebug("ENTER");
589 return __currentContentIndex;
593 PlayerPresentationModel::GetNextContentIndex(void) const
595 AppLogDebug("ENTER");
597 return __nextContentIndex;
601 PlayerPresentationModel::GetContentInfoN(int contentIndex)
603 AppLogDebug("ENTER");
604 if (__pPlayContentList == null || contentIndex < INIT_VALUE)
606 AppLogDebug("EXIT(index(%d) MUST be greater than or equal to 0 OR __pPlayContentList is null)", contentIndex);
610 Tizen::Base::String* contentPath = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
611 if (contentPath == null || File::IsFileExist(*contentPath) == false)
617 ContentInformation* pContentInfo = new (std::nothrow) ContentInformation();
618 AudioContentInfo* pAudioContentInfo = CommonUtil::GetAudioContentInfoN(*contentPath);
620 if (pAudioContentInfo != null)
622 if (pAudioContentInfo->GetArtist() == null)
624 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
628 pContentInfo->ArtistName = pAudioContentInfo->GetArtist();
631 if (pAudioContentInfo->GetTitle() == null)
633 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
637 pContentInfo->TitleName = pAudioContentInfo->GetTitle();
639 pContentInfo->Duration = pAudioContentInfo->GetDuration();/*__pPlayer->GetDuration();*/
640 if (__pPlayer != null && pContentInfo->Duration == null)
642 __pPlayer->GetDuration();
644 pContentInfo->contentId = pAudioContentInfo->GetContentId();
645 delete pAudioContentInfo;
649 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
650 if (pAudioMeta == null)
656 if (pAudioMeta->GetArtist() == null)
658 pContentInfo->ArtistName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
662 pContentInfo->ArtistName = pAudioMeta->GetArtist();
665 if (pAudioMeta->GetTitle() == null)
667 pContentInfo->TitleName = ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN");
671 pContentInfo->TitleName = pAudioMeta->GetTitle();
674 if (__pPlayer != null)
676 pContentInfo->Duration = __pPlayer->GetDuration();
686 Tizen::Graphics::Bitmap*
687 PlayerPresentationModel::GetContentAlbumArtN(int contentIndex)
689 AppLogDebug("ENTER");
690 Bitmap* pAlbumArtBitmap = null;
691 if (contentIndex <= -1)
693 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
695 return pAlbumArtBitmap;
698 String* path = static_cast<String*>(__pPlayContentList->GetAt(contentIndex));
701 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
703 return pAlbumArtBitmap;
706 pAlbumArtBitmap = CommonUtil::GetContentAlbumArtN(*path);
707 if (pAlbumArtBitmap == null)
709 pAlbumArtBitmap = ResourceManager::GetBitmapN(L"34_thumb_07.png");
712 return pAlbumArtBitmap;
716 PlayerPresentationModel::Play(int contentIndex, int sliderPosition, bool bPausePlay)
718 AppLogDebug("ENTER");
719 result r = E_SUCCESS;
721 if (__pPlayer == null)
727 __seekCompleted = true;
728 /* if (__seekCompleted == false)
734 if (GetContentListCount() == 0)
737 InitializeProgress();
740 PlayerState playerState;
741 String currentDuration = null;
742 String* pPath = null;
744 TryCatch(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), , "contentIndex is invalid");
746 if (bPausePlay == false)
748 pPath = GetContentPath(contentIndex);
749 AppLogDebug("pPath = %ls", pPath->GetPointer());
750 AppLogDebug("__pCurrentPlayContentPath = %ls", __pCurrentPlayContentPath->GetPointer());
751 if (__pPlayer->GetState() == PLAYER_STATE_ENDOFCLIP
752 || pPath->Equals(*__pCurrentPlayContentPath) == false || __currentContentIndex != contentIndex)
755 InitializeProgress();
757 __previousPlayerState = PLAYER_STATE_INITIALIZED;
758 __currentContentIndex = contentIndex;
760 __pCurrentPlayContentPath->Clear();
761 __pCurrentPlayContentPath->Append(pPath->GetPointer());
763 AudioContentInfo* pAudioInfo = CommonUtil::GetAudioContentInfoN(*(__pCurrentPlayContentPath));
765 if (pAudioInfo != null)
767 __pCurrentPlayContentTitle = new (std::nothrow) String(pAudioInfo->GetTitle());
768 __pCurrentPlayContentThumbnail = pAudioInfo->GetThumbnailN();
769 if (__pCurrentPlayContentThumbnail == null)
771 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
773 __pCurrentPlayContentArtist = new (std::nothrow) String(pAudioInfo->GetArtist());
774 __currentPlayContentDuration = pAudioInfo->GetDuration();
775 if (__currentPlayContentDuration == null)
777 __currentPlayContentDuration = __pPlayer->GetDuration();
783 Tizen::Content::AudioMetadata* pAudioMeta = Tizen::Content::ContentManagerUtil::GetAudioMetaN(*static_cast<String*>(__pPlayContentList->GetAt(contentIndex)));
784 if (pAudioMeta == null)
786 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
787 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
788 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
789 __currentPlayContentDuration = __pPlayer->GetDuration();
793 __pCurrentPlayContentTitle = new (std::nothrow) String(pAudioMeta->GetTitle());
794 if (__pCurrentPlayContentTitle == null)
796 __pCurrentPlayContentTitle = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
799 __pCurrentPlayContentArtist = new (std::nothrow) String(pAudioMeta->GetArtist());
800 if (__pCurrentPlayContentArtist == null)
802 __pCurrentPlayContentArtist = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MUSIC_BODY_UNKNOWN"));
805 __pCurrentPlayContentThumbnail = pAudioMeta->GetThumbnailN();
806 if (__pCurrentPlayContentThumbnail == null)
808 __pCurrentPlayContentThumbnail = ResourceManager::GetBitmapN(L"34_thumb_07.png");
811 __currentPlayContentDuration = pAudioMeta->GetDuration();
812 if (__currentPlayContentDuration == null)
814 __currentPlayContentDuration = __pPlayer->GetDuration();
823 IEnumerator* pEnum = __pPlayContentList->GetEnumeratorN();
824 String* pFilePath = null;
829 while (pEnum->MoveNext() == E_SUCCESS)
831 pFilePath = static_cast<String*>(pEnum->GetCurrent());
833 if (pFilePath->Equals(*__pCurrentPlayContentPath))
835 __currentContentIndex = index;
844 if (__pPlayer->GetState() == PLAYER_STATE_PLAYING)
851 playerState = __pPlayer->GetState();
855 case PLAYER_STATE_PLAYING:
857 CallOnPlayContentChanged(__currentContentIndex);
861 case PLAYER_STATE_STOPPED:
863 case PLAYER_STATE_OPENED:
865 case PLAYER_STATE_PAUSED:
867 case PLAYER_STATE_ENDOFCLIP:
869 if (__pPauseAutoOffTimer != null)
871 r = __pPauseAutoOffTimer->Cancel();
872 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
874 if (__pPlayStateTimer != null)
876 r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
877 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..\n");
880 AppLogDebug("%d", __pPlayer->GetState());
881 r = __pPlayer->Play();
882 TryCatch(r == E_SUCCESS, , "Play failed(%s)", GetErrorMessage(r));
883 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
885 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
886 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
887 __playposition = sliderPosition;
889 if (bPausePlay == false)
891 CallOnPlayContentChanged(__currentContentIndex);
894 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
895 CallOnPlayTimeChanged(currentDuration, __playposition);
899 case PLAYER_STATE_ERROR:
901 AppLogDebug("PlayerState : %d", playerState);
903 TryCatch(r == E_SUCCESS, , "PLAYER_STATE_ERROR occured.\n");
907 case PLAYER_STATE_CLOSED:
909 case PLAYER_STATE_INITIALIZED:
911 TryCatch(__pPlayer != null && pPath != null, r = E_FAILURE, "Player is not initialized or pPath is null.");
912 r = __pPlayer->OpenFile(*pPath);
913 TryCatch(r == E_SUCCESS, , "[%ls] OpenFile failed\n(%s).", pPath->GetPointer(), GetErrorMessage(r));
915 if ((__previousPlayerState == PLAYER_STATE_PLAYING) || (__previousPlayerState == PLAYER_STATE_ENDOFCLIP)
916 || (__previousPlayerState == PLAYER_STATE_INITIALIZED))
918 if (__pPauseAutoOffTimer != null)
920 r = __pPauseAutoOffTimer->Cancel();
921 TryLog(r == E_SUCCESS, "__pPauseAutoOffTimer cancel failed\n(%s)", GetErrorMessage(r));
923 if (__pPlayStateTimer != null)
925 r = __pPlayStateTimer->Start(PROGRESS_TIMER_DURATION);
926 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed\n(%s)", GetErrorMessage(r));
929 r = __pPlayer->Play();
930 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
931 if (sliderPosition != 0 && playerState != PLAYER_STATE_PAUSED)
933 r = __pPlayer->SeekTo(sliderPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
934 TryCatch(r == E_SUCCESS, , "Unable to seek to.\n");
935 __playposition = sliderPosition;
938 if (__previousPlayerState == PLAYER_STATE_PAUSED)
940 r = __pPlayer->Play();
941 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
942 r = __pPlayer->Pause();
943 TryCatch(r == E_SUCCESS, , "Play failed\n(%s)", GetErrorMessage(r));
946 if (bPausePlay == false)
948 CallOnPlayContentChanged(__currentContentIndex);
951 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
952 CallOnPlayTimeChanged(currentDuration, __playposition);
956 case PLAYER_STATE_OPENING:
965 CallOnPlayStateChanged(__pPlayer->GetState());
970 CallOnPlayStateChanged(PLAYER_STATE_ERROR);
975 PlayerPresentationModel::Pause(void)
977 AppLogDebug("ENTER");
978 if (__pPlayer == null)
984 result r = E_SUCCESS;
985 PlayerState playerState = __pPlayer->GetState() ;
986 AppLogDebug("%d", playerState);
987 if (playerState == PLAYER_STATE_PLAYING)
989 r = __pPlayer->Pause();
990 TryCatch(r == E_SUCCESS, , "__pPlayer pause failed..%s\n",GetErrorMessage(r));
992 if (__pPlayStateTimer != null)
994 r = __pPlayStateTimer->Cancel();
995 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer cancel failed..\n");
997 if (__pPauseAutoOffTimer != null)
999 /*__pPauseAutoOffTimer->Start(3000);*/
1000 r = __pPauseAutoOffTimer->Start(PAUSE_AUTO_OFF_TIME);
1001 TryCatch(r == E_SUCCESS, , "__pPauseAutoOffTimer start failed..\n");
1004 CallOnPlayStateChanged(__pPlayer->GetState());
1005 AppLogDebug("EXIT");
1009 //AppLogException("[%ls]", GetErrorMessage(r));
1014 PlayerPresentationModel::MovePreviousContent(bool forceMove)
1016 AppLogDebug("ENTER");
1017 if (__pPlayer == null)
1019 AppLogDebug("EXIT");
1023 result r = E_SUCCESS;
1024 String currentDuration = null;
1026 // if ((__pPlayer->GetState() == PLAYER_STATE_PLAYING || __pPlayer->GetState() == PLAYER_STATE_PAUSED) && (__playposition > MIN_REWIND_POSITION))
1027 if (__playposition > MIN_REWIND_POSITION && forceMove != true)
1029 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1030 TryCatch(r == E_SUCCESS, , "SeekTo failed. [%ls]", GetErrorMessage(r));
1031 __playposition = MIN_SLIDER_COUNT;
1032 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1033 CallOnPlayTimeChanged(currentDuration, __playposition);
1034 AppLogDebug("EXIT");
1039 // InitializeProgress();
1040 // InitializePlayer();
1041 /* if(IsShuffleEnable())
1043 srand(int(time(NULL)));
1044 __currentContentIndex = rand() % __pPlayContentList->GetCount();
1048 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1050 __currentContentIndex = __pPlayContentList->GetCount() - 1;
1054 __currentContentIndex--;
1057 __removedContentIndex = INIT_CONTENT_INDEX;
1060 __currentContentIndex = __previousContentIndex;
1061 GenerateNextIndex();
1062 __removedContentIndex = INIT_CONTENT_INDEX;
1064 if (__pPlayContentList->GetCount() > 0)
1066 CallOnPlayContentChanged(__currentContentIndex);
1067 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1070 __seekCompleted = false;
1071 __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1072 InitializeProgress();
1075 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1077 AppLogDebug("EXIT");
1081 //AppLogException("[%s]", GetErrorMessage(r));
1086 PlayerPresentationModel::MoveNextContent(void)
1088 AppLogDebug("ENTER");
1089 if (__pPlayer == null)
1091 AppLogDebug("EXIT");
1094 __currentContentIndex = __nextContentIndex;
1095 GenerateNextIndex();
1096 __removedContentIndex = INIT_CONTENT_INDEX;
1098 if (__pPlayContentList->GetCount() > 0)
1100 CallOnPlayContentChanged(__currentContentIndex);
1101 if (GetPlayerState() == PLAYER_STATE_PAUSED)
1104 __seekCompleted = false;
1105 __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1106 InitializeProgress();
1109 // Play(__currentContentIndex, MIN_SLIDER_COUNT);
1111 AppLogDebug("EXIT");
1116 PlayerPresentationModel::SeekToRewind(void)
1118 AppLogDebug("ENTER");
1119 int playDuration = __pPlayer->GetDuration();
1120 __playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1122 AppLogDebug("EXIT");
1126 PlayerPresentationModel::Rewind(void)
1128 AppLogDebug("ENTER");
1129 __playposition = __playposition - __xTimesValue;
1130 result r = SetPlayPosition(__playposition);
1133 StopForwardRewind();
1137 if (__playposition < MIN_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1139 StopForwardRewind();
1143 if (__pFastRewindTimer != null)
1145 r = __pFastRewindTimer->Start(PROGRESS_TIMER_DURATION);
1146 TryCatch(r == E_SUCCESS, , "__pFastRewindTimer start failed. [%ls]", GetErrorMessage(r));
1149 AppLogDebug("EXIT");
1153 //AppLogException("[%ls]", GetErrorMessage(r));
1158 PlayerPresentationModel::SeekToForward(void)
1160 AppLogDebug("ENTER");
1161 int playDuration = __pPlayer->GetDuration();
1162 if(playDuration != 0)
1164 __playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1167 AppLogDebug("EXIT");
1171 PlayerPresentationModel::Forward(void)
1173 AppLogDebug("ENTER");
1174 __playposition = __playposition - __xTimesValue;
1175 result r = SetPlayPosition(__playposition);
1178 AppLogDebug("SetPlayPosition Failed %s",GetErrorMessage(r));
1179 StopForwardRewind();
1183 if (__playposition > MAX_SLIDER_COUNT && GetPlayerState() == PLAYER_STATE_PAUSED)
1185 StopForwardRewind();
1189 if (__pFastForwardTimer != null)
1191 r = __pFastForwardTimer->Start(PROGRESS_TIMER_DURATION);
1192 TryCatch(r == E_SUCCESS, , "__pFastForwardTimer start failed. [%ls]", GetErrorMessage(r));
1195 AppLogDebug("EXIT");
1199 //AppLogException("[%ls]", GetErrorMessage(r));
1204 PlayerPresentationModel::StopForwardRewind(void)
1206 AppLogDebug("ENTER");
1207 result r = E_SUCCESS;
1209 if (__pFastForwardTimer != null)
1211 r = __pFastForwardTimer->Cancel();
1212 TryLog(r == E_SUCCESS, "[%s] __pFastForwardTimer cancel failed", GetErrorMessage(r));
1215 if (__pFastRewindTimer != null)
1217 r = __pFastRewindTimer->Cancel();
1218 TryLog(r == E_SUCCESS, "[%s] __pFastRewindTimer cancel failed", GetErrorMessage(r));
1221 __xTimesValue = INIT_X_VALUE;
1222 __seekCompleted = true;
1223 AppLogDebug("EXIT");
1228 PlayerPresentationModel::SetPlayPosition(int playPosition)
1230 AppLogDebug("ENTER");
1231 if (__pPlayer == null)
1233 AppLogDebug("EXIT");
1237 result r = E_SUCCESS;
1238 String currentDuration = null;
1240 if (/*(playPosition >= MIN_SLIDER_COUNT) && (playPosition <= TIMER_INTERVAL) &&*/ __seekCompleted == true)
1242 if (GetPlayerState() == PLAYER_STATE_PLAYING || GetPlayerState() == PLAYER_STATE_PAUSED)
1244 if (playPosition >= MAX_SLIDER_COUNT)
1246 r = __pPlayer->SeekTo(__pPlayer->GetDuration());
1247 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1248 // StopForwardRewind();
1249 // __seekCompleted = false;
1252 else if (playPosition <= MIN_SLIDER_COUNT)
1254 r = __pPlayer->SeekTo(MIN_SLIDER_COUNT);
1255 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1259 r = __pPlayer->SeekTo(playPosition * (__pPlayer->GetDuration() / TIMER_INTERVAL));
1260 TryCatch(r == E_SUCCESS, , "__pPlayer seekto failed..\n");
1262 TryCatch(r == E_SUCCESS, r = E_FAILURE, "Unable to seek to.\n");
1264 __playposition = playPosition;
1265 __lastPosition = __playposition;
1266 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1267 CallOnPlayTimeChanged(currentDuration, __playposition);
1268 __seekCompleted = false;
1272 // __playposition = playPosition;
1273 // currentDuration = CommonUtil::GetFormatDate(playPosition * (__currentPlayContentDuration / TIMER_INTERVAL));
1274 // CallOnPlayTimeChanged(currentDuration, __playposition);
1275 __seekCompleted = true;
1280 __lastPosition = playPosition;
1283 AppLogDebug("EXIT");
1287 //AppLogException( "[%s]", GetErrorMessage(r));
1288 if (__pPlayer->GetDuration() > MIN_SLIDER_COUNT)
1290 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1291 CallOnPlayTimeChanged(currentDuration, __playposition);
1293 __seekCompleted = false;
1294 AppLogDebug("EXIT");
1299 PlayerPresentationModel::GetPlayPosition(void)
1301 AppLogDebug("ENTER");
1302 AppLogDebug("EXIT");
1303 return __playposition;
1307 PlayerPresentationModel::GetCurrentDuration(void)
1309 AppLogDebug("ENTER");
1310 String currentDuration;
1311 if (__pPlayer != null)
1313 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1317 currentDuration = CommonUtil::GetFormatDate(INIT_VALUE);
1319 AppLogDebug("EXIT");
1320 return currentDuration;
1324 PlayerPresentationModel::SetContentList(IList* pArgs)
1326 AppLogDebug("ENTER");
1327 result r = E_SUCCESS;
1328 String* temp = null;
1330 if (__pPlayContentList == null)
1332 __pPlayContentList = new (std::nothrow) ArrayList();
1333 TryCatch(__pPlayContentList != null, r = E_OUT_OF_MEMORY, "Unable to create ArrayList.\n");
1335 r = __pPlayContentList->Construct();
1336 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Construct ArrayList.\n");
1340 __pPlayContentList->RemoveAll(true);
1343 temp = static_cast<String*>(pArgs->GetAt(0));
1344 if (temp->Equals(MUSIC, true))
1346 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(2));
1347 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1349 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1350 while (pEnum->MoveNext() == E_SUCCESS)
1352 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1353 AppLogDebug("%ls", pContentPath->GetPointer());
1354 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1359 ArrayList* pContentList = static_cast<ArrayList*>(pArgs->GetAt(0));
1360 TryReturn(pContentList != null, E_FAILURE, "pArgs->GetAt(0) is null.")
1362 IEnumerator* pEnum = pContentList->GetEnumeratorN();
1363 while (pEnum->MoveNext() == E_SUCCESS)
1365 String* pContentPath = static_cast<String*>(pEnum->GetCurrent());
1366 AppLogDebug("%ls", pContentPath->GetPointer());
1367 __pPlayContentList->Add(new (std::nothrow) String(*pContentPath));
1371 AppLogDebug("EXIT");
1375 //AppLogException("[%s].\n",GetErrorMessage(r));
1376 if (__pPlayContentList != null)
1378 delete __pPlayContentList;
1379 __pPlayContentList = null;
1385 PlayerPresentationModel::GetContentListCount(void)const
1387 AppLogDebug("ENTER");
1388 if (__pPlayContentList != null)
1390 AppLogDebug("EXIT");
1391 return __pPlayContentList->GetCount();
1395 AppLogDebug("EXIT");
1401 PlayerPresentationModel::SetVolume(int volume)
1403 AppLogDebug("ENTER");
1404 String key(MEDIA_VOLUME);
1405 result r = E_SUCCESS;
1407 if (__pVolumeBarStateTimer != null)
1409 r = __pVolumeBarStateTimer->Cancel();
1410 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel failed.", GetErrorMessage(r));
1411 r = __pVolumeBarStateTimer->Start(VOLUMEBAR_INTERVAL);
1412 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to Start __pVolumeBarStateTimer.\n");
1415 if (volume >= 0 && volume <= 15)
1417 SettingInfo::SetValue(key, volume);
1419 AppLogDebug("EXIT");
1423 //AppLogException("[%ls]", GetErrorMessage(r));
1428 PlayerPresentationModel::GetVolume(void)
1430 AppLogDebug("ENTER");
1432 String key(MEDIA_VOLUME);
1433 SettingInfo::GetValue(key, volume);
1434 AppLogDebug("EXIT");
1439 PlayerPresentationModel::SetShuffleEnable(bool shuffleEnable)
1441 AppLogDebug("ENTER");
1442 /* int __totalCount = 0;
1444 if (__pPlayContentList != null)
1446 __totalCount = __pPlayContentList->GetCount();
1449 if (shuffleEnable == true)
1454 srand(int(time(NULL)));
1455 for (int i = 0; i < __totalCount; i++)
1457 nDust = rand() % __totalCount;
1458 nSour = rand() % __totalCount;
1460 nTemp = __pPlayContentIndexOrder[nDust];
1461 __pPlayContentIndexOrder[nDust] = __pPlayContentIndexOrder[nSour];
1462 __pPlayContentIndexOrder[nSour] = nTemp;
1465 for (int i = 0; i < __totalCount; i++)
1467 if (__pPlayContentIndexOrder[i] - 1 == __currentContentIndex)
1469 nTemp = __pPlayContentIndexOrder[i];
1470 __pPlayContentIndexOrder[i] = __pPlayContentIndexOrder[__currentContentIndex];
1471 __pPlayContentIndexOrder[__currentContentIndex] = nTemp;
1477 int currentIndex = __currentContentIndex;
1478 __currentContentIndex = __pPlayContentIndexOrder[currentIndex] - 1;
1479 for (int i=0; i<__totalCount; i++)
1481 __pPlayContentIndexOrder[i]=i + 1;
1484 __shuffleEnable = shuffleEnable;
1485 GenerateNextIndex();
1486 AppLogDebug("EXIT");
1490 PlayerPresentationModel::SetRepeatMode(int repeatMode)
1492 AppLogDebug("ENTER");
1493 __repeatMode = repeatMode;
1494 AppLogDebug("EXIT");
1498 PlayerPresentationModel::IsShuffleEnable(void)
1500 AppLogDebug("ENTER");
1501 AppLogDebug("EXIT");
1502 return __shuffleEnable;
1506 PlayerPresentationModel::IsFileExist(int contentIndex) const
1508 AppLogDebug("ENTER");
1509 TryReturn(contentIndex >= 0 && contentIndex < __pPlayContentList->GetCount(), false, "contentIndex is invalid.")
1510 String* pFilePath = GetContentPath(contentIndex);
1514 result r = file.Construct(*pFilePath, "r");
1515 TryReturn(r == E_SUCCESS, false, "File construct was failed.")
1517 AppLogDebug("EXIT");
1518 return file.IsFileExist(*pFilePath);
1522 PlayerPresentationModel::GetRepeatState(void)
1524 AppLogDebug("ENTER");
1525 AppLogDebug("EXIT");
1526 return __repeatMode;
1530 PlayerPresentationModel::GetFileName(String* pFilePath)
1532 AppLogDebug("ENTER");
1533 String path = Tizen::Io::File::GetFileName(*pFilePath);
1534 String strRemoveTemp = IDS_BLANK;
1535 int removeIndex = -1 ;
1536 path.LastIndexOf(IDS_PERIOD, path.GetLength() - 1, removeIndex);
1537 path.SubString(removeIndex + 1, strRemoveTemp);
1538 String strTemp = IDS_BLANK;
1540 path.Remove(removeIndex, strRemoveTemp.GetLength() + 1);
1541 path.SubString(0, strTemp);
1542 AppLogDebug("EXIT");
1547 PlayerPresentationModel::InitializeProgress(void)
1549 AppLogDebug("ENTER");
1550 result r = E_SUCCESS;
1552 String currentDuration = null;
1553 if (__pPlayer != null)
1555 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1559 currentDuration = INITIAL_TIME;
1562 if (__pPlayStateTimer != null /*&& __previousPlayerState != PLAYER_STATE_INITIALIZED*/
1563 && __previousPlayerState != PLAYER_STATE_PAUSED
1564 && __previousPlayerState != PLAYER_STATE_CLOSED)
1566 r = __pPlayStateTimer->Cancel();
1567 TryLog(r == E_SUCCESS, "[%s] __pPlayStateTimer cancel failed.", GetErrorMessage(r));
1569 __playposition = MIN_SLIDER_COUNT;
1570 // __seekCompleted = true;
1571 __xTimesValue = INIT_VALUE;
1572 CallOnPlayTimeChanged(currentDuration, __playposition);
1573 AppLogDebug("EXIT");
1578 PlayerPresentationModel::UpdateContentDB(void)
1580 AppLogDebug("ENTER");
1581 result r = E_SUCCESS;
1583 String contentIdString;
1584 ArrayList* pTempList = null;
1586 Tizen::Base::String contentPath = *static_cast<String*>(__pPlayContentList->GetAt(__currentContentIndex));
1587 if (File::IsFileExist(contentPath) == false)
1589 AppLogDebug("File not exist(%ls)", contentPath.GetPointer());
1593 ContentId contentId = CommonUtil::GetContentId(contentPath);
1594 if (IsFailed(GetLastResult()))
1596 AppLogDebug("CommonUtil::GetContentId(%ls) failed", contentPath.GetPointer());
1601 Tizen::System::SystemTime::GetCurrentTime(Tizen::System::TIME_MODE_STANDARD, playTime);
1602 Tizen::Base::String playTimeString = playTime.ToString();
1604 PlaylistDB* pPlaylistDB = new (std::nothrow) PlaylistDB();
1605 r = pPlaylistDB->CreatePlaylistDatabase();
1606 TryCatch(r == E_SUCCESS,,"CreatePlaylistDatabase() failed with error %s",GetErrorMessage(r));
1608 pTempList = new (std::nothrow) ArrayList();
1609 pTempList->Construct();
1611 contentIdString = contentId.ToString();
1612 if (pPlaylistDB->Read(contentIdString) != E_KEY_ALREADY_EXIST)
1614 pPlaylistDB->Insert(contentIdString, playCount + 1, playTimeString);
1618 pTempList = pPlaylistDB->ReadValueN(contentIdString);
1619 if (pTempList != null)
1621 playCount = static_cast<Integer*>(pTempList->GetAt(0))->ToInt();
1623 pPlaylistDB->Update(contentIdString, playCount + 1, playTimeString);
1628 if (pPlaylistDB != null)
1634 if (pTempList != null)
1636 pTempList->RemoveAll(true);
1640 AppLogDebug("EXIT");
1644 PlayerPresentationModel::GenerateNextIndex(void)
1646 AppLogDebug("ENTER");
1647 if (IsShuffleEnable())
1649 int totalCount = __pPlayContentList->GetCount();
1653 __previousContentIndex = 0;
1654 __nextContentIndex = 0;
1658 srand(int(time(NULL)));
1659 __previousContentIndex = rand() % totalCount;
1660 while (__previousContentIndex == __currentContentIndex)
1662 __previousContentIndex = rand() % totalCount;
1665 __nextContentIndex = rand() % totalCount;
1666 while (__nextContentIndex == __currentContentIndex)
1668 __nextContentIndex = rand() % totalCount;
1674 if (__pPlayContentList->GetCount() == 0)
1676 __previousContentIndex = 0;
1677 __nextContentIndex = 0;
1681 if (__currentContentIndex == 0 || __removedContentIndex == __pPlayContentList->GetCount())
1683 __previousContentIndex = __pPlayContentList->GetCount() - 1;
1687 __previousContentIndex = __currentContentIndex - 1;
1690 if (__currentContentIndex == __pPlayContentList->GetCount() - 1
1691 || __removedContentIndex == __pPlayContentList->GetCount())
1693 __nextContentIndex = 0;
1697 if (__removedContentIndex != INIT_CONTENT_INDEX)
1699 __nextContentIndex = __previousContentIndex + 1;
1700 if (__nextContentIndex > __pPlayContentList->GetCount() - 1)
1702 __nextContentIndex = 0;
1707 __nextContentIndex = __currentContentIndex + 1;
1711 AppLogDebug("EXIT");
1715 PlayerPresentationModel::OnPlayerOpened(result r)
1717 AppLogDebug("ENTER");
1718 AppLogDebug("EXIT");
1722 PlayerPresentationModel::OnPlayerReleased(void)
1724 AppLogDebug("ENTER");
1725 if (__pPlayer != null && (__pPlayer->GetState() == PLAYER_STATE_PAUSED))
1727 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1729 AppLogDebug("EXIT");
1733 PlayerPresentationModel::OnPlayerEndOfClip(void)
1735 AppLogDebug("ENTER");
1736 // StopForwardRewind();
1738 if (__pPlayer == null)
1740 AppLogDebug("EXIT");
1743 __seekCompleted = true;
1744 AppLogDebug("GetRepeatState() : %d", GetRepeatState());
1745 switch (GetRepeatState())// 0 - 2 (OFF, ONE, ALL)
1749 while (__pPlayContentList->GetCount() > 0 && IsFileExist(__currentContentIndex) == false)
1751 RemoveContent(*GetContentPath(__currentContentIndex));
1754 InitializeProgress();
1756 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1762 if (__pPlayContentList->GetCount() - 1 == __currentContentIndex)
1764 StopForwardRewind();
1765 InitializeProgress();
1766 Play(__currentContentIndex, MIN_SLIDER_COUNT, true);
1771 while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1773 RemoveContent(*GetContentPath(GetNextContentIndex()));
1776 InitializeProgress();
1777 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1784 while (__pPlayContentList->GetCount() > 0 && IsFileExist(GetNextContentIndex()) == false)
1786 RemoveContent(*GetContentPath(GetNextContentIndex()));
1789 InitializeProgress();
1790 Play(__currentContentIndex, MIN_SLIDER_COUNT);
1797 AppLogDebug("EXIT");
1801 PlayerPresentationModel::OnPlayerBuffering(int percent)
1803 AppLogDebug("ENTER");
1804 if (__pPlayer == null)
1806 AppLogDebug("EXIT");
1809 CallOnPlayStateChanged(__pPlayer->GetState());
1810 AppLogDebug("EXIT");
1814 PlayerPresentationModel::OnPlayerErrorOccurred(PlayerErrorReason r)
1816 AppLogDebug("ENTER");
1817 if (__pPlayer == null)
1819 AppLogDebug("EXIT");
1822 CallOnPlayStateChanged(__pPlayer->GetState());
1823 AppLogDebug("EXIT");
1827 PlayerPresentationModel::OnPlayerInterrupted(void)
1829 AppLogDebug("ENTER");
1831 AppLogDebug("EXIT");
1836 PlayerPresentationModel::OnPlayerSeekCompleted(result r)
1838 AppLogDebug("ENTER %s",GetErrorMessage(r));
1841 __seekCompleted = true;
1845 __seekCompleted = false;
1848 if (__lastPosition != __playposition)
1850 SetPlayPosition(__lastPosition);
1852 AppLogDebug("EXIT");
1856 PlayerPresentationModel::OnPlayerAudioFocusChanged(void)
1858 AppLogDebug("ENTER");
1859 /*__audioFocusChanged = true;*/
1861 AppLogDebug("EXIT");
1865 PlayerPresentationModel::OnAudioSessionInterrupted(void)
1867 AppLogDebug("ENTER");
1868 AppLogDebug("EXIT");
1872 PlayerPresentationModel::OnAudioSessionInterruptReleased(void)
1874 AppLogDebug("ENTER");
1875 AppLogDebug("EXIT");
1879 PlayerPresentationModel::OnAudioSessionAudioFocusChanged(void)
1881 AppLogDebug("ENTER");
1882 AppLogDebug("EXIT");
1886 PlayerPresentationModel::OnTimerExpired(Timer& timer)
1888 AppLogDebug("ENTER");
1889 if (__pPlayer == null)
1891 AppLogDebug("EXIT");
1895 result r = E_SUCCESS;
1896 if (__pPlayStateTimer == &timer)
1898 PlayerState playerState = __pPlayer->GetState() ;
1899 String currentDuration = null;
1900 int playDuration = __pPlayer->GetDuration();
1902 switch (playerState)
1904 case PLAYER_STATE_PLAYING:
1906 long int totalDuration = __pPlayer->GetDuration();
1907 TryReturnVoid(playDuration != 0, "playDuration is zero.");
1909 if (totalDuration < 2*PROGRESS_BAR_DURATION_TIMER)
1911 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER/10);
1915 r = __pPlayStateTimer->Start(PROGRESS_BAR_DURATION_TIMER);
1918 TryCatch(r == E_SUCCESS, , "__pPlayStateTimer start failed..\n");
1919 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
1920 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1921 __playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1922 CallOnPlayTimeChanged(currentDuration, __playposition);
1926 case PLAYER_STATE_PAUSED:
1928 TryReturnVoid(__seekCompleted == true, "SeekTo is not complete.");
1929 TryReturnVoid(playDuration != 0, "playDuration is zero.");
1930 currentDuration = CommonUtil::GetFormatDate(__pPlayer->GetPosition());
1931 __playposition = static_cast<int>(__pPlayer->GetPosition() / (playDuration / TIMER_INTERVAL));
1932 CallOnPlayTimeChanged(currentDuration, __playposition);
1940 else if (__pFastForwardTimer == &timer)
1945 else if (__pFastRewindTimer == &timer)
1950 else if (__pAutoOffTimer == &timer)
1952 Application::GetInstance()->Terminate();
1954 else if (__pPauseAutoOffTimer == &timer)
1956 Application::GetInstance()->Terminate();
1958 else if (__pVolumeBarStateTimer == &timer)
1960 r = __pVolumeBarStateTimer->Cancel();
1961 TryLog(r == E_SUCCESS, "[%s] __pVolumeBarStateTimer cancel Failed.", GetErrorMessage(r));
1962 CallOnPlayVolumeBarStateChanged();
1966 //AppLogDebug("Timer is invalid value.");
1968 AppLogDebug("EXIT");
1973 //AppLogException("[%ls]", GetErrorMessage(r));
1978 PlayerPresentationModel::AddMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
1980 AppLogDebug("ENTER");
1981 __musicPlayerEventListener.Add(const_cast<IMusicPlayerEventListener*>(&listener));
1982 AppLogDebug("EXIT");
1986 PlayerPresentationModel::RemoveMusicPlayerEventListener(const IMusicPlayerEventListener& listener)
1988 AppLogDebug("ENTER");
1989 __musicPlayerEventListener.Remove(const_cast<IMusicPlayerEventListener*>(&listener));
1990 AppLogDebug("EXIT");
1994 PlayerPresentationModel::CallOnPlayStateChanged(PlayerState playerState)
1996 AppLogDebug("ENTER");
1997 IMusicPlayerEventListener* pListener = null;
1998 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
1999 while (pEnum->MoveNext() == E_SUCCESS)
2001 pEnum->GetCurrent(pListener);
2002 if (pListener != null)
2004 pListener->OnPlayStateChanged(playerState);
2008 AppLogDebug("EXIT");
2012 PlayerPresentationModel::CallOnPlayContentChanged(int currentContentIndex)
2014 AppLogDebug("ENTER");
2015 IMusicPlayerEventListener* pListener = null;
2016 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2017 while (pEnum->MoveNext() == E_SUCCESS)
2019 pEnum->GetCurrent(pListener);
2020 if (pListener != null)
2022 pListener->OnPlayContentChanged(currentContentIndex);
2026 AppLogDebug("EXIT");
2030 PlayerPresentationModel::CallOnPlayContentRemoved(int removedContentIndex)
2032 AppLogDebug("ENTER");
2033 IMusicPlayerEventListener* pListener = null;
2034 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2035 while (pEnum->MoveNext() == E_SUCCESS)
2037 pEnum->GetCurrent(pListener);
2038 if (pListener != null)
2040 pListener->OnPlayContentRemoved(removedContentIndex);
2044 AppLogDebug("EXIT");
2048 PlayerPresentationModel::CallOnPlayTimeChanged(Tizen::Base::String& currentDuration, int currentPosition)
2050 AppLogDebug("ENTER");
2051 IMusicPlayerEventListener* pListener = null;
2052 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2053 while (pEnum->MoveNext() == E_SUCCESS)
2055 pEnum->GetCurrent(pListener);
2056 if (pListener != null)
2058 pListener->OnPlayTimeChanged(currentDuration, currentPosition);
2062 AppLogDebug("EXIT");
2066 PlayerPresentationModel::CallOnPlayVolumeBarStateChanged(void)
2068 AppLogDebug("ENTER");
2069 IMusicPlayerEventListener* pListener = null;
2070 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2071 while (pEnum->MoveNext() == E_SUCCESS)
2073 pEnum->GetCurrent(pListener);
2074 if (pListener != null)
2076 pListener->OnPlayVolumeBarStateChanged();
2080 AppLogDebug("EXIT");
2084 PlayerPresentationModel::CallOnPlayPresentationModelDestroying(void)
2086 AppLogDebug("ENTER");
2087 IMusicPlayerEventListener* pListener = null;
2088 IEnumeratorT<IMusicPlayerEventListener*>* pEnum = __musicPlayerEventListener.GetEnumeratorN();
2089 while (pEnum->MoveNext() == E_SUCCESS)
2091 pEnum->GetCurrent(pListener);
2092 if (pListener != null)
2094 pListener->OnPlayPresentationModelDestroying();
2098 AppLogDebug("EXIT");