From: Minkyu Kang Date: Tue, 21 Jul 2015 11:35:06 +0000 (+0900) Subject: musicplayer: set new path when playing music X-Git-Tag: accepted/tizen/tv/20150728.070555~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=691ec07cd48502ab0e9c9bcf92213797ebe1662f;p=profile%2Ftv%2Fapps%2Fnative%2Fair_mediahub.git musicplayer: set new path when playing music Change-Id: I5f168c3570557a500c55b9f8cb3864db1d42557d Signed-off-by: Minkyu Kang --- diff --git a/include/util/playermgr.h b/include/util/playermgr.h index 0eafe4b..46c6005 100644 --- a/include/util/playermgr.h +++ b/include/util/playermgr.h @@ -34,5 +34,6 @@ bool playermgr_set_position(struct playermgr *m, int ms, void playermgr_get_state(struct playermgr *m, player_state_e *state); bool playermgr_set_completed_cb(struct playermgr *m, player_completed_cb cb, void *data); +const char *playermgr_get_path(struct playermgr *m); #endif diff --git a/src/util/playermgr.c b/src/util/playermgr.c index 8adbdd8..4cd046a 100644 --- a/src/util/playermgr.c +++ b/src/util/playermgr.c @@ -24,8 +24,29 @@ struct playermgr { Evas_Object *win; player_h player; + char *path; }; +static void _set_path(struct playermgr *m, const char *path) +{ + free(m->path); + + if (path) + m->path = strdup(path); + else + m->path = NULL; +} + +const char *playermgr_get_path(struct playermgr *m) +{ + if (!m) { + _ERR("invalid parameter"); + return NULL; + } + + return m->path; +} + int playermgr_get_duration(struct playermgr *m) { int r; @@ -155,6 +176,8 @@ void playermgr_stop(struct playermgr *m) player_pause(m->player); player_stop(m->player); player_unprepare(m->player); + + _set_path(m, NULL); } bool playermgr_play(struct playermgr *m, const char *path, int ms) @@ -174,6 +197,8 @@ bool playermgr_play(struct playermgr *m, const char *path, int ms) return false; } + _set_path(m, path); + if (m->win) { r = player_set_display(m->player, PLAYER_DISPLAY_TYPE_OVERLAY, GET_DISPLAY(m->win)); @@ -246,6 +271,7 @@ struct playermgr *playermgr_create(Evas_Object *win) } m->win = win; + m->path = NULL; return m; } @@ -262,5 +288,6 @@ void playermgr_destroy(struct playermgr *m) player_destroy(m->player); } + free(m->path); free(m); } diff --git a/src/view/mplayer.c b/src/view/mplayer.c index 17e43f0..a065194 100644 --- a/src/view/mplayer.c +++ b/src/view/mplayer.c @@ -302,28 +302,47 @@ static void _player_play(struct _priv *priv) { app_media_info *mi; player_state_e state; + const char *path; + struct controller *ctl; + + mi = _get_current_media_info(priv); + if (!mi) { + _ERR("failed to getting media info"); + return; + } playermgr_get_state(priv->player, &state); switch (state) { case PLAYER_STATE_IDLE: case PLAYER_STATE_READY: - mi = _get_current_media_info(priv); - if (!mi) { - _ERR("failed to getting media info"); - return; - } - progressbar_start(priv->progress); playermgr_play(priv->player, mi->file_path, 0); break; case PLAYER_STATE_PAUSED: + path = playermgr_get_path(priv->player); + if (path && !strcmp(mi->file_path, path)) + playermgr_resume(priv->player); + else + playermgr_play(priv->player, mi->file_path, 0); + + progressbar_resume(priv->progress); + break; case PLAYER_STATE_PLAYING: + path = playermgr_get_path(priv->player); + if (path && !strcmp(mi->file_path, path)) + break; + + progressbar_start(priv->progress); + playermgr_play(priv->player, mi->file_path, 0); break; default: _ERR("player was not created"); break; } + + ctl = priv->ctl; + ctl->ops->signal(ctl->handle, PLAY_BTN_LOC, SIG_SET_PAUSE); } static void _player_stop(struct _priv *priv) @@ -472,7 +491,7 @@ static void _list_selected(int id, void *data, if (priv->playlist.cur != index) { _mplayer_set_current(priv, index); - _player_next(priv); + _player_play(priv); } }