diff --git a/README.md b/README.md index b5cf8d9..94fe86c 100644 --- a/README.md +++ b/README.md @@ -197,48 +197,43 @@ ##### [Go back to Index](#index) - Getting a lengthy error when trying to use **`audioplayers` plugin**? - - - All you need to do is open **`android > build.gradle` (Project Level `gradle` file)** - - - Inside **`buildscript {}`**, you'll find **`ext.kotlin_version` (Line 2 in file)** - - - Replace whatever version it is with [**Latest Stable Kotlin Version**](https://kotlinlang.org/docs/releases.html#release-details) - - - As of **July 23, 2021** it is, **`ext.kotlin_version = '1.5.21'`** - - - Now, **re-install** the app. If it's already running, press **Stop** then press **Run (Play)** again. -- **`FlatButton`** is **`deprecated`**, so use **`TextButton`** instead. +- first you need to play the sound from "asset/note1.wav" -- By the end, the implementation of your **`TextButton`** should look like this: - - ```dart +- Then you can copy paste this code : + +```dart +import 'package:flutter/material.dart'; +import 'package:audioplayers/audioplayers.dart'; + +void main() => runApp(XylophoneApp()); + +class XylophoneApp extends StatelessWidget { @override Widget build(BuildContext context) { - return Expanded( - child: TextButton( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(color), + final player = AudioPlayer(); + + return MaterialApp( + home: Scaffold( + body: SafeArea( + child: Center( + child: TextButton( + onPressed: () async { + await player.play(AssetSource('note1.wav')); + }, + child: Text("Click me"), + ), + ), ), - onPressed: () { - playSound(soundNumber); - }, ), ); } - ``` - - - **`AudioCache`** is **`deprecated`**, so use **`AudioPlayer`** instead. - - By the end, your solution to playing the audio should look like this: - ```dart - void playSound(int soundNumber) { - final player = AudioPlayer(); - player.setSource(AssetSource('note$soundNumber.wav')); - } - ``` +} +``` +- after that start your programe , it should work + +- **`AudioCache`** is **`deprecated`**, so use **`AudioPlayer`** instead. -- An example of a working project as of 16/07/2022 has been linked below: - - [Link to repository](https://github.com/vpatel-dev/xylophone-flutter) ## Section 10 : Quizzler App (Lesson 94)