コード例 #1
0
        public void Load(Stream stream)
        {
            _thumbnails.Clear();

            JsonSerializer serializer = new JsonSerializer();
            JObject        jRoot;

            using (StreamReader reader = new StreamReader(stream))
                jRoot = JObject.Load(new JsonTextReader(reader));

            JArray jThumbs = jRoot["thumbnails"] as JArray;

            foreach (JObject thumb in jThumbs)
            {
                byte[]            image     = Convert.FromBase64String(thumb["image"].Value <string>());
                JpegBitmapDecoder decoder   = new JpegBitmapDecoder(new MemoryStream(image), BitmapCreateOptions.None, BitmapCacheOption.None);
                TimeSpan          timestamp = TimeSpan.Parse(thumb["time"].Value <string>());

                VideoThumbnail thumbnail = new VideoThumbnail
                {
                    Thumbnail = decoder.Frames[0],
                    Timestamp = timestamp
                };

                Add(thumbnail);
            }
        }
コード例 #2
0
        public void Add(VideoThumbnail videoThumbnail)
        {
            for (int i = 0; i < _thumbnails.Count; i++)
            {
                if (_thumbnails[i].Timestamp > videoThumbnail.Timestamp)
                {
                    _thumbnails.Insert(i, videoThumbnail);
                    return;
                }
            }

            _thumbnails.Add(videoThumbnail);
        }
コード例 #3
0
        public VideoThumbnail Get(TimeSpan timestamp)
        {
            if (_thumbnails.Count == 0)
            {
                return(null);
            }

            for (int index = _thumbnails.Count - 1; index >= 0; index--)
            {
                VideoThumbnail thumbnail = _thumbnails[index];
                if (thumbnail.Timestamp <= timestamp)
                {
                    return(thumbnail);
                }
            }

            return(_thumbnails.First());
        }