Skip to content

Commit 1f19e98

Browse files
committed
Update CHANGELOG.md. Reformat to 80 chars and fix case issues to fit in with pub.dev lints.
1 parent 527e813 commit 1f19e98

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.1
2+
3+
- Duration calculation changed from second to millisecond level (@sveinbjornt)
4+
15
## 0.2.0
26

37
- Migrate to null safe.

example/mp3_info_example.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'dart:io';
33
import 'package:mp3_info/mp3_info.dart';
44

55
void main() {
6-
final mp3 = MP3Processor.fromFile(File('test_files/test_128kpbs_441khz_stereo_10s.mp3'));
6+
final mp3 = MP3Processor.fromFile(
7+
File('test_files/test_128kpbs_441khz_stereo_10s.mp3'));
78

89
print('MP3: test_128kpbs_441khz_stereo_10s.mp3');
910

lib/src/mp3_processor.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import 'mp3.dart';
1515
/// Processes an MP3 file extracting key metadata information. The current version
1616
/// does not support extracting metadata from ID3 tags.
1717
class MP3Processor {
18-
static int FRAME_1 = 0;
19-
static int FRAME_2 = 1;
20-
static int FRAME_3 = 2;
21-
static int FRAME_4 = 3;
18+
static int frame1 = 0;
19+
static int frame2 = 1;
20+
static int frame3 = 2;
21+
static int frame4 = 3;
2222

2323
/// Process the MP3 contained within the [File] instance.
2424
static MP3Info fromFile(File file) {
@@ -40,13 +40,14 @@ class MP3Processor {
4040
/// the ID3 tag space (excluding the 10 byte header itself. This function
4141
/// calculates the start of the first MP3 frame.
4242
int _processID3(Uint8List bytes) {
43-
var headerSize = (bytes[6] << 21) + (bytes[7] << 14) + (bytes[8] << 7) + (bytes[9]);
43+
var headerSize =
44+
(bytes[6] << 21) + (bytes[7] << 14) + (bytes[8] << 7) + (bytes[9]);
4445

4546
return headerSize + 10;
4647
}
4748

4849
Version _processMpegVersion(Uint8List frameHeader) {
49-
var version = frameHeader[FRAME_2] & mpegVersionMask;
50+
var version = frameHeader[frame2] & mpegVersionMask;
5051

5152
switch (version) {
5253
case mpegVersion1:
@@ -61,7 +62,7 @@ class MP3Processor {
6162
}
6263

6364
Layer _processMpegLayer(Uint8List frameHeader) {
64-
final mpegLayer = frameHeader[FRAME_2] & mpegLayerMask;
65+
final mpegLayer = frameHeader[frame2] & mpegLayerMask;
6566

6667
switch (mpegLayer) {
6768
case layer1:
@@ -76,15 +77,15 @@ class MP3Processor {
7677
}
7778

7879
bool _processCrcCheck(Uint8List frameHeader) {
79-
final mpegProtection = frameHeader[FRAME_2] & mpegProtectionMask;
80+
final mpegProtection = frameHeader[frame2] & mpegProtectionMask;
8081

8182
return mpegProtection > 0;
8283
}
8384

8485
int? _processBitRate(Uint8List frameHeader, Version version, Layer layer) {
85-
final sampleInfo = frameHeader[FRAME_3];
86-
final bitRate =
87-
(sampleInfo & mpegBitRateMask) >> 4; // Easier to compare if we shift the bits down.
86+
final sampleInfo = frameHeader[frame3];
87+
final bitRate = (sampleInfo & mpegBitRateMask) >>
88+
4; // Easier to compare if we shift the bits down.
8889
Map<int, int> bitRateMap;
8990

9091
if (version == Version.MPEG_1) {
@@ -109,7 +110,7 @@ class MP3Processor {
109110
}
110111

111112
SampleRate? _processSampleRate(Uint8List frameHeader) {
112-
final sampleRate = (frameHeader[FRAME_3] & mpegSampleRateMask);
113+
final sampleRate = (frameHeader[frame3] & mpegSampleRateMask);
113114
SampleRate? rate;
114115

115116
switch (sampleRate) {
@@ -138,7 +139,7 @@ class MP3Processor {
138139
}
139140

140141
ChannelMode _processChannelMode(Uint8List frameHeader) {
141-
final channelMode = (frameHeader[FRAME_4] & mpegChannelModeMask);
142+
final channelMode = (frameHeader[frame4] & mpegChannelModeMask);
142143
ChannelMode mode;
143144

144145
switch (channelMode) {
@@ -160,19 +161,19 @@ class MP3Processor {
160161
}
161162

162163
bool _processCopyright(Uint8List frameHeader) {
163-
final copyright = (frameHeader[FRAME_4] & mpegCopyrightMask);
164+
final copyright = (frameHeader[frame4] & mpegCopyrightMask);
164165

165166
return copyright > 0;
166167
}
167168

168169
bool _processOriginal(Uint8List frameHeader) {
169-
final original = (frameHeader[FRAME_4] & mpegOriginalMask);
170+
final original = (frameHeader[frame4] & mpegOriginalMask);
170171

171172
return original > 0;
172173
}
173174

174175
Emphasis? _processEmphasis(Uint8List frameHeader) {
175-
final emphasis = (frameHeader[FRAME_4] & mpegEmphasisMask);
176+
final emphasis = (frameHeader[frame4] & mpegEmphasisMask);
176177
Emphasis? e;
177178

178179
switch (emphasis) {
@@ -201,7 +202,8 @@ class MP3Processor {
201202
// Does the MP3 start with an ID3 tag?
202203
firstFrameOffset = latin1.decode(tag) == 'ID3' ? _processID3(header) : 0;
203204

204-
final frameHeaderBytes = bytes.sublist(firstFrameOffset, firstFrameOffset + 10);
205+
final frameHeaderBytes =
206+
bytes.sublist(firstFrameOffset, firstFrameOffset + 10);
205207

206208
// Ensure we have a valid MP3 frame
207209
final frameSync1 = frameHeaderBytes[0] & frameSyncA;
@@ -234,7 +236,8 @@ class MP3Processor {
234236
emphasis,
235237
);
236238
} else {
237-
throw InvalidMP3FileException('The file cannot be processed as it is not a valid MP3 file');
239+
throw InvalidMP3FileException(
240+
'The file cannot be processed as it is not a valid MP3 file');
238241
}
239242
}
240243
}

pubspec.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
name: mp3_info
22
description: A package for extracting key meta information from an MP3 file including sample rate, bitrate and duration. Written in pure Dart.
3-
version: 0.2.0
3+
version: 0.2.1
44
homepage: https://github.com/amugofjava/mp3_info
55

66
environment:
77
sdk: '>=2.12.0 <3.0.0'
88

9-
#dependencies:
10-
119
dev_dependencies:
1210
pedantic: ^1.11.0
1311
test: ^1.16.8

test/mp3_info_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import 'package:test/test.dart';
1010

1111
void main() {
1212
final tenSeconds = 10;
13-
final input_128kbps_441_stereo = File('test_files/test_128kpbs_441khz_stereo_10s.mp3');
13+
final input_128kbps_441_stereo =
14+
File('test_files/test_128kpbs_441khz_stereo_10s.mp3');
1415
final input_256kbps_441_mono_copyright_emphasis_none =
1516
File('test_files/test_256kbps_441khz_mono_emphasis_none_10s.mp3');
1617
final input_256kbps_441_mono_copyright_emphasis_ccit =
1718
File('test_files/test_256kbps_441khz_mono_emphasis_ccit_10s.mp3');
18-
final input_256kbps_48_stereo = File('test_files/test_256kpbs_48khz_stereo_10s.mp3');
19-
final input_256kbps_48_mono = File('test_files/test_256kpbs_48khz_mono_10s.mp3');
19+
final input_256kbps_48_stereo =
20+
File('test_files/test_256kpbs_48khz_stereo_10s.mp3');
21+
final input_256kbps_48_mono =
22+
File('test_files/test_256kpbs_48khz_mono_10s.mp3');
2023
final input_sine_wav = File('test_files/test_sine_48khz_10s.wav');
2124

2225
group('128Kbps 44.1KHz Dual channel', () {
@@ -54,7 +57,8 @@ void main() {
5457
});
5558

5659
group('128Kbps 44.1KHz Joint stereo; copyrighted; emphasis none', () {
57-
final mp3 = MP3Processor.fromFile(input_256kbps_441_mono_copyright_emphasis_none);
60+
final mp3 =
61+
MP3Processor.fromFile(input_256kbps_441_mono_copyright_emphasis_none);
5862

5963
setUp(() {});
6064

@@ -88,7 +92,8 @@ void main() {
8892
});
8993

9094
group('128Kbps 44.1KHz Joint stereo; copyrighted; emphasis CCIT', () {
91-
final mp3 = MP3Processor.fromFile(input_256kbps_441_mono_copyright_emphasis_ccit);
95+
final mp3 =
96+
MP3Processor.fromFile(input_256kbps_441_mono_copyright_emphasis_ccit);
9297

9398
setUp(() {});
9499

0 commit comments

Comments
 (0)