media_info 0.6.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

media_info #

Pub

Utilizes platform code to determine audio, video & photo properties.

Depending on the underlying platform version, various workarounds will be applied to fetch the fields.

Currently supported properties:

  • width
  • height
  • frame rate
  • duration (in milliseconds)
  • mime type
  • number of tracks

Additionally, thumbnails can be generated.

0.6.2 #

  • Image decoding moved to the Dart side
  • Add support for audio details
  • Fixes bugs when decoding video on Android

0.6.1 #

  • Android: Removes logging in the main plugin
  • Android: Removes various unsafe/deprecated method calls

0.6.0 #

  • Update pubspec.yaml format
  • Android: Video rotation can not be detected on Android < 17
  • Support the v2 Android embedder
  • Bump a few example dependency versions
  • iOS: Remove unused logging
  • iOS: Migrate iOS project
  • Adds basic method plugin tests on Dart side
  • Resolves width / height detection for portrait videos. Thank you @bdoubleu86

0.5.2 #

  • Android: Optimize the logic when a ExoPlayer frame is actually ready.

0.5.1 #

  • Android: Ensure underlying ExoPlayer instance is reused & run on a single thread for all operations.

0.5.0 #

  • Android: Switch Metadata retrieval from MediaStore methods to ExoPlayer
  • Android: Bump AGP & Gradle

0.4.1 #

  • Updates AGP to latest
  • Bump Glide dependency for Android

0.4.0 #

  • Replace Kotlin with Java
  • Various bugfixes

0.3.0 #

  • Ensure Android results are always submitted on the main thread

0.2.2+1 #

  • Do not return invalid values when detection fails. Throw flutter errors instead.

0.2.2 #

  • iOS: Read mimeType
  • iOS: Detect image width & height

0.2.1 #

  • Prevent crashes on iOS when asset track list is empty.

0.2.0 #

  • Require object instance to instead of providing static methods. This improves mocking & testing capabilities.

0.1.0 #

  • getMediaInfo implementation for iOS
  • generateThumbnail implementation for iOS
  • improve generateThumbnail API to return a Future

0.0.4+1 #

  • Bump gradle plugin version

0.0.4 #

  • Set Android compile SDK version to 28
  • Migrate to AndroidX

0.0.3+1 #

  • Upgrade gradle & kotlin dependencies

0.0.3 #

  • [Android] Thumbnail support for video / image files

0.0.2 #

  • Detect mimeType

0.0.1 #

  • Initial Release with Android platform support.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:media_info/media_info.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class Resolution {
  const Resolution(this.w, this.h);

  final int w;
  final int h;
}

const List<Resolution> _resolutions = [
  Resolution(384, 216),
  Resolution(512, 288),
  Resolution(640, 360),
  Resolution(768, 432),
  Resolution(896, 504),
  Resolution(1024, 576),
  Resolution(1152, 648),
  Resolution(1280, 720),
  Resolution(1408, 792),
  Resolution(1536, 864),
  Resolution(1664, 936),
  Resolution(1792, 1008),
  Resolution(1920, 1080),
];

class _MyAppState extends State<MyApp> {
  String _file;
  Map<String, dynamic> _mediaInfoCache;
  final Map<String, Future<String>> _thumbnails = <String, Future<String>>{};

  final MediaInfo _mediaInfo = MediaInfo();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      showPerformanceOverlay: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Media Info App'),
        ),
        body: SafeArea(
          child: SingleChildScrollView(
            child: Padding(
              padding: const EdgeInsets.all(24.0),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Text(_file ?? 'Please select a file'),
                  Text(
                    (_mediaInfoCache?.keys ?? <String>[])
                        .map((String k) => '$k: ${_mediaInfoCache[k]}')
                        .join(',\n\n'),
                    style: Theme.of(context).textTheme.body2,
                  ),
                  Builder(
                    builder: (BuildContext context) {
                      if (_thumbnails.isEmpty) {
                        return const SizedBox();
                      }

                      final List<String> listW = _thumbnails.keys.toList();
                      listW.sort((a, b) {
                        final wA = int.parse(a.split('x').first);
                        final wB = int.parse(b.split('x').first);

                        return wA.compareTo(wB);
                      });

                      final List<Widget> widgets = <Widget>[];
                      for (final String res in listW) {
                        widgets.addAll([
                          Text(res),
                          FutureBuilder<String>(
                            future: _thumbnails[res],
                            builder: (BuildContext context, snapshot) {
                              if (snapshot.hasData) {
                                return Image.file(File(snapshot.data));
                              }
                              if (snapshot.hasError) {
                                return Text(
                                  'E: ${snapshot.error}',
                                  style: TextStyle(color: Colors.red),
                                );
                              }

                              return const SizedBox();
                            },
                          ),
                          Divider(),
                        ]);
                      }

                      return Column(
                        mainAxisSize: MainAxisSize.min,
                        children: widgets,
                      );
                    },
                  ),
                ],
              ),
            ),
          ),
        ),
        floatingActionButton: _buildSelectButton(),
      ),
    );
  }

  Widget _buildSelectButton() {
    return FloatingActionButton(
      child: Icon(Icons.attach_file),
      onPressed: () async {
        final String mediaFile = await FilePicker.getFilePath();

        if (!mounted || mediaFile == null) {
          return;
        }

        setState(() {
          _file = mediaFile;
          _mediaInfoCache = null;
          _thumbnails.clear();
        });

        final Map<String, dynamic> mediaInfo =
            await _mediaInfo.getMediaInfo(mediaFile);

        if (!mounted || mediaInfo == null) {
          return;
        }

        setState(() {
          _mediaInfoCache = mediaInfo;
        });

        final Directory cacheDir = await getTemporaryDirectory();
        final int cacheName = _file.hashCode;

        final int w = mediaInfo['width'];
        final int h = mediaInfo['height'];

        final String mime = mediaInfo['mimeType'];
        if (mime.startsWith("video/")) {
          Set<Resolution> resolutions = Set();
          resolutions.addAll(_resolutions);
          resolutions.add(Resolution(w, h));

          for (final Resolution res in resolutions) {
            final String target =
                File('${cacheDir.path}/$cacheName.${res.w}').path;
            if (File(target).existsSync()) {
              File(target).deleteSync();
            }

            _thumbnails['${res.w}x${res.h}'] =
                _mediaInfo.generateThumbnail(_file, target, res.w, res.h);
          }
        }

        setState(() {});
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  media_info: ^0.6.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:media_info/media_info.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
72
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
86
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:media_info/media_info.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:media_info/media_info.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:media_info/media_info.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:media_info/media_info.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • media_info that is a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
flutter 0.0.0
mime ^0.9.6+3 0.9.6+3
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
file_picker ^1.11.0+3
flutter_test
mockito ^4.1.1
path_provider ^1.6.10