file_audio 0.0.4 copy "file_audio: ^0.0.4" to clipboard
file_audio: ^0.0.4 copied to clipboard

A plugin for playing audio files and asset files with ducking support for iOS and Android.

example/lib/main.dart

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

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

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FileAudio player = FileAudio(duckOthers: false);

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

  Future<void> start() async {
    final ByteData data = await rootBundle.load('assets/5To0.mp3');
    Directory tempDir = await getApplicationDocumentsDirectory();
    File tempFile = File('${tempDir.path}/5To0.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();
  }
}
1
likes
160
points
30
downloads

Publisher

verified publishermocken.org

Weekly Downloads

A plugin for playing audio files and asset files with ducking support for iOS and Android.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter, path_provider, plugin_platform_interface

More

Packages that depend on file_audio