viewer: set video position when play/stop video file 63/43563/2
authorMinkyu Kang <mk7.kang@samsung.com>
Fri, 10 Jul 2015 06:30:48 +0000 (15:30 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Fri, 10 Jul 2015 06:36:29 +0000 (15:36 +0900)
Change-Id: Ideaeb01e3629fdc65e283d87e4617f0684d3550b
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
include/util/playermgr.h
src/util/playermgr.c
src/view/viewer.c

index 7ba5831..0eafe4b 100644 (file)
@@ -22,7 +22,7 @@ struct playermgr;
 struct playermgr *playermgr_create(Evas_Object *win);
 void playermgr_destroy(struct playermgr *m);
 
-bool playermgr_play(struct playermgr *m, const char *path);
+bool playermgr_play(struct playermgr *m, const char *path, int ms);
 void playermgr_stop(struct playermgr *m);
 bool playermgr_resume(struct playermgr *m);
 bool playermgr_pause(struct playermgr *m);
index 07aa63c..332eebd 100644 (file)
@@ -157,7 +157,7 @@ void playermgr_stop(struct playermgr *m)
        player_unprepare(m->player);
 }
 
-bool playermgr_play(struct playermgr *m, const char *path)
+bool playermgr_play(struct playermgr *m, const char *path, int ms)
 {
        int r;
 
@@ -199,6 +199,12 @@ bool playermgr_play(struct playermgr *m, const char *path)
                return false;
        }
 
+       r = player_set_play_position(m->player, ms, false, NULL, NULL);
+       if (r != PLAYER_ERROR_NONE) {
+               _ERR("player: set_position error (%d)", r);
+               return false;
+       }
+
        return true;
 }
 
index 0e8db1c..b0ac6ca 100644 (file)
@@ -23,6 +23,7 @@
 #include <media_info.h>
 #include <player.h>
 #include <app_media.h>
+#include <app_contents.h>
 
 #include "define.h"
 #include "view.h"
@@ -149,6 +150,7 @@ struct _viewer_info {
 };
 
 static void _player_play(struct _priv *priv);
+static void _player_stop(struct _priv *priv);
 
 static void _callback_movie(void *data, const char *ev);
 static void _callback_photo(void *data, const char *ev);
@@ -394,6 +396,35 @@ static app_media_info *_get_current_media_info(struct _priv *priv)
        return mi;
 }
 
+static void _set_played_position(struct _priv *priv, int position)
+{
+       video_meta_h video;
+       app_media *am;
+       int r;
+
+       am = eina_list_nth(priv->playlist.list, priv->playlist.cur);
+       if (!am) {
+               _ERR("failed to get app_media");
+               return;
+       }
+
+       video = app_media_get_video_handle(am);
+       if (!video) {
+               _ERR("failed to getting video handle");
+               return;
+       }
+
+       r = video_meta_set_played_position(video, position);
+       if (r != MEDIA_CONTENT_ERROR_NONE) {
+               _ERR("failed to set played position");
+               return;
+       }
+
+       r = video_meta_update_to_db(video);
+       if (r != MEDIA_CONTENT_ERROR_NONE)
+               _ERR("failed to update db");
+}
+
 static bool _viewer_show(struct _priv *priv, int foc)
 {
        struct _viewer_info *info;
@@ -446,12 +477,14 @@ static bool _viewer_show(struct _priv *priv, int foc)
        }
        ctl->ops->focus(ctl->handle, loc, true);
 
-       _draw_contents(priv, id, mi);
-
        _draw_title_bar(priv, id, mi);
        _draw_progressbar(priv, id, mi);
        _draw_favorite_icon(priv, id, mi);
 
+       _draw_contents(priv, id, mi);
+
+       app_contents_recent_add(CONTENTS_MEDIA, mi->media_id);
+
        return true;
 }
 
@@ -572,6 +605,10 @@ static void _pop_view(struct _priv *priv)
 {
        struct view_update_data vdata;
 
+       if (priv->viewer.cur == VIEWER_MOVIE ||
+                       priv->viewer.cur == VIEWER_VIDEO)
+               _player_stop(priv);
+
        vdata.index = priv->playlist.cur;
 
        viewmgr_update_view(VIEW_BASE, UPDATE_FOCUS, &vdata);
@@ -655,7 +692,7 @@ static void _player_play(struct _priv *priv)
                _remove_thumbnail(priv);
 
                progressbar_start(priv->progress);
-               playermgr_play(priv->player, mi->file_path);
+               playermgr_play(priv->player, mi->file_path, mi->video->position);
 
                break;
        default:
@@ -667,6 +704,12 @@ static void _player_play(struct _priv *priv)
 static void _player_stop(struct _priv *priv)
 {
        struct controller *ctl;
+       int position;
+
+       if (priv->viewer.cur == VIEWER_MOVIE) {
+               position = playermgr_get_position(priv->player);
+               _set_played_position(priv, position);
+       }
 
        progressbar_stop(priv->progress);
        playermgr_stop(priv->player);
@@ -685,6 +728,10 @@ static void _player_complete_cb(void *data)
        priv = data;
 
        progressbar_stop(priv->progress);
+       _set_played_position(priv, 0);
+
+       if (priv->viewer.cur == VIEWER_MOVIE)
+               _pop_view(priv);
 }
 
 static void _player_set_position_cb(void *data)
@@ -884,6 +931,8 @@ static void _show(void *view_data)
 
        priv = view_data;
 
+       media_content_connect();
+
        _viewer_show(priv, DIR_NONE);
 
        timeout_handler_enable(priv->timeout, true);
@@ -907,6 +956,8 @@ static void _hide(void *view_data)
 
        timeout_handler_enable(priv->timeout, false);
 
+       media_content_disconnect();
+
        evas_object_hide(priv->base);
 }