pparth602

Untitled

Oct 29th, 2020 (edited)
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.64 KB | None | 0 0
  1. import 'package:audiobook_player/presentation/pages/widgets/book_info_tile.dart';
  2. import 'package:file_picker/file_picker.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
  5.  
  6. class FilePickerTrial extends StatelessWidget {
  7.   final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();
  8.   final List<String> audioPaths = [];
  9.   final List<String> audioTitle = [];
  10.   final List<String> audioAuthor = [];
  11.   final List<String> audioDuration = [];
  12.   FilePickerTrial({Key key}) : super(key: key);
  13.  
  14.   @override
  15.   Widget build(BuildContext context) {
  16.     Size size = MediaQuery.of(context).size;
  17.     return Container(
  18.       child: Scaffold(
  19.         appBar: AppBar(
  20.           actions: [
  21.             Container(
  22.               width: size.width,
  23.               child: Padding(
  24.                 padding: const EdgeInsets.all(8.0),
  25.                 child: Row(
  26.                   mainAxisSize: MainAxisSize.max,
  27.                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  28.                   children: [
  29.                     Align(
  30.                       alignment: Alignment.centerLeft,
  31.                       child: IconButton(
  32.                         icon: Icon(Icons.sort, color: Colors.black),
  33.                         onPressed: () {},
  34.                       ),
  35.                     ),
  36.                     IconButton(
  37.                       icon: Icon(Icons.add_circle, color: Colors.black),
  38.                       onPressed: () async {
  39.                         FilePickerResult pathResult = await FilePicker.platform
  40.                             .pickFiles(
  41.                                 type: FileType.audio, allowMultiple: true);
  42.                         for (int i = 0; i < pathResult.paths.length; i++) {
  43.                           audioPaths.add(pathResult.paths[i]);
  44.                         }
  45.                         print(
  46.                             'AudioPaths Length ============== ${audioPaths.length} ==============');
  47.                         for (int j = 0; j < audioPaths.length; j++) {
  48.                           await _flutterFFprobe
  49.                               .getMediaInformation(audioPaths[j])
  50.                               .then(
  51.                             (info) {
  52.                               print(
  53.                                   "================Media Information=============");
  54.                               audioTitle.add(
  55.                                   info.getMediaProperties()['tags']['title']);
  56.                               audioAuthor.add(
  57.                                   info.getMediaProperties()['tags']['artist']);
  58.                               audioDuration
  59.                                   .add(info.getMediaProperties()['duration']);
  60.                               print(
  61.                                   '====================> $audioTitle ==============');
  62.                               print(
  63.                                   '====================> $audioAuthor ==============');
  64.                             },
  65.                           );
  66.                         }
  67.                       },
  68.                     ),
  69.                   ],
  70.                 ),
  71.               ),
  72.             ),
  73.           ],
  74.         ),
  75.         body: ListView.builder(
  76.             itemCount: audioPaths.length,
  77.             itemBuilder: (context, index) {
  78.               return BookInfoTile(
  79.                   bookCoverImageURL: 'assets/no_cover.png',
  80.                   bookTitle: audioTitle[index],
  81.                   authorName: audioAuthor[index],
  82.                   bookLength: int.parse(audioDuration[index]),
  83.                   onClick: null);
  84.             }),
  85.       ),
  86.     );
  87.   }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment