Add get/set played time, count API 50/40450/6
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 4 Jun 2015 02:32:15 +0000 (11:32 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 5 Jun 2015 07:17:40 +0000 (00:17 -0700)
Change-Id: I545693f13d45a3dfd5c2f71a583e9fc72939c41e
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
include/media_info.h
src/media_info.c

index f8452bcb48bd4e4da8b16d9dda69ec50f554131d..40ee2b43534f71aea511c567b3fef41c4da35ac8 100755 (executable)
@@ -950,6 +950,38 @@ int media_info_is_drm(media_info_h media, bool *is_drm);
  */
 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type);
 
+/**
+ * @brief Gets number which represents how many times given content has been played.
+ * @since_tizen 2.4
+ *
+ * @param [in] media The handle to media info
+ * @param [out] count_played The counter of content played
+ *
+ * @return 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE Successful
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int media_info_get_played_count(media_info_h media, int *played_count);
+
+/**
+ * @brief Gets the content's played time parameter.
+ * @details Function returns content's elapsed playback time parameter as period
+ *          starting from the beginning of the track.
+ * @since_tizen 2.4
+ *
+ * @param [in] media The handle to media info
+ * @param [out] played_time The elapsed time of the content
+ *
+ * @return 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE Successful
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int media_info_get_played_time(media_info_h media, time_t *played_time);
+
 /**
  * @brief Gets the media info from the media database.
  *
@@ -977,6 +1009,40 @@ int media_info_get_storage_type(media_info_h media, media_content_storage_e *sto
  */
 int media_info_get_media_from_db(const char *media_id, media_info_h *media);
 
+/**
+ * @brief Increments the played count to content meta handle.
+ * @detalis You can increase the played(opened) count of the media file.
+ * @since_tizen 2.4
+ *
+ * @param [in] media The handle to media info
+ *
+ * @return 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE Successful
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @post media_info_update_to_db()
+ */
+int media_info_increase_played_count(media_info_h media);
+
+/**
+ * @brief Sets the played time to content meta handle.
+ * @detalis You can set the latest played(opened) time of the media file. the latest played time to be set the current time on the system.
+ * @since_tizen 2.4
+ *
+ * @param [in] media The handle to media info
+ *
+ * @return 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #MEDIA_CONTENT_ERROR_NONE Successful
+ * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @post media_info_update_to_db()
+ */
+int media_info_set_played_time(media_info_h media);
+
 /**
  * @brief Sets the display name of media info.
  * @since_tizen 2.3
index 4ec51e9b0d692480ed1091fd8c1aaa8e3195b7ce..03d7757e32a8ee37e04377c779656009b769ebf5 100755 (executable)
@@ -302,6 +302,10 @@ void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
        _media->latitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LATITUDE);
        _media->altitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_ALTITUDE);
 
+       _media->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
+       _media->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
+       _media->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
+
        if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)))
                _media->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
 
@@ -984,6 +988,9 @@ int media_info_clone(media_info_h *dst, media_info_h src)
                _dst->favourite = _src->favourite;
                _dst->is_drm = _src->is_drm;
                _dst->storage_type = _src->storage_type;
+               _dst->played_count = _src->played_count;
+               _dst->played_time = _src->played_time;
+               _dst->played_position = _src->played_position;
                _dst->sync_status = _src->sync_status;
 
                if(_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
@@ -2312,6 +2319,84 @@ int media_info_get_storage_type(media_info_h media, media_content_storage_e *sto
        return ret;
 }
 
+int media_info_get_played_count(media_info_h media, int *played_count)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       media_info_s *_media = (media_info_s*)media;
+
+       if(_media)
+       {
+               *played_count = _media->played_count;
+               ret = MEDIA_CONTENT_ERROR_NONE;
+       }
+       else
+       {
+               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
+int media_info_get_played_time(media_info_h media, time_t* played_time)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       media_info_s *_media = (media_info_s*)media;
+
+       if(_media)
+       {
+               *played_time = _media->played_time;
+               ret = MEDIA_CONTENT_ERROR_NONE;
+       }
+       else
+       {
+               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
+int media_info_increase_played_count(media_info_h media)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+
+       media_info_s *_media = (media_info_s*)media;
+
+       if(_media)
+       {
+               _media->played_count += 1;
+       }
+       else
+       {
+               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
+int media_info_set_played_time(media_info_h media)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       time_t current_time;
+
+       media_info_s *_media = (media_info_s*)media;
+
+       if(_media != NULL)
+       {
+               time(&current_time);
+               _media->played_time = current_time;
+       }
+       else
+       {
+               media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+               ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
@@ -2833,15 +2918,16 @@ int media_info_update_to_db(media_info_h media)
                }
 
                set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
+                       played_count=%d, last_played_time=%d, last_played_position=%d, \
                        rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q, weather=%Q, sync_status=%d, \
                        file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q",
-                       _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->rating, _media->favourite,
+                       _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->played_count, _media->played_time, _media->played_position, _media->rating, _media->favourite,
                        _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
                        file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin);
 
                len = snprintf(sql, sizeof(sql), "UPDATE %s SET %s WHERE media_uuid='%s'", DB_TABLE_MEDIA, set_sql, _media->media_id);
                sqlite3_free(set_sql);
-               
+
                SAFE_FREE(description_pinyin);
                SAFE_FREE(author_pinyin);
                SAFE_FREE(provider_pinyin);
@@ -2850,7 +2936,7 @@ int media_info_update_to_db(media_info_h media)
                SAFE_FREE(location_tag_pinyin);
                SAFE_FREE(age_rating_pinyin);
                SAFE_FREE(keyword_pinyin);
-               
+
                if (len > 0) {
                        sql[len] = '\0';
                } else {