Audio File I/O
Kodio supports reading and writing audio files in common container formats. The API works across all Kotlin Multiplatform targets, including platforms without filesystem access.
Supported formats
Format | Read | Write | Extensions |
|---|---|---|---|
WAV | PCM int (8/16/24/32-bit), IEEE float (32/64-bit) | PCM int, IEEE float |
|
AIFF / AIFF-C | PCM int (8/16/24/32-bit), IEEE float ( | PCM int, IEEE float |
|
AU | PCM int (8/16/24/32-bit), IEEE float (32/64-bit) | PCM int, IEEE float |
|
MP3 | MPEG-1 Layer III to PCM (decode only) | Not supported |
|
Specify the format with AudioFileFormat.Wav, AudioFileFormat.Aiff, AudioFileFormat.Au, or AudioFileFormat.Mp3.
Format detection
Loaders probe magic bytes first, then fall back to the file name extension. There is no silent default to WAV.
Explicit
fileFormatargument wins.Otherwise magic-byte sniff (
RIFF/WAVE,FORM/AIFF/AIFC,.snd,ID3or a validated MPEG frame header).Otherwise known extension from
fileName/ path.Magic wins if it disagrees with the extension.
If still unknown, loaders throw
AudioFileReadError.UnsupportedFormat. Empty input throwsInvalidFile.
Saving recordings
Save a recording to disk. The default format is WAV:
Save as AIFF or AU:
MP3 encode is not supported and throws AudioFileWriteError.UnsupportedFormat.
For more control over the output, use the AudioFlow extensions:
Loading audio files
From Compose resources or byte arrays
Raw PCM (no container) uses a separate API:
From a file path
From a stream
Metadata
See Audio File Metadata for AudioFileReader.readMetadata() and AudioTags.
Error handling
Read errors
AudioFileReadError.InvalidFileThe data is not a valid audio file (for example missing header or corrupt structure).
AudioFileReadError.UnsupportedFormatThe format could not be detected, or the encoding is not supported (for example ADPCM, or MP3 encode).
AudioFileReadError.IOA filesystem-level error occurred while reading.
Write errors
AudioFileWriteError.UnsupportedFormatThe audio format cannot be written to the target container (for example planar layout to WAV, or any MP3 encode).
AudioFileWriteError.IOA filesystem-level error occurred while writing.
Platform guide
Platform | Recommended method | Notes |
|---|---|---|
Compose Multiplatform |
| Works everywhere |
JVM / Desktop |
| Direct filesystem access |
Android |
| Use ContentResolver for user-selected files |
iOS / macOS |
| Filesystem or bundled resources |
Web (JS / Wasm) |
| No filesystem; use fetch or bundled assets |