コード例 #1
0
        public static async Task <MetadataItemsBox> CreateAsync(IBinaryStream stream, Box box)
        {
            if (!box.IsContainer)
            {
                throw new FormatException();
            }

            var metadataItemsBox = new MetadataItemsBox();

            foreach (var subbox in box.Boxes)
            {
                switch (subbox.Name)
                {
                case "covr":
                    var data = subbox.Boxes.FirstOrDefault(a => a.Name == "data");
                    if (data != null)
                    {
                        metadataItemsBox.Cover = (await MetadataValueBox.CreateAsync(stream, data).ConfigureAwait(false)).DataLocation;
                    }
                    break;

                default:
                    break;
                }
            }
            return(metadataItemsBox);
        }
コード例 #2
0
ファイル: Mpeg4File.cs プロジェクト: Venzz/Venz
        public static async Task <ParseResult <Mpeg4File> > ParseAsync(IBinaryStream stream, ParseOptions options)
        {
            try
            {
                stream.Position = 4;
                if (await stream.ReadStringAsync(4) != "ftyp")
                {
                    return(ParseResult <Mpeg4File> .CreateUnknownFormat());
                }

                var file = new Mpeg4File();
                stream.Position = 0;
                var streamLength = await stream.GetLengthAsync().ConfigureAwait(false);

                while (stream.Position < streamLength)
                {
                    file.Boxes.Add(await Mpeg4File.ReadBoxAsync(stream, await stream.GetLengthAsync().ConfigureAwait(false)));
                }

                if (options == ParseOptions.Metadata)
                {
                    var mediaData     = file.Contains("mdat") ? file["mdat"] : null;
                    var metadataItems = file.Contains("moov.udta.meta.ilst") ? await MetadataItemsBox.CreateAsync(stream, file["moov.udta.meta.ilst"]).ConfigureAwait(false) : null;

                    var mediaHeader = file.Contains("moov.trak.mdia.mdhd") ? await MediaHeaderBox.CreateAsync(stream, file["moov.trak.mdia.mdhd"]).ConfigureAwait(false) : null;

                    file.Metadata = new Mpeg4Metadata(metadataItems?.Cover, mediaHeader?.Duration, mediaHeader?.TimeScale, mediaData?.Length);
                }

                return(ParseResult <Mpeg4File> .Create(file));
            }
            catch (Exception exception)
            {
                return(ParseResult <Mpeg4File> .Create(exception));
            }
        }