Example #1
0
        /// <summary>
        /// Saves the metadata, using an available <see cref="IMetadataEncoder"/>. If no extensions are able to write
        /// to this file extension, an <see cref="UnsupportedAudioException"/>
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <exception cref="UnsupportedAudioException">
        /// No metadata encoders are able to save metadata in the required format.
        /// </exception>
        public void SaveMetadata(SettingsDictionary settings = null)
        {
            if (settings == null)
            {
                settings = new SettingsDictionary();
            }

            using (FileStream fileStream = FileInfo.Open(FileMode.Open, FileAccess.ReadWrite))
            {
                // Ensure the existing metadata has been loaded:
                if (_metadata == null)
                {
                    LoadMetadata(fileStream);
                    fileStream.Position = 0;
                }

                // Try each encoder that supports the file extension:
                foreach (ExportFactory <IMetadataEncoder> encoderFactory in
                         ExtensionProvider.GetFactories <IMetadataEncoder>("Extension", FileInfo.Extension))
                {
                    using (ExportLifetimeContext <IMetadataEncoder> lifetimeContext = encoderFactory.CreateExport())
                    {
                        IMetadataEncoder encoder = lifetimeContext.Value;
                        ValidateSettings(settings, encoder);
                        encoder.WriteMetadata(fileStream, Metadata, settings);

                        return;
                    }
                }
            }

            throw new UnsupportedAudioException(Resources.TaggedAudioFileUnsupportedError);
        }
Example #2
0
 public static ValueTask <FlushResult> WriteFrameAsync(this IMetadataEncoder encoder, PipeWriter writer, Frame frame, CancellationToken token = default)
 {
     encoder.WriteMetadata(writer, frame);
     return(writer.WriteByChunkAsync(frame.Payload, token));
 }