-
Notifications
You must be signed in to change notification settings - Fork 1
API Reference
Complete reference for all hAudiotagger methods, types, and error handling.
// Read from file path (native only)
static Future<Tag?> read(String path)
// Read from bytes (web + native)
static Future<Tag?> readFromBytes(Uint8List bytes)Returns null if no metadata is found. Throws HaudiotaggerError on failure.
// Write to file path (native only)
static Future<void> write(String path, Tag tag)
// Write to bytes (returns modified bytes)
static Future<Uint8List> writeToBytes(Uint8List bytes, Tag tag)Replaces all existing metadata with the provided tag.
// Update file path (native only)
static Future<void> update(String path, TagChanges changes)
// Update bytes (returns modified bytes)
static Future<Uint8List> updateFromBytes(Uint8List bytes, TagChanges changes)Only the fields set in changes are modified — everything else stays intact.
// Remove specific fields from file (native only)
static Future<void> remove(String path, List<TagField> fields)
// Remove from bytes (returns modified bytes)
static Future<Uint8List> removeFromBytes(Uint8List bytes, List<TagField> fields)// Clear all metadata from file (native only)
static Future<void> clear(String path)
// Clear from bytes (returns modified bytes)
static Future<Uint8List> clearFromBytes(Uint8List bytes)// Read one field from file (native only)
static Future<String?> readField(String path, TagField field)
// Read one field from bytes (web + native)
static Future<String?> readFieldFromBytes(Uint8List bytes, TagField field)Faster than read() when you only need one value.
Supported fields:
TagField.titleTagField.artistTagField.albumTagField.albumArtistTagField.yearTagField.genreTagField.trackNumberTagField.trackTotalTagField.discNumberTagField.discTotalTagField.lyricsTagField.commentTagField.bpm
Warning
TagField.pictures is not supported — use readPictures() or readPictureByType() instead.
// Read all pictures from file (native only)
static Future<List<Picture>> readPictures(String path)
// Read all pictures from bytes (web + native)
static Future<List<Picture>> readPicturesFromBytes(Uint8List bytes)// Read specific picture type from file (native only)
static Future<Picture?> readPictureByType(String path, PictureType type)
// Read specific picture type from bytes (web + native)
static Future<Picture?> readPictureByTypeFromBytes(Uint8List bytes, PictureType type)Picture types:
PictureType.otherPictureType.fileIconPictureType.otherFileIconPictureType.frontCoverPictureType.backCoverPictureType.leafletPictureType.mediaPictureType.artistPictureType.conductorPictureType.bandPictureType.composerPictureType.lyricistPictureType.recordingLocationPictureType.duringRecordingPictureType.duringPerformancePictureType.movieScreenCapturePictureType.colouredFishPictureType.illustrationPictureType.artistLogoPictureType.studioLogo
// Read from file (native only)
static Future<ExtendedTag> getExtended(String path)
// Read from bytes (web + native)
static Future<ExtendedTag> getExtendedFromBytes(Uint8List bytes)// Write to file (native only)
static Future<void> setExtended(String path, ExtendedTag data)
// Write to bytes (returns modified bytes)
static Future<Uint8List> setExtendedFromBytes(Uint8List bytes, ExtendedTag data)Replaces all extended fields.
// Partial update on file (native only)
static Future<void> updateExtended(String path, ExtendedChanges changes)
// Partial update on bytes (returns modified bytes)
static Future<Uint8List> updateExtendedFromBytes(Uint8List bytes, ExtendedChanges changes)Only set fields are modified.
// Remove from file (native only)
static Future<void> removeExtended(String path)
// Remove from bytes (returns modified bytes)
static Future<Uint8List> removeExtendedFromBytes(Uint8List bytes)Available fields:
| Category | Fields |
|---|---|
| MusicBrainz |
musicBrainzRecordingId, musicBrainzTrackId, musicBrainzReleaseId, musicBrainzReleaseGroupId, musicBrainzArtistId, musicBrainzReleaseArtistId, musicBrainzWorkId, musicBrainzReleaseType
|
| AcoustID |
acoustId, acoustIdFingerprint
|
| Identifiers |
isrc, barcode, catalogNumber
|
| People |
arranger, conductor, director, engineer, lyricist, mixDj, mixEngineer, performer, producer, publisher, label, remixer, writer, composer, originalLyricist
|
| Dates |
recordingDate, releaseDate, originalReleaseDate
|
| Style |
initialKey, color, mood
|
| URLs |
audioFileUrl, audioSourceUrl, commercialInformationUrl, copyrightUrl, trackArtistUrl, radioStationUrl, paymentUrl, publisherUrl
|
| Legal |
copyrightMessage, license
|
| Podcast |
podcastDescription, podcastSeriesCategory, podcastUrl, podcastGlobalUniqueId, podcastKeywords
|
| Other |
setSubtitle, showName, contentGroup, trackSubtitle, language, script, parentalAdvisory, fileOwner, originalFileName, originalMediaType, encodedBy, encoderSoftware, encoderSettings
|
// Read from file (native only)
static Future<List<Chapter>> getChapters(String path)
// Read from bytes (web + native)
static Future<List<Chapter>> getChaptersFromBytes(Uint8List bytes)// Write to file (native only)
static Future<void> setChapters(String path, List<Chapter> chapters)
// Write to bytes (returns modified bytes)
static Future<Uint8List> setChaptersFromBytes(Uint8List bytes, List<Chapter> chapters)// Read from file (native only)
static Future<Map<String, String>> getCustomTags(String path)
// Read from bytes (web + native)
static Future<Map<String, String>> getCustomTagsFromBytes(Uint8List bytes)// Write to file (native only)
static Future<void> setCustomTag(String path, String key, String value)
// Write to bytes (returns modified bytes)
static Future<Uint8List> setCustomTagFromBytes(Uint8List bytes, String key, String value)// Remove from file (native only)
static Future<void> removeCustomTag(String path, String key)
// Remove from bytes (returns modified bytes)
static Future<Uint8List> removeCustomTagFromBytes(Uint8List bytes, String key)// Write same tag to multiple files
static Future<BatchResult> batchWrite(List<String> paths, Tag tag)
// Write same tag to multiple byte arrays
static Future<BatchBytesResult> batchWriteFromBytes(List<Uint8List> bytesList, Tag tag)// Apply same changes to multiple files
static Future<BatchResult> batchUpdateChanges(List<String> paths, TagChanges changes)
// Apply same changes to multiple byte arrays
static Future<BatchBytesResult> batchUpdateChangesFromBytes(List<Uint8List> bytesList, TagChanges changes)// Apply per-file changes with callback
static Future<BatchResult> batchUpdate(
List<String> paths,
Tag Function(String path, Tag current) updater, {
void Function(BatchProgress progress)? onProgress,
})
// Apply per-file changes to byte arrays
static Future<BatchBytesResult> batchUpdateFromBytes(
List<Uint8List> bytesList,
Tag Function(int index, Tag current) updater, {
void Function(BatchProgress progress)? onProgress,
})// Validate file (native only)
static Future<ValidationResult> validate(String path)
// Validate bytes (web + native)
static Future<ValidationResult> validateFromBytes(Uint8List bytes)
// Validate Tag directly
static Future<ValidationResult> validateTag(Tag tag)// Normalize file (native only)
static Future<Tag> normalize(String path)
// Normalize bytes (returns modified bytes)
static Future<Uint8List> normalizeBytes(Uint8List bytes)
// Normalize Tag directly
static Future<Tag> normalizeTag(Tag tag, {NormalizeOptions? options})NormalizeOptions:
| Field | Type | Default |
|---|---|---|
trimValues |
bool |
true |
normalizeWhitespace |
bool |
true |
normalizeUnicode |
bool |
true |
removeEmptyValues |
bool |
true |
// Copy between files (native only)
static Future<void> copyMetadata(
String sourcePath,
String destPath, {
bool includeArtwork = true,
bool includeLyrics = true,
bool includeCustomTags = true,
})
// Copy between byte arrays
static Future<Uint8List> copyMetadataFromBytes(
Uint8List sourceBytes,
Uint8List destBytes, {
bool includeArtwork = true,
bool includeLyrics = true,
bool includeCustomTags = true,
})static Tag mergeTags(Tag tagA, Tag tagB, {MergeStrategy? strategy})MergeStrategy:
-
preferFirst— tagA wins for all fields -
preferSecond— tagB wins for all fields -
preferFirstNonEmpty— tagA wins unless empty, then tagB -
preferSecondNonEmpty— tagB wins unless empty, then tagA
static MetadataDiff diff(Tag oldTag, Tag newTag)static String formatFilename(Tag tag, {required String pattern})Placeholders: {title}, {artist}, {album}, {albumArtist}, {track}, {trackTotal}, {disc}, {discTotal}, {year}, {genre}
static Future<String> rename(String path, {required String pattern})// Inspect file (native only)
static Future<AudioFileInfo> inspect(String path)
// Inspect bytes (web + native)
static Future<AudioFileInfo> inspectFromBytes(Uint8List bytes)| Field | Type | Notes |
|---|---|---|
title |
String? |
|
trackArtist |
String? |
|
album |
String? |
|
albumArtist |
String? |
|
year |
int? |
|
genre |
String? |
|
trackNumber |
int? |
|
trackTotal |
int? |
|
discNumber |
int? |
|
discTotal |
int? |
|
lyrics |
String? |
|
comment |
String? |
|
bpm |
double? |
|
duration |
int? |
Read-only |
pictures |
List<Picture> |
|
replayGainTrackGain |
String? |
e.g. "-6.43"
|
replayGainTrackPeak |
String? |
e.g. "0.981201"
|
replayGainAlbumGain |
String? |
e.g. "-7.12"
|
replayGainAlbumPeak |
String? |
e.g. "0.995000"
|
Same fields as Tag, all optional. Only set fields are applied.
| Field | Type |
|---|---|
pictureType |
PictureType |
mimeType |
MimeType? |
bytes |
Uint8List |
| Field | Type | Notes |
|---|---|---|
title |
String |
Chapter name |
startMs |
int |
Start time in milliseconds |
endMs |
int |
End time in milliseconds |
| Field | Type |
|---|---|
duration |
Duration? |
durationMicros |
int? |
bitrate |
int? |
sampleRate |
int? |
channels |
int? |
bitsPerSample |
int? |
codec |
String |
containerFormat |
String |
lossless |
bool |
bitrateMode |
BitrateMode |
fileSize |
BigInt? |
| Field | Type | Notes |
|---|---|---|
format |
String |
e.g. MP3, FLAC
|
tagFormat |
String |
e.g. ID3v2, VorbisComments
|
properties |
AudioProperties |
Technical details |
metadata |
Tag? |
All metadata fields |
pictures |
List<Picture> |
Embedded artwork |
size |
BigInt |
File size in bytes |
| Field | Type |
|---|---|
successes |
int |
failures |
int |
errors |
List<(String, String)> |
| Field | Type |
|---|---|
results |
List<Uint8List> |
failures |
int |
errors |
List<(int, String)> |
| Field | Type |
|---|---|
completed |
int |
total |
int |
percent |
double |
| Field | Type |
|---|---|
changes |
List<MetadataChange> |
length |
int |
isEmpty |
bool |
| Field | Type |
|---|---|
field |
TagField |
oldValue |
T? |
newValue |
T? |
type |
ChangeType |
| Field | Type |
|---|---|
issues |
List<ValidationIssue> |
isValid |
bool (getter) |
| Field | Type |
|---|---|
field |
String |
message |
String |
severity |
ValidationSeverity |
All operations can throw HaudiotaggerError:
try {
final tag = await Haudiotagger.read('/path/to/song.mp3');
} on HaudiotaggerError catch (e) {
print('Error: ${e.message}');
}Error variants:
-
OpenFile— File not found, inaccessible, or corrupted -
Read— Failed to parse metadata -
Write— Failed to write metadata -
UnsupportedFormat— File format not supported
Made with ❤️ and 🦀 by Hirdaya Shrestha