Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

package:mp3 player/play pause button.dart

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';

import 'package:audioplayers/audioplayers.dart';

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

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

class _JidduState extends State<Jiddu> with TickerProviderStateMixin {
  AnimationController controller;
  AudioPlayer _audioPlayer = AudioPlayer();
  bool isPlaying = false;
  @override
  void initState() {
    super.initState();
    controller = AnimationController(
      vsync: this,
      duration: Duration(seconds: 60),
    );
      _audioCache = AudioCache(
        prefix: "audio/",
        fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
  }

  playme() async {
  AudioPlayer audioplay = await _audioCache.play('30sec.mp3');
  }

  AudioCache _audioCache;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Audio')),
      body: Column(
        children: <Widget>[
          Center(
              child: RaisedButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Text('Go Back'))),
          Container(
              margin: EdgeInsets.all(20.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  FloatingActionButton(
                    child: AnimatedBuilder(
                      animation: controller,
                      builder: (BuildContext context, Widget child) {
                        return new Icon(controller.isAnimating
                            ? Icons.pause
                            : Icons.play_arrow);
                      },
                    ),
                    onPressed: () {
                      if (controller.isAnimating && isPlaying){
                        controller.stop();

                     } else {
                        controller.reverse(
                            from: controller.value == 0.0
                                ? 1.0
                                : controller.value);    
                        playme();
                      }
                    },
                  ),
                ],
              )),
        ],
      ),
    );
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pause
ADD COMMENT
Topic
Name
4+7 =