audiotagger 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

audiotagger #

build status pub

This library allow yoy to read and write ID3 tags to MP3 files.

Library actually works only on Android.

Add dependency #

dependencies:
  audiotagger: ^1.0.5

Audiotagger need accesso to read and write storage. To do this, add this lines in your AndroidManifest.xml (inside manifest tag, see example manifest to check).

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Than you can use you preferred way to request them or simply set checkPermission flag to true.

Table of contents #

Basic usage for any operation #

Initialize a new instance of the tagger;

final tagger = new Audiotagger();

Any operation has a checkPermission boolean parameter. By setting it to true, the tagger will check for storage read and write permission, before to start the operations.

Reading operations #

Read tags as map #

You can get a Map of the ID3 tags.

void getTagsAsMap() async {
    final String filePath = "/storage/emulated/0/file.mp3";
    final Map map = await tagger.readTagsAsMap(
        path: filePath,
        checkPermission: true,
    );
}

This method does not read the artwork of the song. To do this, use the readArtwork method.

The map has this schema:Tag schema.

Read tags as Tag object #

You can get a Tag object of the ID3 tags.

void getTags() async {
    final String filePath = "/storage/emulated/0/file.mp3";
    final Tag tag = await tagger.readTags(
        path: filePath,
        checkPermission: true,
    );
}

This method does not read the artwork of the song. To do this, use the readArtwork method.

The Tag object has this schema: Tag schema.

Read artwork #

To get the artwork of the song, use this method.

void getArtwork() async {
    final String filePath = "/storage/emulated/0/file.mp3";
    final Uint8List bytes = await tagger.readArtwork(
        path: filePath,
        checkPermission: true,
    );
}

It return a Uint8List of the bytes of the artwork.

Writing operations #

Write tags from map #

You can write the ID3 tags from a Map.

void setTagsFromMap() async {
    final path = "storage/emulated/0/Music/test.mp3";
    final tags = <String, String>{
        "title": "Title of the song",
        "artist": "A fake artist",
        "album": "A fake album",
    };

    final result = await tagger.writeTagsFromMap(
        path: path,
        tags: tags,
        checkPermission: true,
    );
}

The map has this schema:Tag schema.

Write tags from Tag object #

You can write the ID3 tags from a Tag object.

void setTags() async {
    final path = "storage/emulated/0/Music/test.mp3";
    final tags = <String, String>{
        "title": "Title of the song",
        "artist": "A fake artist",
        "album": "A fake album",
    };
    final tag = Tag.fromMap(tags);

    final result = await tagger.writeTags(
        path: path,
        tag: tag,
        checkPermission: true,
    );
}

The Tag object has this schema: Tag schema.

Models #

These are the schemes of the Map asked and returned by Audiotagger and of the Tag class.

Map of tags #

<String, String>{
    "title": value,
    "artist": value,
    "genre": value,
    "trackNumber": value,
    "trackTotal": value,
    "discNumber": value,
    "discTotal": value,
    "lyrics": value,
    "comment": value,
    "album": value,
    "albumArtist": value,
    "year": value,
};

Tag class #

    String title;
    String artist;
    String genre;
    String trackNumber;
    String trackTotal;
    String discNumber;
    String discTotal;
    String lyrics;
    String comment;
    String album;
    String albumArtist;
    String year;
    String artwork; // It represents the file path of the song artwork.

This library is developed and maintained by Nicolò Rebaioli
🌐 My website
📫 niko.reba@gmail.com

Released under MIT license

Copyright 2019 Nicolò Rebaioli

1.0.0 #

1.0.2 #

  • Fixed bug in writeTags when artwork field was not provided.
  • Updated dependecies, examples and README.

1.0.3 #

  • Increased performance.

1.0.4 #

1.0.5 #

  • Updated documentation.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:audiotagger/audiotagger.dart';
import 'package:audiotagger/models/tag.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final filePath = "/storage/emulated/0/Download/test.mp3";
  Widget result;
  Audiotagger tagger = new Audiotagger();

  Future _writeTags() async {
    String artwork = "/storage/emulated/0/Download/cover.png";
    Tag tags = Tag(
      title: "Title of the song",
      artist: "A fake artist",
      album: "A fake album",
      year: "2020",
      artwork: artwork,
    );

    final output = await tagger.writeTags(
      path: filePath,
      tag: tags,
      checkPermission: true,
    );

    setState(() {
      result = Text(output.toString());
    });
  }

  Future _readTags() async {
    final output = await tagger.readTagsAsMap(
      path: filePath,
      checkPermission: true,
    );
    setState(() {
      result = Text(jsonEncode(output));
    });
  }

  Future _readArtwork() async {
    final output = await tagger.readArtwork(
      path: filePath,
      checkPermission: true,
    );
    setState(() {
      result = output != null ? Image.memory(output) : Text("No artwork found");
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Audiotagger example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              result != null ? result : Text("Ready.."),
              RaisedButton(
                child: Text("Read tags"),
                onPressed: () async {
                  await _readTags();
                },
              ),
              RaisedButton(
                child: Text("Read artwork"),
                onPressed: () async {
                  await _readArtwork();
                },
              ),
              RaisedButton(
                child: Text("Write tags"),
                onPressed: () async {
                  await _writeTags();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  audiotagger: ^1.0.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:audiotagger/audiotagger.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
45
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
permission_handler ^4.0.0 4.4.0+hotfix.2
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
permission_handler_platform_interface 1.0.0
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test