Skip to content

Swift library for reading and writing audio file metadata, powered by TagLib (via C++ interop). Used in: ● Anywhere Offline Music Player ●

License

Notifications You must be signed in to change notification settings

Anywhere-Music-Player/SwiftTagLib

Repository files navigation

SwiftTagLib

Swift Version iOS Version

A library to read and write Metadata in audio files. Built on top of taglib v2.1.

Heavily inspired by SFBAudioEngine and made as an adaptation of it with focus on metadata. You can review differences from SFBAudioEngine here.

Usage

import SwiftTagLib

// create audio file from url: reads it's metadata & properties
let url = URL(fileURLWithPath: "./path/to/audiofile.mp3")
var audioFile = try AudioFile(url: url)

// by default attached pictures are read from metadata during initialization
// skipping them will reduce time spent reading metadata
audioFile = try AudioFile(url: url, options: [.skipPictures])

// if you need to know if file metadata has attached pictures,
// might give false positives if pictures are corrupted/empty
print("has attached pictures:", audioFile.metadata.hasAttachedPictures)

// get metadata values
print("song:", audioFile.metadata.artist ?? "_", "-", audioFile.metadata.title ?? "_")
print("bitrate:", audioFile.properties.bitrate, "duration:", aduioFile.properties.duration)
let picture = audioFile.metadata.attachedPictures.first

// set metadata values
audioFile.metadata.title = "Song name"
audioFile.metadata.lyrics = .none
audioFile.metadata.attachedPictures = [
    .init(data: Data(), kind: .frontCover, description: "album cover")
]

// write metadata changes
try audioFile.write()

Warning

This library does not state or guarantee ABI stability despite packaging XCFramework's. Whenever the version changes you should recompile.

Note on C++ Interoprability

This library is done using Swift C++ Interop (there are some limitations to consider). Understanding Objective-C and Swift interoperability. Currently supporting reading from most of the same types as SFBAudioEngine in C++ Bridge.

Development

After cloning this repository you should call the following(in it's root directory), to fetch the git submodules:

git submodule update --init

The Package.swift in the root directory is a wrapper for underlying Package.swift in XCFrameworkPackage directory, you should work with/edit the latter.

To compile Package.swift in XCFrameworkPackage as bunch of .xcframework's, go into XCFrameworkPackage directory and call:

make

Acknowledgments

This library would not be possible without any of this libraries:

Notes

  • WMA file format is supported by taglib here, but not SFBAudioEngine, can probably try to support it even though it's outdated.
  • taglib v2.1 introduced shorten file support, but no changes were made to accomodate that yet.

About

Swift library for reading and writing audio file metadata, powered by TagLib (via C++ interop). Used in: ● Anywhere Offline Music Player ●

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •