Skip to content

A Flutter plugin for reading and writing mp3 file tags.

License

Notifications You must be signed in to change notification settings

janhrastnik/mp3editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mp3editor

A Flutter plugin for reading and writing mp3 file tags.

Usage

First get the filepath from an mp3 file saved on the device. If you have the mp3 file in your flutter assets, you can save it to the device like so:

import 'package:path_provider/path_provider.dart';
String filepath;

writeToFile(ByteData data, String path) {
  final buffer = data.buffer;
  return new File(path).writeAsBytes(
    buffer.asUint8List(data.offsetInBytes, data.lengthInBytes)
  );
}

Future<void> getFilepath() async {
    String dir = (await getApplicationDocumentsDirectory()).path;
    if (!(File(dir + "/track.mp3").existsSync())) {
      var bytes = await rootBundle.load("mp3samples/track.mp3");
      await writeToFile(bytes, dir + "/track.mp3");
    }
    filepath = dir + "/track.mp3";
}

To read specific tags:

Future<String> title = Mp3editor.getTitle(filepath);
Future<String> artist = Mp3editor.getArtist(filepath);
Future<String> trackNumber = Mp3editor.getTrackNumber(filepath);
Future<String> album = Mp3editor.getAlbum(filepath);
Future<String> year = Mp3editor.getYear(filepath);
Future<String> genre = Mp3editor.getGenre(filepath);
Future<String> comment = Mp3editor.getComment(filepath);

Method will return null if tag is empty.

To write tags, you will need overwrite all the existing tags in the file:

Mp3editor.setID3v1Tag(
  filepath: filepath,
  title: 'Title',
  artist: 'Artist',
  album: 'Album',
  year: '2019',
  genre: 52,
  comment: 'Comment'
);

Be careful with the 'genre' parameter, you need to specify an ID3v1 genre number, see this for more.

Checkout the example for further details.

About

A Flutter plugin for reading and writing mp3 file tags.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published