Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:audiobook_player/presentation/pages/widgets/book_info_tile.dart';
- import 'package:file_picker/file_picker.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
- class FilePickerTrial extends StatelessWidget {
- final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();
- final List<String> audioPaths = [];
- final List<String> audioTitle = [];
- final List<String> audioAuthor = [];
- final List<String> audioDuration = [];
- FilePickerTrial({Key key}) : super(key: key);
- @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]);
- }
- print(
- 'AudioPaths Length ============== ${audioPaths.length} ==============');
- for (int j = 0; j < audioPaths.length; j++) {
- await _flutterFFprobe
- .getMediaInformation(audioPaths[j])
- .then(
- (info) {
- print(
- "================Media Information=============");
- audioTitle.add(
- info.getMediaProperties()['tags']['title']);
- audioAuthor.add(
- info.getMediaProperties()['tags']['artist']);
- audioDuration
- .add(info.getMediaProperties()['duration']);
- print(
- '====================> $audioTitle ==============');
- print(
- '====================> $audioAuthor ==============');
- },
- );
- }
- },
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- body: ListView.builder(
- itemCount: audioPaths.length,
- itemBuilder: (context, index) {
- return BookInfoTile(
- bookCoverImageURL: 'assets/no_cover.png',
- bookTitle: audioTitle[index],
- authorName: audioAuthor[index],
- bookLength: int.parse(audioDuration[index]),
- onClick: null);
- }),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment