mplayer: adds support three state of repeat mode (all/one/none) 28/46428/2
authorMinkyu Kang <mk7.kang@samsung.com>
Thu, 20 Aug 2015 07:28:10 +0000 (16:28 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Fri, 21 Aug 2015 01:05:47 +0000 (10:05 +0900)
Change-Id: I5eee61ce78a29ae2b20db3e4b324579c4e113300
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
src/view/mplayer.c

index 8c3b881..c1cafd0 100644 (file)
 #define PART_MUSIC_BTN "control_btn"
 #define PLAY_BTN_LOC 2
 
+enum _repeat_state {
+       REPEAT_ALL,
+       REPEAT_ONE,
+       REPEAT_NONE
+};
+
 struct _list_data {
        app_media *am;
        Elm_Object_Item *item;
@@ -48,6 +54,7 @@ struct _playlist {
        Eina_List *list_org;
        int cur;
        bool shuffle;
+       enum _repeat_state repeat;
 };
 
 struct _priv {
@@ -227,6 +234,33 @@ static void _playlist_set_list(struct _priv *priv, bool shuffle, int index)
        p->shuffle = shuffle;
 }
 
+static void _playlist_set_repeat_mode(struct _priv *priv)
+{
+       struct _playlist *p;
+
+       p = &priv->playlist;
+       if (!p) {
+               _ERR("playlist is NULL");
+               return;
+       }
+
+       switch (p->repeat) {
+       case REPEAT_ALL:
+               p->repeat = REPEAT_ONE;
+               break;
+       case REPEAT_ONE:
+               p->repeat = REPEAT_NONE;
+               break;
+       case REPEAT_NONE:
+               p->repeat = REPEAT_ALL;
+               break;
+       default:
+               _ERR("Unknown repeat state");
+               p->repeat = REPEAT_ALL;
+               break;
+       }
+}
+
 static void _update_info(struct _priv *priv, app_media_info *mi)
 {
        struct view_update_data vdata;
@@ -278,32 +312,69 @@ static void _mplayer_hide(struct _priv *priv)
        ctl->ops->hide(ctl->handle);
 }
 
-static void _mplayer_prev(struct _priv *priv)
+static bool _mplayer_prev(struct _priv *priv)
 {
        int total;
 
        total = eina_list_count(priv->playlist.list);
 
-       if (priv->playlist.cur == 0)
-               priv->playlist.cur = total - 1;
-       else
-               priv->playlist.cur--;
+       switch (priv->playlist.repeat) {
+       case REPEAT_ALL:
+               if (priv->playlist.cur != 0)
+                       priv->playlist.cur--;
+               else
+                       priv->playlist.cur = total - 1;
+               break;
+       case REPEAT_NONE:
+               if (priv->playlist.cur != 0)
+                       priv->playlist.cur--;
+               break;
+       case REPEAT_ONE:
+               break;
+       default:
+               _ERR("Unknown repeat state");
+               break;
+       }
 
        _mplayer_show(priv);
+
+       return true;
 }
 
-static void _mplayer_next(struct _priv *priv)
+static bool _mplayer_next(struct _priv *priv)
 {
        int total;
+       bool r;
 
        total = eina_list_count(priv->playlist.list);
 
-       if (priv->playlist.cur == total - 1)
-               priv->playlist.cur = 0;
-       else
-               priv->playlist.cur++;
+       r = true;
+
+       switch (priv->playlist.repeat) {
+       case REPEAT_ALL:
+               if (priv->playlist.cur != total - 1)
+                       priv->playlist.cur++;
+               else
+                       priv->playlist.cur = 0;
+               break;
+       case REPEAT_NONE:
+               if (priv->playlist.cur != total - 1)
+                       priv->playlist.cur++;
+               else {
+                       priv->playlist.cur = 0;
+                       r = false;
+               }
+               break;
+       case REPEAT_ONE:
+               break;
+       default:
+               _ERR("Unknown repeat state");
+               break;
+       }
 
        _mplayer_show(priv);
+
+       return r;
 }
 
 static void _mplayer_set_current(struct _priv *priv, int index)
@@ -459,14 +530,18 @@ static void _player_stop(struct _priv *priv)
 static void _player_complete_cb(void *data)
 {
        struct _priv *priv;
+       bool r;
 
        if (!data)
                return;
 
        priv = data;
 
-       _mplayer_next(priv);
-       _player_next(priv);
+       r = _mplayer_next(priv);
+       if (r)
+               _player_next(priv);
+       else
+               _player_stop(priv);
 }
 
 static struct progressbar_ops _progressbar_ops = {
@@ -723,6 +798,7 @@ static void _add_playlist_item(struct _priv *priv)
 static void _callback_music(void *data, const char *ev)
 {
        struct _priv *priv;
+       bool r;
 
        if (!data || !ev)
                return;
@@ -733,8 +809,11 @@ static void _callback_music(void *data, const char *ev)
                _mplayer_prev(priv);
                _player_next(priv);
        } else if (!strcmp(ev, SRC_BTN_MUSIC_NEXT)) {
-               _mplayer_next(priv);
-               _player_next(priv);
+               r = _mplayer_next(priv);
+               if (r)
+                       _player_next(priv);
+               else
+                       _player_stop(priv);
        } else if (!strcmp(ev, SRC_BTN_MUSIC_PLAY)) {
                _player_play_pause(priv);
        } else if (!strcmp(ev, SRC_BTN_MUSIC_SHUFFLE)) {
@@ -744,6 +823,8 @@ static void _callback_music(void *data, const char *ev)
 
                _mplayer_set_current(priv, priv->playlist.cur);
                _player_play(priv);
+       } else if (!strcmp(ev, SRC_BTN_MUSIC_REPEAT)) {
+               _playlist_set_repeat_mode(priv);
        }
 }
 
@@ -847,6 +928,7 @@ static Evas_Object *_create(Evas_Object *win, void *data)
        priv->playlist.list_org = NULL;
        priv->playlist.cur = 0;
        priv->playlist.shuffle = false;
+       priv->playlist.repeat = REPEAT_ALL;
 
        player = playermgr_create(NULL);
        if (!player) {