summaryrefslogtreecommitdiff
path: root/Tizen.Content/Tizen.Content.MediaContent/MediaBookmark.cs
blob: 71bfd713a045410de0676e3b72f106c45926306e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/// Copyright 2016 by Samsung Electronics, Inc.,
///
/// This software is the confidential and proprietary information
/// of Samsung Electronics, Inc.("Confidential Information"). You
/// shall not disclose such Confidential Information and shall use
/// it only in accordance with the terms of the license agreement
/// you entered into with Samsung.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tizen.Content.MediaContent
{
    /// <summary>
    /// A MediaBookmark allows you to mark interesting moment in a media(video and audio) to enable fast searching.
    /// The MediaBookmark Information API provides functions to get information about bookmarks associated with video and audio items.
    /// </summary>
    public class MediaBookmark : IDisposable
    {
        private IntPtr _bookmarkHandle;
        private bool _disposedValue = false;
        internal readonly uint _offset;
        internal readonly String _thumbnailPath;
        internal readonly String _mediaId;
        internal MediaBookmark(IntPtr handle)
        {
            _bookmarkHandle = handle;
        }

        ~MediaBookmark()
        {
            Dispose(false);
        }
        /// <summary>
        /// The media bookmark ID
        /// </summary>
        public int Id
        {
            get
            {
                int id;
                MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetBookmarkId(_bookmarkHandle, out id);
                if (res != MediaContentError.None)
                {
                    Log.Warn(Globals.LogTag, "Failed to get bookmark id");
                }
                return id;
            }
        }

        /// <summary>
        /// The thumbnail path of media bookmark
        /// </summary>
        public string ThumbnailPath
        {
            get
            {
                string path;
                MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetThumbnailPath(_bookmarkHandle, out path);
                if (res != MediaContentError.None)
                {
                    Log.Warn(Globals.LogTag, "Failed to get bookmark thumbnail path");
                }
                return path;
            }
        }

        /// <summary>
        /// The bookmark time offset (in milliseconds)
        /// </summary>
        public uint Offset
        {
            get
            {
                uint time;
                MediaContentError res = (MediaContentError)Interop.MediaBookmark.GetMarkedTime(_bookmarkHandle, out time);
                return time;
            }
        }

        /// <summary>
        /// The bookmark time offset (in milliseconds)
        /// </summary>
        internal string MediaId
        {
            get
            {
                return _mediaId;
            }
        }

        /// <summary>
        /// Inserts a new bookmark in media on the specified time offset to the media database.
        /// </summary>
        /// <param name="offset">The bookmark time offset (in seconds)</param>
        /// <param name="thumbnailPath">The thumbnail path of video bookmark. If the media type is audio, then thumbnail is null.</param>
        public MediaBookmark(MediaInformation content, uint offset, string thumbnailPath)
        {
            _mediaId = content.MediaId;
            _offset = offset;
            if(thumbnailPath != null)
            _thumbnailPath = thumbnailPath;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (_bookmarkHandle != IntPtr.Zero)
                {
                    Interop.Face.Destroy(_bookmarkHandle);
                    _bookmarkHandle = IntPtr.Zero;
                }
                _disposedValue = true;
            }
        }
    }
}