Search
 
SCRIPT & CODE EXAMPLE
 

DART

flutter button playing sound

void main() => runApp(HomePage());

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  AudioCache _audioCache;

  @override
  void initState() {
    super.initState();
    // create this only once
    _audioCache = AudioCache(prefix: "audio/", fixedPlayer: AudioPlayer()..setReleaseMode(ReleaseMode.STOP));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("Music play")),
        body: RaisedButton(
          onPressed: () => _audioCache.play('my_audio.mp3'),
          child: Text("Play Audio"),
        ),
      ),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: @override in dart 
Dart :: flutter - resize asset image to dart ui image 
Dart :: dart async stream 
Dart :: how to vibrate phone flutter 
Dart :: what is pubspec.yaml 
Dart :: flutter get child widget size 
Dart :: late in dart 
Dart :: dart typedef 
Dart :: search functionality dart 
Dart :: support various locales flutter 
Dart :: flutter pre intistate statefulwidget 
Dart :: single clone data in flutter 
Dart :: how to create camera icon in flutter dev 
Dart :: flutter string add , for 1000 
Dart :: dart async map 
Dart :: flutter column stackov 
Dart :: how to show snackbar in initState() in flutter 
Dart :: dart code examples 
Swift :: swift self.present full screen 
Swift :: change from Date to String swift 5 
Swift :: swift func for constraint 
Swift :: How to change the backgroundColor of UIDatePicker or UIPicker ? 
Swift :: Undefined symbol: protocol descriptor for Swift.ExpressibleByFloatLiteral 
Swift :: swift wait 5 seconds 
Swift :: swiftui text field 
Swift :: power number in swift13 
Swift :: how to loop swift 
Swift :: swift find difference between two arrays 
Swift :: iOS & Swift - The Complete iOS App Development Bootcamp 
Swift :: swft image 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =