fileaudioplayer 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new64

FileAudioPlayer #

Audio player for local files. This plugin have ducking support to reduce the main audio volume while playing background music.

Link to pub.dev package: fileaudioplayer

Installation #

In the dependencies section of the pubspec.yaml project file add:

fileaudioplayer: <latest_version>

Usage #

    FileAudioPlayer audioPlayer = FileAudioPlayer();

    audioPlayer.start(filePath);

    audioPlayer.stop();

    audioPlayer.pause();

    audioPlayer.resume();

1.0.0 #

  • initial release

example/lib/main.dart

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

import 'package:fileaudioplayer/fileaudioplayer.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

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

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

class _MyAppState extends State<MyApp> {
  FileAudioPlayer player = new FileAudioPlayer();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: <Widget>[
            new FlatButton(
              child: new Text("Start"),
              onPressed: () {
                start();
              },
            ),
            new FlatButton(
              child: new Text("Stop"),
              onPressed: () {
                stop();
              },
            ),
            new FlatButton(
              child: new Text("Pause"),
              onPressed: () {
                pause();
              },
            ),
            new FlatButton(
              child: new Text("Resume"),
              onPressed: () {
                resume();
              },
            )
          ],
        )),
      ),
    );
  }

  Future<void> start() async {
    final ByteData data =
        await rootBundle.load('assets/synthesized-audio.mp3');
    Directory tempDir = await getApplicationDocumentsDirectory();
    File tempFile = File('${tempDir.path}/demo.mp3');
    await tempFile.writeAsBytes(data.buffer.asUint8List(), flush: true);
    String mp3Uri = tempFile.uri.toString();

    print("start");

    await player.start(mp3Uri);

    print("end");
  }

  Future<void> stop() async {
    await player.stop();
  }

  Future<void> pause() async {
    await player.pause();
  }

  Future<void> resume() async {
    await player.resume();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  fileaudioplayer: ^1.0.0

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:fileaudioplayer/fileaudioplayer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

7 out of 7 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test