public AudioInfo ReadAudioInfo(Stream stream) { Contract.Ensures(Contract.Result <AudioInfo>() != null); using (var decoder = new NativeStreamAudioInfoDecoder(stream)) { DecoderInitStatus initStatus = decoder.Initialize(); if (initStatus != DecoderInitStatus.Ok) { if (initStatus == DecoderInitStatus.UnsupportedContainer) { throw new UnsupportedAudioException(Resources.AudioInfoDecoderUnsupportedContainerError); } else { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.AudioInfoDecoderInitializationError, initStatus)); } } if (!decoder.ProcessMetadata()) { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.AudioInfoDecoderDecodingError, decoder.GetState())); } decoder.Finish(); return(decoder.AudioInfo); } }
public MetadataDictionary ReadMetadata(Stream stream) { Contract.Ensures(Contract.Result <MetadataDictionary>() != null); using (var decoder = new NativeStreamMetadataDecoder(stream)) { decoder.SetMetadataRespond(MetadataType.VorbisComment); decoder.SetMetadataRespond(MetadataType.Picture); DecoderInitStatus initStatus = decoder.Initialize(); if (initStatus != DecoderInitStatus.Ok) { if (initStatus == DecoderInitStatus.UnsupportedContainer) { throw new UnsupportedAudioException(Resources.MetadataDecoderUnsupportedContainerError); } else { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.MetadataDecoderInitializationError, initStatus)); } } if (!decoder.ProcessMetadata()) { throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.MetadataDecoderDecodingError, decoder.GetState())); } decoder.Finish(); return(decoder.Metadata); } }
public void Initialize(Stream stream) { Contract.Ensures(_decoder != null); _decoder = new NativeStreamSampleDecoder(stream); DecoderInitStatus initStatus = _decoder.Initialize(); if (initStatus == DecoderInitStatus.Ok) { return; } if (initStatus == DecoderInitStatus.UnsupportedContainer) { throw new UnsupportedAudioException(Resources.SampleDecoderUnsupportedContainerError); } throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.SampleDecoderInitializationError, initStatus)); }