musicplayer: set new path when playing music 03/44403/2
authorMinkyu Kang <mk7.kang@samsung.com>
Tue, 21 Jul 2015 11:35:06 +0000 (20:35 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Wed, 22 Jul 2015 02:11:38 +0000 (11:11 +0900)
Change-Id: I5f168c3570557a500c55b9f8cb3864db1d42557d
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
include/util/playermgr.h
src/util/playermgr.c
src/view/mplayer.c

index 0eafe4b..46c6005 100644 (file)
@@ -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
index 8adbdd8..4cd046a 100644 (file)
 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);
 }
index 17e43f0..a065194 100644 (file)
@@ -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);
        }
 }