如何在Flutter中使用id3插件
How to use id3 plugging in Flutter
只得到每个标签的第一个字母,或者可能是我哪里错了
void info() {
MP3Instance mp3instance = new MP3Instance("/storage/emulated/0/Download/Army_320-(Mr-Jat.in).mp3");
if(mp3instance.parseTagsSync()){
print(mp3instance.getMetaTags());
print(mp3instance.metaTags['Title']);
print(mp3instance.metaTags['Artist']);
print(mp3instance.metaTags['Album']);
print(mp3instance.metaTags['Year']);
print(mp3instance.metaTags['Genre']);
}
}
这是输出
I/flutter ( 6995): {Version: v2.3.0, Title: A
I/flutter ( 6995): A
I/flutter ( 6995): S
I/flutter ( 6995): H
I/flutter ( 6995): 2
I/flutter ( 6995): M
仅显示文本的第一个字母并停止。
我打印出 mp3instance.getMetaTags()
的 ASCII 等价物并意识到字符串中有一些 ASCII control characters 终止了 print()
语句。
经过一番研究,我使用这种方法删除了控制字符:
String normalizeString(String s) {
var encoded = ascii.encode(s.toString());
List<int> normalized = new List.from(encoded.map((e) => (e < 32) ? 32 : e));
return ascii.decode(normalized);
}
我打印了规范化的字符串如下:
print( "Before normalizing: " + mp3instance.getMetaTags().toString() );
String normalString = normalizeString( mp3instance.getMetaTags().toString() );
print( "After normalizing: " + normalString);
print( "Normalized title: " + mp3instance.metaTags['Title'].toString() );
更多资源:
Replace non ASCII character from string
只得到每个标签的第一个字母,或者可能是我哪里错了
void info() {
MP3Instance mp3instance = new MP3Instance("/storage/emulated/0/Download/Army_320-(Mr-Jat.in).mp3");
if(mp3instance.parseTagsSync()){
print(mp3instance.getMetaTags());
print(mp3instance.metaTags['Title']);
print(mp3instance.metaTags['Artist']);
print(mp3instance.metaTags['Album']);
print(mp3instance.metaTags['Year']);
print(mp3instance.metaTags['Genre']);
}
}
这是输出
I/flutter ( 6995): {Version: v2.3.0, Title: A
I/flutter ( 6995): A
I/flutter ( 6995): S
I/flutter ( 6995): H
I/flutter ( 6995): 2
I/flutter ( 6995): M
仅显示文本的第一个字母并停止。
我打印出 mp3instance.getMetaTags()
的 ASCII 等价物并意识到字符串中有一些 ASCII control characters 终止了 print()
语句。
经过一番研究,我使用这种方法删除了控制字符:
String normalizeString(String s) {
var encoded = ascii.encode(s.toString());
List<int> normalized = new List.from(encoded.map((e) => (e < 32) ? 32 : e));
return ascii.decode(normalized);
}
我打印了规范化的字符串如下:
print( "Before normalizing: " + mp3instance.getMetaTags().toString() );
String normalString = normalizeString( mp3instance.getMetaTags().toString() );
print( "After normalizing: " + normalString);
print( "Normalized title: " + mp3instance.metaTags['Title'].toString() );
更多资源:
Replace non ASCII character from string