Search
 
SCRIPT & CODE EXAMPLE
 

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();
                      }
                    },
                  ),
                ],
              )),
        ],
      ),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: excuse function after 2 second flutter 
Dart :: dart fold list 
Dart :: change color icon tabbar flutter 
Dart :: dart exit function 
Dart :: dart then method 
Dart :: How to create maps in flutter 
Dart :: how to format timeofday in custom format flutter 
Dart :: late in dart 
Dart :: difference between hot reload and hot restart in flutter 
Dart :: opendrawer without appbar 
Dart :: how to use $ input in dart as a string 
Dart :: dart svg drawer 
Dart :: tab splash hide flutter 
Dart :: dart test matcher expecting a field value 
Dart :: flutter standarrt icon size 
Dart :: dart format print 
Dart :: Cannot remove from an unmodifiable list dart 
Dart :: flutter circular elevated button 
Dart :: round border container flutter 
Swift :: swift notifications mac 
Swift :: ui alert swift yes no 
Swift :: add toggle without text swiftui 
Swift :: swift http request 
Swift :: loop key value swift 
Swift :: swift go back to previous view controller 
Swift :: swift how to animate constraint change 
Swift :: dismiss two view controllers at once swift 
Swift :: ios swift create new background thread 
Swift :: Swift Basic Input 
Swift :: How to hide view in swiftui 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =