pparth602

Untitled

Oct 30th, 2020
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 7.58 KB | None | 0 0
  1. import 'package:file_picker/file_picker.dart';
  2. import 'package:flutter_svg/flutter_svg.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
  5. import 'package:media_metadata_plugin/media_media_data.dart';
  6. import 'package:media_metadata_plugin/media_metadata_plugin.dart';
  7.  
  8. class MetaDemo extends StatefulWidget {
  9.   MetaDemo({Key key}) : super(key: key);
  10.  
  11.   @override
  12.   _MetaDemoState createState() => _MetaDemoState();
  13. }
  14.  
  15. class _MetaDemoState extends State<MetaDemo> {
  16.   final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();
  17.   final List<String> audioPaths = [];
  18.   final List<String> audioTitle = [];
  19.   final List<AudioMetaData> audiobookMetaData = [];
  20.   final List<String> audioAuthor = [];
  21.   final List<String> audioDuration = [];
  22.  
  23.   @override
  24.   Widget build(BuildContext context) {
  25.     Size size = MediaQuery.of(context).size;
  26.     return Container(
  27.       child: Scaffold(
  28.         appBar: AppBar(
  29.           actions: [
  30.             Container(
  31.               width: size.width,
  32.               child: Padding(
  33.                 padding: const EdgeInsets.all(8.0),
  34.                 child: Row(
  35.                   mainAxisSize: MainAxisSize.max,
  36.                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  37.                   children: [
  38.                     Align(
  39.                       alignment: Alignment.centerLeft,
  40.                       child: IconButton(
  41.                         icon: Icon(Icons.sort, color: Colors.black),
  42.                         onPressed: () {},
  43.                       ),
  44.                     ),
  45.                     IconButton(
  46.                       icon: Icon(Icons.add_circle, color: Colors.black),
  47.                       onPressed: () async {
  48.                         FilePickerResult pathResult = await FilePicker.platform
  49.                             .pickFiles(
  50.                                 type: FileType.audio, allowMultiple: true);
  51.  
  52.                         for (int i = 0; i < pathResult.paths.length; i++) {
  53.                           audioPaths.add(pathResult.paths[i]);
  54.  
  55.                           // AudioMetaData audioMMetaData1 =
  56.                           //     await MediaMetadataPlugin.getMediaMetaData(
  57.                           //         audioPaths[i]);
  58.                           // audiobookMetaData.add(audioMMetaData1);
  59.                         }
  60.  
  61.                         for (int j = 0; j < audioPaths.length; j++) {
  62.                           AudioMetaData audioMMetaData1 =
  63.                               await MediaMetadataPlugin.getMediaMetaData(
  64.                                   audioPaths[j]);
  65.  
  66.                           audiobookMetaData.add(audioMMetaData1);
  67.                           print('========>This is Meta $audioMMetaData1');
  68.                         }
  69.                         setState(() async {
  70.                           // for (int j = 0; j < audioPaths.length; j++) {
  71.                           //   await _flutterFFprobe
  72.                           //       .getMediaInformation(audioPaths[j])
  73.                           //       .then(
  74.                           //     (info) {
  75.                           //       audioTitle.add(
  76.                           //           info.getMediaProperties()['tags']['title']);
  77.                           //       audioAuthor.add(info
  78.                           //           .getMediaProperties()['tags']['artist']);
  79.                           //       audioDuration
  80.                           //           .add(info.getMediaProperties()['duration']);
  81.                           //     },
  82.                           //   );
  83.                           // }
  84.                         });
  85.                       },
  86.                     ),
  87.                   ],
  88.                 ),
  89.               ),
  90.             ),
  91.           ],
  92.         ),
  93.         body: ListView.builder(
  94.             itemCount: audiobookMetaData.length,
  95.             itemBuilder: (BuildContext context, int index) {
  96.               return BookInfoTile(
  97.                   bookCoverImageURL: 'assets/no_cover.png',
  98.                   bookTitle: audiobookMetaData[index].trackName,
  99.                   authorName: audiobookMetaData[index].authorName,
  100.                   bookLength: audiobookMetaData[index].trackDuration.toString(),
  101.                   onClick: () {
  102.                     print('Button is Clicked');
  103.                   });
  104.             }),
  105.       ),
  106.     );
  107.   }
  108. }
  109.  
  110. class BookInfoTile extends StatelessWidget {
  111.   final String bookCoverImageURL;
  112.   final String bookTitle;
  113.   final String authorName;
  114.   final String bookLength;
  115.   final onClick;
  116.   final Function onStop;
  117.  
  118.   const BookInfoTile(
  119.       {Key key,
  120.       @required this.bookCoverImageURL,
  121.       @required this.bookTitle,
  122.       @required this.authorName,
  123.       @required this.bookLength,
  124.       @required this.onClick,
  125.       this.onStop})
  126.       : super(key: key);
  127.   @override
  128.   Widget build(BuildContext context) {
  129.     Size size = MediaQuery.of(context).size;
  130.     return GestureDetector(
  131.       onTap: onClick,
  132.       child: Expanded(
  133.         child: Row(
  134.           mainAxisAlignment: MainAxisAlignment.start,
  135.           crossAxisAlignment: CrossAxisAlignment.center,
  136.           children: [
  137.             ClipRRect(
  138.               borderRadius: BorderRadius.circular(25.0),
  139.               child: Image.asset(
  140.                 bookCoverImageURL,
  141.                 fit: BoxFit.fill,
  142.                 alignment: Alignment.centerLeft,
  143.                 height: size.height * 0.22,
  144.                 width: size.width * 0.40,
  145.               ),
  146.             ),
  147.             SizedBox(width: 16),
  148.             Expanded(
  149.               child: Column(
  150.                 crossAxisAlignment: CrossAxisAlignment.start,
  151.                 children: [
  152.                   Text(
  153.                     bookTitle,
  154.                     overflow: TextOverflow.visible,
  155.                     style: TextStyle(
  156.                       fontWeight: FontWeight.bold,
  157.                       color: Colors.black,
  158.                     ),
  159.                   ),
  160.                   const SizedBox(
  161.                     height: 10,
  162.                   ),
  163.                   Text(
  164.                     'by $authorName',
  165.                     style: TextStyle(
  166.                       fontSize: 15,
  167.                       fontWeight: FontWeight.normal,
  168.                       color: Color(0xFF767676),
  169.                     ),
  170.                   ),
  171.                   const SizedBox(
  172.                     height: 8,
  173.                   ),
  174.                   RichText(
  175.                     text: TextSpan(
  176.                       children: [
  177.                         WidgetSpan(
  178.                           alignment: PlaceholderAlignment.middle,
  179.                           child: SvgPicture.asset(
  180.                             'assets/svg/circle-fill.svg',
  181.                             color: Color(0xFFffe564),
  182.                             height: 10,
  183.                             alignment: Alignment.topCenter,
  184.                           ),
  185.                         ),
  186.                         TextSpan(
  187.                           text: " $bookLength",
  188.                           style: TextStyle(
  189.                             fontSize: 15,
  190.                             fontWeight: FontWeight.normal,
  191.                             color: Color(0xFF767676),
  192.                           ),
  193.                         ),
  194.                       ],
  195.                     ),
  196.                   ),
  197.                   RaisedButton(
  198.                     onPressed: onStop,
  199.                     child: Text('Stop'),
  200.                   ),
  201.                 ],
  202.               ),
  203.             ),
  204.           ],
  205.         ),
  206.       ),
  207.     );
  208.   }
  209. }
  210.  
Advertisement
Add Comment
Please, Sign In to add comment