nessmediametadataretriever 1.0.2 copy "nessmediametadataretriever: ^1.0.2" to clipboard
nessmediametadataretriever: ^1.0.2 copied to clipboard

outdated

nessmediametadataretriever

example/lib/main.dart

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:nessmediametadataretriever/nessmediametadataretriever.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
   Metadata? metadata;
   String? path;
   Widget? albumArt;
   Widget? table;

  Future<void> onSelected(String path) async {
    FocusScope.of(context).unfocus();
    print(File(path).existsSync());
    var metadata = await NessMetadataRetriever.fromFile(File(path));
    setState(() {
      albumArt = metadata.albumArt != null
          ? Image.memory(
        metadata.albumArt!,
        height: 200.0,
        width: 200.0,
      )
          : Container(
        height: 200.0,
        width: 200.0,
        child: Text('No album art.'),
      );
      table = SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.all(20.0),
              child: albumArt ?? Container(),
            ),
            SizedBox(
              width: 16.0,
            ),
            DataTable(
              columns: [
                DataColumn(
                    label: Text('Property',
                        style: TextStyle(fontWeight: FontWeight.w600))),
                DataColumn(
                    label: Text('Value',
                        style: TextStyle(fontWeight: FontWeight.w600))),
              ],
              rows: [
                DataRow(
                  cells: [
                    DataCell(Text('trackName')),
                    DataCell(Text('${metadata.title}')),
                  ],
                ),
                DataRow(
                  cells: [
                    DataCell(Text('trackArtistNames')),
                    DataCell(Text('${metadata.artists}')),
                  ],
                ),
                DataRow(
                  cells: [
                    DataCell(Text('albumName')),
                    DataCell(Text('${metadata.album}')),
                  ],
                ),
                DataRow(
                  cells: [
                    DataCell(Text('albumArtistName')),
                    DataCell(Text('${metadata.albumArtist}')),
                  ],
                ),

                DataRow(
                  cells: [
                    DataCell(Text('trackDuration')),
                    DataCell(Text('${metadata.duration}')),
                  ],
                ),

              ],
            ),
          ],
        ),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: const Text('flutter_media_metadata'),
        ),
        body: Scrollbar(
          isAlwaysShown: true,
          child: ListView(
            padding: EdgeInsets.symmetric(horizontal: 16.0),
            children: [
              Divider(
                color: Colors.transparent,
                height: 16.0,
              ),
              TextField(
                cursorWidth: 1.0,
                onEditingComplete: () => onSelected(path!),
                onChanged: (String value) => path = value,
                style: TextStyle(fontSize: 14.0),
                decoration: InputDecoration(
                    hintText: 'Enter media path.',
                    hintStyle: TextStyle(fontSize: 14.0)),
              ),
              Divider(
                color: Colors.transparent,
                height: 16.0,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () => onSelected(path!),
                    child: Text('Retrieve Metadata'),
                  ),
                ],
              ),
              Divider(
                color: Colors.transparent,
                height: 16.0,
              ),
              Divider(
                color: Colors.transparent,
                height: 16.0,
              ),
              table ??
                  Text(
                    'No media opened.',
                    textAlign: TextAlign.center,
                  ),
            ],
          ),
        ),
      ),
    );
  }
}