mpv_audio_kit 0.2.2 copy "mpv_audio_kit: ^0.2.2" to clipboard
mpv_audio_kit: ^0.2.2 copied to clipboard

Flutter audio player built on top of libmpv. Supports audio filters, pitch control, equalizer, and all mpv audio features. Targets macOS, Windows, Linux, iOS and Android.

example/lib/main.dart

import 'dart:async';
import 'dart:io';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:mpv_audio_kit/mpv_audio_kit.dart';
import 'package:window_manager/window_manager.dart';
import 'screens/home/home_page.dart';
import 'services/audio_handler.dart';
import 'services/settings_service.dart';
import 'theme/app_theme.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
    await windowManager.ensureInitialized();
    WindowOptions windowOptions = const WindowOptions(
      size: Size(1000, 800),
      minimumSize: Size(400, 600),
      center: true,
      backgroundColor: Colors.transparent,
      skipTaskbar: false,
      titleBarStyle: TitleBarStyle.normal,
    );
    await windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show();
      await windowManager.focus();
    });
  }

  MpvAudioKit.ensureInitialized();
  // Example for custom libmpv path:
  // MpvAudioKit.ensureInitialized(libmpv: '/path/to/libmpv.so');
  final settingsService = await SettingsService.init();

  final player = Player(
    configuration: const PlayerConfiguration(
      initialVolume: 50.0,
      autoPlay: true,
      logLevel: LogLevel.debug,
    ),
  );

  final audioHandler = await AudioService.init(
    builder: () => MpvAudioHandler(player),
    config: const AudioServiceConfig(
      androidNotificationChannelId: 'com.alesdrnz.mpvaudiokit.channel.audio',
      androidNotificationChannelName: 'Audio playback',
      androidNotificationOngoing: true,
      androidShowNotificationBadge: false,
      androidStopForegroundOnPause: true,
      notificationColor: AppTheme.notificationColor,
    ),
  );

  await settingsService.wire(player);

  runApp(
    MyApp(
      player: player,
      audioHandler: audioHandler,
      settingsService: settingsService,
    ),
  );
}

class MyApp extends StatefulWidget {
  final Player player;
  final MpvAudioHandler audioHandler;
  final SettingsService settingsService;

  const MyApp({
    super.key,
    required this.player,
    required this.audioHandler,
    required this.settingsService,
  });

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

class _MyAppState extends State<MyApp> {
  @override
  void dispose() {
    // Root teardown. Consumers first (they observe the player), the
    // Player last. Fires only on process teardown, but exercises the
    // documented disposal path so this example shows correct lifecycle.
    unawaited(widget.settingsService.dispose());
    widget.audioHandler.dispose();
    unawaited(widget.player.dispose());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'mpv_audio_kit',
      debugShowCheckedModeBanner: false,
      scrollBehavior: AppTheme.scrollBehavior,
      theme: AppTheme.light,
      darkTheme: AppTheme.dark,
      themeMode: ThemeMode.system,
      home: ExcludeSemantics(
        child: HomePage(
          player: widget.player,
          audioHandler: widget.audioHandler,
          settingsService: widget.settingsService,
        ),
      ),
    );
  }
}
37
likes
160
points
683
downloads
screenshot

Documentation

API reference

Publisher

verified publisherales-drnz.com

Weekly Downloads

Flutter audio player built on top of libmpv. Supports audio filters, pitch control, equalizer, and all mpv audio features. Targets macOS, Windows, Linux, iOS and Android.

Repository (GitHub)
View/report issues

Topics

#cross-platform #audio-player #libmpv #ffmpeg #dsp

License

BSD-3-Clause (license)

Dependencies

crypto, ffi, fftea, flutter, meta, plugin_platform_interface

More

Packages that depend on mpv_audio_kit

Packages that implement mpv_audio_kit