Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:file_picker/file_picker.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
- import 'package:media_metadata_plugin/media_media_data.dart';
- import 'package:media_metadata_plugin/media_metadata_plugin.dart';
- class MetaDemo extends StatefulWidget {
- MetaDemo({Key key}) : super(key: key);
- @override
- _MetaDemoState createState() => _MetaDemoState();
- }
- class _MetaDemoState extends State<MetaDemo> {
- final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();
- final List<String> audioPaths = [];
- final List<String> audioTitle = [];
- final List<AudioMetaData> audiobookMetaData = [];
- final List<String> audioAuthor = [];
- final List<String> audioDuration = [];
- @override
- Widget build(BuildContext context) {
- Size size = MediaQuery.of(context).size;
- return Container(
- child: Scaffold(
- appBar: AppBar(
- actions: [
- Container(
- width: size.width,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- mainAxisSize: MainAxisSize.max,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Align(
- alignment: Alignment.centerLeft,
- child: IconButton(
- icon: Icon(Icons.sort, color: Colors.black),
- onPressed: () {},
- ),
- ),
- IconButton(
- icon: Icon(Icons.add_circle, color: Colors.black),
- onPressed: () async {
- FilePickerResult pathResult = await FilePicker.platform
- .pickFiles(
- type: FileType.audio, allowMultiple: true);
- for (int i = 0; i < pathResult.paths.length; i++) {
- audioPaths.add(pathResult.paths[i]);
- // AudioMetaData audioMMetaData1 =
- // await MediaMetadataPlugin.getMediaMetaData(
- // audioPaths[i]);
- // audiobookMetaData.add(audioMMetaData1);
- }
- for (int j = 0; j < audioPaths.length; j++) {
- AudioMetaData audioMMetaData1 =
- await MediaMetadataPlugin.getMediaMetaData(
- audioPaths[j]);
- audiobookMetaData.add(audioMMetaData1);
- print('========>This is Meta $audioMMetaData1');
- }
- setState(() async {
- // for (int j = 0; j < audioPaths.length; j++) {
- // await _flutterFFprobe
- // .getMediaInformation(audioPaths[j])
- // .then(
- // (info) {
- // audioTitle.add(
- // info.getMediaProperties()['tags']['title']);
- // audioAuthor.add(info
- // .getMediaProperties()['tags']['artist']);
- // audioDuration
- // .add(info.getMediaProperties()['duration']);
- // },
- // );
- // }
- });
- },
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- body: ListView.builder(
- itemCount: audiobookMetaData.length,
- itemBuilder: (BuildContext context, int index) {
- return BookInfoTile(
- bookCoverImageURL: 'assets/no_cover.png',
- bookTitle: audiobookMetaData[index].trackName,
- authorName: audiobookMetaData[index].authorName,
- bookLength: audiobookMetaData[index].trackDuration.toString(),
- onClick: () {
- print('Button is Clicked');
- });
- }),
- ),
- );
- }
- }
- class BookInfoTile extends StatelessWidget {
- final String bookCoverImageURL;
- final String bookTitle;
- final String authorName;
- final String bookLength;
- final onClick;
- final Function onStop;
- const BookInfoTile(
- {Key key,
- @required this.bookCoverImageURL,
- @required this.bookTitle,
- @required this.authorName,
- @required this.bookLength,
- @required this.onClick,
- this.onStop})
- : super(key: key);
- @override
- Widget build(BuildContext context) {
- Size size = MediaQuery.of(context).size;
- return GestureDetector(
- onTap: onClick,
- child: Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- ClipRRect(
- borderRadius: BorderRadius.circular(25.0),
- child: Image.asset(
- bookCoverImageURL,
- fit: BoxFit.fill,
- alignment: Alignment.centerLeft,
- height: size.height * 0.22,
- width: size.width * 0.40,
- ),
- ),
- SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- bookTitle,
- overflow: TextOverflow.visible,
- style: TextStyle(
- fontWeight: FontWeight.bold,
- color: Colors.black,
- ),
- ),
- const SizedBox(
- height: 10,
- ),
- Text(
- 'by $authorName',
- style: TextStyle(
- fontSize: 15,
- fontWeight: FontWeight.normal,
- color: Color(0xFF767676),
- ),
- ),
- const SizedBox(
- height: 8,
- ),
- RichText(
- text: TextSpan(
- children: [
- WidgetSpan(
- alignment: PlaceholderAlignment.middle,
- child: SvgPicture.asset(
- 'assets/svg/circle-fill.svg',
- color: Color(0xFFffe564),
- height: 10,
- alignment: Alignment.topCenter,
- ),
- ),
- TextSpan(
- text: " $bookLength",
- style: TextStyle(
- fontSize: 15,
- fontWeight: FontWeight.normal,
- color: Color(0xFF767676),
- ),
- ),
- ],
- ),
- ),
- RaisedButton(
- onPressed: onStop,
- child: Text('Stop'),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment