int CMusicController::refCnt = 0;
-void IMusicControllerListener::sm_CbComplete(void *cookie)
+// Implementation of IMusicControllerListener
+void IMusicControllerListener::s_CbComplete(void *cookie)
{
IMusicControllerListener *root = (IMusicControllerListener *)cookie;
if (root)
- root->t_OnComplete();
+ root->OnComplete();
}
-void IMusicControllerListener::sm_CbError(void *cookie)
+void IMusicControllerListener::s_CbError(void *cookie)
{
IMusicControllerListener *root = (IMusicControllerListener *)cookie;
if (root)
- root->t_OnError();
+ root->OnError();
}
-void IMusicControllerListener::sm_CbUsbConnected(void *cookie)
+void IMusicControllerListener::s_CbUsbConnected(void *cookie)
{
IMusicControllerListener *root = (IMusicControllerListener *)cookie;
if (root)
- root->t_OnUsbConnected();
+ root->OnUsbConnected();
}
-void IMusicControllerListener::sm_CbUpdateContent(void *cookie)
+void IMusicControllerListener::s_CbUpdateContent(void *cookie)
{
IMusicControllerListener *root = (IMusicControllerListener *)cookie;
if (root)
- root->t_OnUpdateContent();
+ root->OnUpdateContent();
}
-static void _run_callback(SMusicController *m, int type)
+// Implementation of CMusicController
+void CMusicController::sm_CbPlaybackCompletion(void *dt)
{
+ CMusicController* root = (CMusicController*)dt;
+ if (root)
+ root->m_OnPlaybackCompletion();
+}
+
+
+void CMusicController::m_OnPlaybackCompletion(void)
+{
+ bool r;
Eina_List *l;
- SCbInfo *cbinfo;
+ IMusicControllerListener *mcListener = NULL;
+ void *obj;
+
+ r = t_PlayNext(DIR_NEXT, E_ON_COMPLETE);
+ if (r == false)
+ _ERR(" music play next song failed ");
+
+ EINA_LIST_FOREACH(m->elListener, l, obj) {
+ mcListener = (IMusicControllerListener *)obj;
+ if (mcListener)
+ mcListener->s_CbComplete(mcListener);
+ }
+}
+
+
+void CMusicController::sm_CbContentUpdated(void *dt)
+{
+ CMusicController *root = (CMusicController *)dt;
+ if (root)
+ root->m_OnContentUpdated();
+}
+
+
+void CMusicController::m_OnContentUpdated(void)
+{
+ Eina_List *l;
+ IMusicControllerListener *mcListener = NULL;
+ void *obj;
+
+ EINA_LIST_FOREACH(m->elListener, l, obj) {
+ mcListener = (IMusicControllerListener *)obj;
+ if (mcListener)
+ mcListener->s_CbUpdateContent(mcListener);
+ }
+}
+
+
+void CMusicController::m_InvokeErrorCallback(SMusicController *m, int type)
+{
+ Eina_List *l;
+ IMusicControllerListener *mcListener = NULL;
void *obj;
if (!m)
return;
EINA_LIST_FOREACH(m->elListener, l, obj) {
- cbinfo = (SCbInfo *)obj;
- if (cbinfo->type == type && cbinfo->cb)
- cbinfo->cb(cbinfo->data);
+ mcListener = (IMusicControllerListener *)obj;
+ if (mcListener)
+ mcListener->s_CbError(mcListener);
}
}
Stop();
if (playnext_type == E_ON_COMPLETE &&
- m->repeatstate == REPEAT_STATUS_ONE)
+ m->repeatstate == REPEAT_STATUS_ONE)
goto finish;
if (direction == DIR_NEXT) {
r = m->pPlaylist->LoadNextSong(m->stateShuffle);
- } else {
+ }
+ else {
r = m->pPlaylist->LoadPreviousSong(m->stateShuffle);
}
}
if (playnext_type == E_ON_COMPLETE &&
- m->repeatstate == REPEAT_STATUS_NONE) {
+ m->repeatstate == REPEAT_STATUS_NONE) {
r = m->pPlaylist->GetCurSongIndex(&index);
if (r == false) {
_ERR(" get cur song index failed ");
return true;
}
-void CMusicController::sm_CbPlaybackCompletion(void *dt)
-{
- CMusicController* root = (CMusicController*)dt;
- if (root)
- root->m_OnPlaybackCompletion();
-}
-
-
-void CMusicController::m_OnPlaybackCompletion(void)
-{
- bool r;
- Eina_List *l;
- SCbInfo *cbinfo;
- void *obj;
-
- r = t_PlayNext(DIR_NEXT, E_ON_COMPLETE);
- if (r == false)
- _ERR(" music play next song failed ");
-
- EINA_LIST_FOREACH(m->elListener, l, obj) {
- cbinfo = (SCbInfo *)obj;
- if (cbinfo->type == E_SONG_COMPLETE && cbinfo->cb)
- cbinfo->cb(cbinfo->data);
- }
-}
-
-
-void CMusicController::sm_CbContentUpdated(void *dt)
-{
- CMusicController *root = (CMusicController *)dt;
- if (root)
- root->m_OnContentUpdated();
-}
-
-
-void CMusicController::m_OnContentUpdated(void)
-{
- Eina_List *l;
- SCbInfo *cbinfo;
- void *obj;
-
- EINA_LIST_FOREACH(m->elListener, l, obj) {
- cbinfo = (SCbInfo *)obj;
- if (cbinfo->type == E_CONTENT_UPDATE && cbinfo->cb)
- cbinfo->cb(cbinfo->data);
- }
-}
-
SMusicController *CMusicController::t_Create(void)
{
}
-bool CMusicController::Initialize(void)
-{
- if (refCnt == 0) {
- instance = new CMusicController;
- if (instance == NULL) {
- return false;
- }
- instance->m = instance->t_Create();
- if (!instance->m) {
- _ERR("music_init failed");
- delete instance;
- instance = NULL;
- return false;
- }
- }
-
- refCnt++;
-
- return true;
-}
-
-
void CMusicController::t_Destroy(void)
{
- SCbInfo *cbinfo;
- void *obj;
-
CUsbConnectionListener::Destroy();
if (m->pPlayback->FlagCreate()) {
m->alinfo->Destroy();
delete m->alinfo;
+ delete m;
+}
- EINA_LIST_FREE(m->elListener, obj) {
- cbinfo = (SCbInfo *)obj;
- free(cbinfo);
+
+bool CMusicController::Initialize(void)
+{
+ if (refCnt == 0) {
+ instance = new CMusicController;
+ if (instance == NULL) {
+ return false;
+ }
+ instance->m = instance->t_Create();
+ if (!instance->m) {
+ _ERR("music_init failed");
+ delete instance;
+ instance = NULL;
+ return false;
+ }
}
- delete m;
+ refCnt++;
+
+ return true;
}
}
-bool CMusicController::UpdatePlaylist(Eina_List *slist, int addmode)
+bool CMusicController::Start(void)
{
ASSERT(m);
- ASSERT(slist);
- if (m->pPlaylist->FlagCreate())
- m->pPlaylist->Update(slist, addmode);
- else {
- if (!m->pPlaylist->Create(slist))
- _ERR(" playlist create failed ");
- }
- return true;
-}
+ const char *songpath;
+ int index;
+ CPlaylist *pPlaylist;
+ CPlayback *pPlayback;
+ CSongInfo *sinfo;
+ char *media_id;
+ pPlaylist = m->pPlaylist;
+ pPlayback = m->pPlayback;
-bool CMusicController::AddListener(IMusicControllerListener *listener)
-{
- ASSERT(m);
- ASSERT(listener);
+ _CREATE_BEGIN{
+ _CHECK(pPlaylist && pPlayback)
+ _CHECK(pPlaylist->GetCurSongIndex(&index))
+ _CHECK(songpath = pPlaylist->SongpathFromIndex(index))
+ _CHECK(pPlayback->SetUri(songpath))
+ _CHECK(pPlayback->Prepare())
+ _CHECK(pPlayback->Start())
- m->elListener = eina_list_append(m->elListener, listener);
+ _WHEN_SUCCESS{
+ m->statePlay = PLAY_STATUS_PLAY;
+
+ _CHECK(m->pPlaylist->GetSonginfoFromIndex(index, &sinfo))
+ _CHECK(media_id = sinfo->Id())
+ _CHECK(m->pMediadata->SetPlayedTime(media_id))
+
+ _WHEN_SUCCESS{
+ bus_send_signal();
+ }
+
+ _CHECK_FAIL{}
+ _CHECK_FAIL{}
+ _CHECK_FAIL{}
+ }
+
+ _CHECK_FAIL{}
+ _CHECK_FAIL{}
+ _CHECK_FAIL{ _ERR("Playback Failed!!"); m_InvokeErrorCallback(m, E_PLAYBACK_ERROR); }
+ _CHECK_FAIL{}
+ _CHECK_FAIL{}
+ _CHECK_FAIL{ _ERR("CMusicController::Start Failed!!"); Stop(); }
+ } _CREATE_END_AND_CATCH{ return false; }
return true;
}
-bool CMusicController::RemoveListener(IMusicControllerListener *listener)
+bool CMusicController::Stop(void)
{
ASSERT(m);
- ASSERT(listener);
- m->elListener = eina_list_remove(m->elListener, listener);
+ if (!m->pPlayback->FlagCreate())
+ return false;
+
+ if (!m->pPlayback->Stop())
+ _ERR(" playback stop failed ");
+
+ m->statePlay = PLAY_STATUS_STOP;
+
+ if (!m->pPlayback->Unprepare())
+ _ERR(" playback unprepare failed");
return true;
}
-bool CMusicController::Start(void)
+bool CMusicController::Resume(void)
{
ASSERT(m);
- const char *songpath;
- int index;
- CPlaylist *pPlaylist;
- CPlayback *pPlayback;
- CSongInfo *sinfo;
- char *media_id;
-
- pPlaylist = m->pPlaylist;
- pPlayback = m->pPlayback;
+ if (!m->pPlayback->FlagCreate())
+ return false;
- if (!pPlaylist || !pPlayback)
- goto error;
+ if (!m->pPlayback->Resume())
+ return false;
- if (!pPlaylist->GetCurSongIndex(&index)) {
- _ERR(" playlist get current song index failed");
- goto error;
- }
+ m->statePlay = PLAY_STATUS_PLAY;
- songpath = pPlaylist->SongpathFromIndex(index);
- if (!songpath) {
- _ERR(" palylist get song path from index failed");
- goto error;
- }
+ return true;
+}
- if (!pPlayback->SetUri(songpath)) {
- _ERR(" playback set uri failed");
- goto playback_error;
- }
- if (!pPlayback->Prepare()) {
- _ERR(" playback prepare failed");
- goto playback_error;
- }
+bool CMusicController::Pause(void)
+{
+ ASSERT(m);
- if (!pPlayback->Start()) {
- _ERR(" playback start failed");
- goto playback_error;
- }
+ if (!m || !m->pPlayback->FlagCreate())
+ return false;
- m->statePlay = PLAY_STATUS_PLAY;
+ if (!m->pPlayback->Pause())
+ return false;
- if (m->pPlaylist->GetSonginfoFromIndex(index, &sinfo)) {
- media_id = sinfo->Id();
- if (media_id) {
- if (m->pMediadata->SetPlayedTime(media_id))
- bus_send_signal();
- } else
- _ERR("song info get media id failed");
- } else
- _ERR("playback get songinfo failed");
+ m->statePlay = PLAY_STATUS_PAUSE;
return true;
-
-playback_error:
- _run_callback(m, E_PLAYBACK_ERROR);
-error:
- Stop();
-
- return false;
}
-bool CMusicController::Stop(void)
+bool CMusicController::AddListener(IMusicControllerListener *listener)
{
ASSERT(m);
+ ASSERT(listener);
- if (!m->pPlayback->FlagCreate())
- return false;
+ m->elListener = eina_list_append(m->elListener, listener);
- if (!m->pPlayback->Stop())
- _ERR(" playback stop failed ");
+ return true;
+}
- m->statePlay = PLAY_STATUS_STOP;
- if (!m->pPlayback->Unprepare())
- _ERR(" playback unprepare failed");
+bool CMusicController::RemoveListener(IMusicControllerListener *listener)
+{
+ ASSERT(m);
+ ASSERT(listener);
+
+ m->elListener = eina_list_remove(m->elListener, listener);
return true;
}
}
-bool CMusicController::PlayNextSong(void)
+bool CMusicController::SetPosition(int milseconds)
{
ASSERT(m);
- return t_PlayNext(DIR_NEXT, E_BUTTON_CLICK);
-}
-
+ if (!m->pPlayback->FlagCreate())
+ return false;
-bool CMusicController::PlayPreviousSong(void)
-{
- ASSERT(m);
+ if (!m->pPlayback->SetPosition(milseconds))
+ return false;
- return t_PlayNext(DIR_PREVIOUS, E_BUTTON_CLICK);
+ return true;
}
-bool CMusicController::PlayIndexSong(int index)
+bool CMusicController::GetPosition(int *const milseconds)
{
ASSERT(m);
- if (!m->pPlaylist->FlagCreate())
+ if (!m->pPlayback->FlagCreate())
return false;
- Stop();
-
- if (!m->pPlaylist->SetCurSongIndex(index))
+ if (!m->pPlayback->GetPosition(milseconds))
return false;
- Start();
-
return true;
}
-bool CMusicController::Resume(void)
+bool CMusicController::SetCurrentSong(char *mediaid)
{
ASSERT(m);
+ ASSERT(mediaid);
- if (!m->pPlayback->FlagCreate())
- return false;
-
- if (!m->pPlayback->Resume())
+ if (!m->pPlaylist->FlagCreate())
return false;
- m->statePlay = PLAY_STATUS_PLAY;
+ m->pPlaylist->SetCurrentSong(mediaid);
return true;
}
-bool CMusicController::Pause(void)
+bool CMusicController::GetCurrentSong(CSongInfo **const sinfo)
{
ASSERT(m);
- if (!m || !m->pPlayback->FlagCreate())
+ int index;
+
+ if (!m->pPlaylist->FlagCreate())
return false;
- if (!m->pPlayback->Pause())
+ if (!m->pPlaylist->GetCurSongIndex(&index)) {
+ _ERR(" playlist get current song index failed");
return false;
+ }
- m->statePlay = PLAY_STATUS_PAUSE;
+ if (!m->pPlaylist->GetSonginfoFromIndex(index, sinfo)) {
+ _ERR(" playlist get current song info failed");
+ return false;
+ }
return true;
}
-bool CMusicController::SetPosition(int milseconds)
+bool CMusicController::UpdatePlaylist(Eina_List *slist, int addmode)
{
ASSERT(m);
+ ASSERT(slist);
- if (!m->pPlayback->FlagCreate())
- return false;
-
- if (!m->pPlayback->SetPosition(milseconds))
- return false;
-
+ if (m->pPlaylist->FlagCreate())
+ m->pPlaylist->Update(slist, addmode);
+ else {
+ if (!m->pPlaylist->Create(slist))
+ _ERR(" playlist create failed ");
+ }
return true;
}
-bool CMusicController::GetPosition(int *const milseconds)
+bool CMusicController::EmptyPlaylist(void)
{
ASSERT(m);
- if (!m->pPlayback->FlagCreate())
+ if (!m->pPlaylist->FlagCreate())
return false;
- if (!m->pPlayback->GetPosition(milseconds))
- return false;
+ m->pPlaylist->Destroy();
return true;
}
-bool CMusicController::RemoveSong(CSongInfo *sinfo, int index)
+bool CMusicController::PlayPreviousSong(void)
{
ASSERT(m);
- ASSERT(sinfo);
-
- int ind;
-
- if (!m->pPlaylist->FlagCreate())
- return false;
- if (!GetCurrentSongIndex(&ind)) {
- _ERR("unable to find current song index");
- return false;
- }
+ return t_PlayNext(DIR_PREVIOUS, E_BUTTON_CLICK);
+}
- if (!m->pPlaylist->RemoveSong(sinfo, index, m->stateShuffle)) {
- _ERR("Song can not be deleted");
- return false;
- }
- if (ind != 0 && ind == index)
- Stop();
+bool CMusicController::PlayNextSong(void)
+{
+ ASSERT(m);
- return true;
+ return t_PlayNext(DIR_NEXT, E_BUTTON_CLICK);
}
-bool CMusicController::EmptyPlaylist(void)
+bool CMusicController::PlayIndexSong(int index)
{
ASSERT(m);
if (!m->pPlaylist->FlagCreate())
return false;
- m->pPlaylist->Destroy();
+ Stop();
+
+ if (!m->pPlaylist->SetCurSongIndex(index))
+ return false;
+
+ Start();
return true;
}
-bool CMusicController::GetCurrentSong(CSongInfo **const sinfo)
+bool CMusicController::RemoveSong(CSongInfo *sinfo, int index)
{
ASSERT(m);
+ ASSERT(sinfo);
- int index;
+ int ind;
if (!m->pPlaylist->FlagCreate())
return false;
- if (!m->pPlaylist->GetCurSongIndex(&index)) {
- _ERR(" playlist get current song index failed");
+ if (!GetCurrentSongIndex(&ind)) {
+ _ERR("unable to find current song index");
return false;
}
- if (!m->pPlaylist->GetSonginfoFromIndex(index, sinfo)) {
- _ERR(" playlist get current song info failed");
+ if (!m->pPlaylist->RemoveSong(sinfo, index, m->stateShuffle)) {
+ _ERR("Song can not be deleted");
return false;
}
- return true;
-}
-
-
-CSongInfo *CMusicController::MediaSongByUri(char *uri)
-{
- ASSERT(m);
- ASSERT(uri);
-
- CSongInfo *sinfo;
-
- sinfo = m->pMediadata->SongByUri(uri);
- if (!sinfo)
- return NULL;
+ if (ind != 0 && ind == index)
+ Stop();
- return sinfo;
+ return true;
}
}
-bool CMusicController::SetCurrentSong(char *mediaid)
+CSongInfo *CMusicController::MediaSongByUri(char *uri)
{
ASSERT(m);
- ASSERT(mediaid);
+ ASSERT(uri);
- if (!m->pPlaylist->FlagCreate())
- return false;
+ CSongInfo *sinfo;
- m->pPlaylist->SetCurrentSong(mediaid);
+ sinfo = m->pMediadata->SongByUri(uri);
+ if (!sinfo)
+ return NULL;
- return true;
+ return sinfo;
}
return;
Eina_List *l;
- SCbInfo *cbinfo;
+ IMusicControllerListener *mcListener = NULL;;
void *obj;
if (CInfo::SourceType() == SOURCE_TYPE_USB) {
}
EINA_LIST_FOREACH(m->elListener, l, obj) {
- cbinfo = (SCbInfo *)obj;
- if (cbinfo->type == E_USB_CONNECT && cbinfo->cb)
- cbinfo->cb(cbinfo->data);
+ mcListener = (IMusicControllerListener *)obj;
+ if (mcListener)
+ mcListener->s_CbUsbConnected(mcListener);
}
}
\ No newline at end of file