just_audio_cache 0.1.0 copy "just_audio_cache: ^0.1.0" to clipboard
just_audio_cache: ^0.1.0 copied to clipboard

outdated

Collection of extension function of [just_audio](https://pub.dev/packages/just_audio) package for auto-handle caching audio files

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:just_audio_cache/just_audio_cache.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  late final AudioPlayer _player;
  final url = 'https://www.mboxdrive.com/m54.mp3';
  PlayerState? _state;

  @override
  void initState() {
    _player = AudioPlayer();
    _player.dynamicSet(url: url);
    _player.playerStateStream.listen((state) {
      setState(() {
        _state = state;
      });
      print(state);
    });
    super.initState();
  }

  void _playAudio() async {
    _player.play();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Container(
        child: Center(
          child: _audioStateWidget(),
        ),
      ),
    );
  }

  Widget _audioStateWidget() {
    if (_state == null) return _playButton;

    if (_state!.playing) {
      return _pauseButton;
    } else {
      return _playButton;
    }
  }

  Widget get _pauseButton => ElevatedButton(
        onPressed: () {
          _player.pause();
        },
        child: Text('Pause'),
      );

  Widget get _playButton => ElevatedButton(
        onPressed: () {
          _playAudio();
        },
        child: Text('Play'),
      );
}
44
likes
0
pub points
89%
popularity

Publisher

unverified uploader

Collection of extension function of [just_audio](https://pub.dev/packages/just_audio) package for auto-handle caching audio files

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http, just_audio, path_provider, shared_preferences

More

Packages that depend on just_audio_cache