Beispiel #1
0
 public static Image GetImage(this MediaSample item)
 {
     using (var strm = item.GetData())
     {
         return(Image.FromStream(strm));
     }
 }
Beispiel #2
0
        /*public static ... GetVideos()
         * {
         *
         * } */

        private static string GetSampleFileName(MediaSample ms)
        {
            if (ms.TitleId < 1)
            {
                throw new ApplicationException("Can't manipulate media sample file before title was saved");
            }
            if (ms.Id < 1)
            {
                throw new ApplicationException("Can't manipulate media sample file before metadata was saved");
            }
            string folder = Path.Combine(s_dataFolder, ms.TitleId.ToString());

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }
            string fileName = Path.Combine(folder, ms.Id.ToString());

            if (!string.IsNullOrEmpty(ms.Extension))
            {
                if (ms.Extension[0] != '.')
                {
                    fileName += "." + ms.Extension;
                }
                else
                {
                    fileName += ms.Extension;
                }
            }
            return(fileName);
        }
Beispiel #3
0
        public static void RemoveSample(MediaSample ms)
        {
            string fn = GetSampleFileName(ms);

            File.Delete(fn);
            using (var db = DB.GetDatabase())
            {
                db.Delete(ms);
            }
        }
Beispiel #4
0
        public static MediaSample AddSample(byte[] data, long titleId, MediaSampleKind kind, string extension)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data", "Sample data can't be null");
            }
            var ms = new MediaSample {
                TitleId = titleId, Extension = extension, MediaKind = kind
            };

            using (var db = DB.GetDatabase())
            {
                db.Insert(ms);
            }
            string fn = GetSampleFileName(ms);

            File.WriteAllBytes(fn, data);
            return(ms);
        }
Beispiel #5
0
        public static Stream GetData(this MediaSample item)
        {
            string fn = GetSampleFileName(item);

            return(File.OpenRead(fn));
        }