decodeSync method

List<ID3MetataInfo> decodeSync()

synchronous decoding. Read the ID3 in the audio file and return ID3MetataInfo object information.

final decoder = ID3Decoder(bytes);
final metadatas = decoder.decodeSync();
for (var metadata in metadatas) {
    debugPrint(metadata.toTagMap().toString());
}

Implementation

List<ID3MetataInfo> decodeSync() {
  assert(!isEmpty, 'id3 data is empty');
  if (isEmpty) return [];

  final List<ID3MetataInfo> metadatas = [];
  // parse ID3v1
  final id3v1 = ID3V1Decoder(_bytes);
  final retv1 = id3v1.convert();
  if (retv1) {
    metadatas.add(id3v1.metadata);
  }

  // parse ID3v2
  final id3v2 = ID3V2Decoder(retv1 ? _bytes.sublist(0, _bytes.length - id3v1.totalLength) : _bytes);
  final retv2 = id3v2.convert();
  if (retv2) {
    metadatas.add(id3v2.metadata);
  }
  return metadatas;
}