flutter_id3_reader 1.0.3 flutter_id3_reader: ^1.0.3 copied to clipboard
plugin to get id3 metadata and album art for a mp3 file
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_id3_reader/flutter_id3_reader.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TagResponse? songInfo;
List<SongInfo> songs = [];
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> getTag() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
final TagResponse tag = await FlutterId3Reader.getTag(
'https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3',
remote: true,
);
setState(() {
songInfo = tag;
});
print('${tag.toString()}');
} on PlatformException {
print('Failed to get id3.');
}
}
Future<void> getAlbumArt() async {
final Uint8List? test = await FlutterId3Reader.getAlbumArt(mediaId: 31);
print('test art $test');
}
Future<void> getPhoneTags() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
var status = await Permission.storage.status;
if (!status.isPermanentlyDenied) {
if (status.isGranted) {
final List<SongInfo> _songs = await FlutterId3Reader.getSongs();
setState(() {
songs = _songs;
});
print('${_songs.toString()}');
} else if (await Permission.storage.request().isGranted) {
final List<SongInfo> _songs = await FlutterId3Reader.getSongs();
setState(() {
songs = _songs;
});
print('${_songs.toString()}');
}
}
} on PlatformException {
print('Failed to get id3.');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(children: [
ElevatedButton(
child: Text('get tag'),
onPressed: () {
getTag();
},
),
ElevatedButton(
child: Text('get all tags'),
onPressed: () {
getPhoneTags();
},
),
ElevatedButton(
child: Text('get Album Art'),
onPressed: () {
getAlbumArt();
},
),
if (songInfo != null && songInfo?.albumArt != null)
Image.memory(songInfo!.albumArt!),
if (songs.isNotEmpty)
...List.generate(songs.length, (index) => Text(songs[index].title))
]),
),
);
}
}