VorbisCommentBlock constructor

VorbisCommentBlock(
  1. FlacMetaBlock _flacMetaBlock
)

Implementation

VorbisCommentBlock(this._flacMetaBlock) {
  if (_flacMetaBlock.data.isNotEmpty) {
    int vendorSize =
        _flacMetaBlock.data[0] |
        _flacMetaBlock.data[1] << 8 |
        _flacMetaBlock.data[2] << 16 |
        _flacMetaBlock.data[3] << 24;
    int commentsCount =
        _flacMetaBlock.data[4 + vendorSize] |
        _flacMetaBlock.data[5 + vendorSize] << 8 |
        _flacMetaBlock.data[6 + vendorSize] << 16 |
        _flacMetaBlock.data[7 + vendorSize] << 24;
    int pos = 4 + vendorSize + 4;
    for (int i = 0; i < commentsCount; i++) {
      int commentSize =
          _flacMetaBlock.data[pos] |
          _flacMetaBlock.data[pos + 1] << 8 |
          _flacMetaBlock.data[pos + 2] << 16 |
          _flacMetaBlock.data[pos + 3] << 24;
      if (commentSize > 0) {
        var comment = _flacMetaBlock.data.sublist(
          pos + 4,
          pos + 4 + commentSize,
        );
        _comments.add(
          VorbisComment(
            String.fromCharCodes(
              comment.sublist(0, comment.indexOf('='.codeUnitAt(0))),
            ).toUpperCase(),
            comment.sublist(comment.indexOf('='.codeUnitAt(0)) + 1),
          ),
        );
      }
      pos += 4 + commentSize;
    }
  }
}