←Select platform

GetAudioData Method

Summary
Gets the embedded audio data from the specified extension list.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterNativeBuffer GetAudioData( 
   int stream 
) 
- (nullable NSData *)getAudioData:(NSInteger)stream error:(NSError **)error; 
public RasterNativeBuffer getAudioData(int stream) 
public: 
RasterNativeBuffer GetAudioData(  
   int stream 
)  
def GetAudioData(self,stream): 

Parameters

stream
Index of the audio stream to retrieve. The extensions may have more than one audio stream. This index is 0-based. Therefore, the first stream is stream 0, the second stream is stream 1, etc. To retrieve all the audio streams, retrieve the streams one by one until an empty RasterNativeBuffer is returned (empty RasterNativeBuffer will have a RasterNativeBuffer.Data set to IntPtr.Zero and RasterNativeBuffer.Length set to 0.

Return Value

A RasterNativeBuffer object containing the audio data.

Remarks

The audio data is stored inside extensions in the WAVE format.

The audio data can be played directly from memory, or the data can be written to a disk file and played from the disk. When writing the audio data to a disk file, give the file a .WAV extension.

The audio data pointer returned is freed automatically when this CodecsExtensionList object is disposed. so do not try to free this memory.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public void ExtensionsExample(string exifFileName) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string stampFileName = Path.Combine(LEAD_VARS.ImagesDir, "Extension.bmp"); 
   string audioFileNameTemplate = Path.Combine(LEAD_VARS.ImagesDir, "Extension.wav"); 
 
   // Read the extensions from the file 
   Debug.WriteLine("Reading the extensions from the exif file"); 
   CodecsExtensionList extensionList = codecs.ReadExtensions(exifFileName, 1); 
   if (extensionList != null) 
   { 
      if ((extensionList.Flags & CodecsExtensionListFlags.Stamp) == CodecsExtensionListFlags.Stamp) 
      { 
         Debug.WriteLine("Stamp extension: Found, saving to {0}", stampFileName); 
         RasterImage stampImage = extensionList.CreateStamp(); 
         codecs.Save(stampImage, stampFileName, RasterImageFormat.Bmp, 24); 
         stampImage.Dispose(); 
      } 
      else 
         Debug.WriteLine("Stamp extension: Not found"); 
 
      if ((extensionList.Flags & CodecsExtensionListFlags.Audio) == CodecsExtensionListFlags.Audio) 
      { 
         Debug.WriteLine("Audio extension: Found, saving ..."); 
         RasterNativeBuffer audioData; 
         int streamIndex = 0; 
 
         do 
         { 
            audioData = extensionList.GetAudioData(streamIndex); 
            if (audioData.Data != IntPtr.Zero) 
            { 
               string audioFileName = string.Format(audioFileNameTemplate, streamIndex); 
               Debug.WriteLine("To {0}", audioFileName); 
               using (FileStream fs = File.Create(audioFileName)) 
               { 
                  byte[] data = new byte[audioData.Length]; 
                  Marshal.Copy(audioData.Data, data, 0, (int)audioData.Length); 
                  fs.Write(data, 0, (int)audioData.Length); 
               } 
 
               streamIndex++; 
            } 
         } 
         while (audioData.Data != IntPtr.Zero); 
 
         Debug.WriteLine("{0} total audio streams found", streamIndex); 
      } 
      else 
         Debug.WriteLine("Audio extension: Not found"); 
 
      CodecsExtension[] extensions = extensionList.GetExtensions(); 
      Debug.WriteLine("Total number of extensions found in the file: {0}", extensions.Length); 
 
      for (int i = 0; i < extensions.Length; i++) 
      { 
         CodecsExtension extension = extensions[i]; 
         Debug.WriteLine(" {0}. Name: {1}, Clsid: {2}, UCDefault: {3}, DatLength: {4}", 
            i, extension.Name, extension.Clsid, extension.UCDefault, extension.DataLength); 
      } 
 
      // Finalize cannot be called directly, it is invoked automatically. 
      // To clean up before exiting, use Dispose 
      extensionList.Dispose(); 
   } 
   else 
      Debug.WriteLine("No extensions were found in the file"); 
 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.