Zanzini
Zanzini

Reputation: 41

Trouble using the audioplayers package in my flutter app

I started with flutter last week and I got this problem with the audioplayer package. I am doing a Flutter Development Bootcamp with Dart at Udemy. I followed almost everything at the video, but I recived a huge error message that I can't solve.

This is my code:

import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(XylophoneApp());

class XylophoneApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.lightBlue,
        body: SafeArea(
          child: Container(
            child: Center(
              child: TextButton(
                onPressed: (){
                  final player = AudioCache();
                  player.play('assets/note1');
                },
                child: Text(
                  'click me'
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

This is the error message that i get: Running Gradle task 'assembleDebug'... e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors e: C:/Users/victo/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15... (The message is much more larger than this)

Compilation error. See log for more details

BUILD FAILED in 21s Exception: Gradle task assembleDebug failed with exit code 1

I've seen this message The binary version of its metadata is 1.5.1, expected version is 1.1.15, but I dont know what to do with it or how I can solve it.

This is my pubspec.yaml:

name: xylophone
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  audioplayers: ^0.19.1
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  uses-material-design: true

  assets:
    - assets/

Upvotes: 4

Views: 8365

Answers (6)

Sadam Hussain MCA
Sadam Hussain MCA

Reputation: 11

audioplayers: ^6.1.0

child: TextButton(
onPressed: () async {
final player = AudioPlayer();
await player.setSource(AssetSource('note1.wav'));
await player.resume();
},
  child: Text('Click Me')
),

Upvotes: 0

Kushal Hemanth Y
Kushal Hemanth Y

Reputation: 100

According to the latest stable releases, the AudioCache() was not dealing well instead you can try this

ElevatedButton(
  onPressed: () {
    final player = AudioPlayer();
    player.play(AssetSource('s1.wav'));
  },
  child: const Text(
    'Click Me',
  ),
),

Note : In player.play(AssetSource('s1.wav')) - in the place of s1.wav just give the filename instead giving the whole path like assets/s1.wav

Upvotes: 0

Chinedu Ofor
Chinedu Ofor

Reputation: 767

If you are using the latest version of audioplayers in my case ^1.0.1 then your code should look like this instead

onPressed: () async {
                final player = AudioPlayer();
                await player.play(AssetSource('note1.wav'));
              },

Wishing you all the best in your learning

Upvotes: 0

kalpesh Ajudiya
kalpesh Ajudiya

Reputation: 101

Migration Guide

dependencies: audioplayers: ^0.x.x

to

dependencies: audioplayers: ^1.0.1

https://github.com/bluefireteam/audioplayers/blob/main/migration_guide.md

try with this [1]: https://i.sstatic.net/jR5PG.png

AudioCache is dead, long live Sources One of the main changes was my desire to "kill" the AudioCache API due to the vast confusion that it caused with users (despite our best efforts documenting everything).

We still have the AudioCache class but its APIs are exclusively dedicated to transforming asset files into local files, cache them, and provide the path. It however doesn't normally need be used by end users because the AudioPlayer itself is now capable of playing audio from any Source.

What is a Source? It's a sealed class that can be one of:

UrlSource: get the audio from a remote URL from the Internet DeviceFileSource: access a file in the user's device, probably selected by a file picker AssetSource: play an asset bundled with your app, normally within the assets directory BytesSource (only some platforms): pass in the bytes of your audio directly (read it from anywhere). If you use AssetSource, the AudioPlayer will use its instance of AudioCache (which defaults to the global cache if unchanged) automatically. This unifies all playing APIs under AudioPlayer and entirely removes the AudioCache detail for most users.

Upvotes: 0

kksal55
kksal55

Reputation: 598

In gradle files, go to build.gradle (Project: YourApp). Then, change the following code (in buildscript):

from

ext.kotlin_version = '1.3.50'

to

ext.kotlin_version = '1.4.32'

or what ever the latest version of Kotlin available and make sure to update Kotlin version on Android Studio as well

After following the instructions, your error will be resolved.

Upvotes: 1

Abhijith
Abhijith

Reputation: 2327

You can look into error log Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15 but try to 1.3.50, i have app with audioplayer i am using this version if it doesn't work use 1.1.15 or the suggested version after changing version uninstall app and run flutter clean and run again

Try downgrade to a lower kotlin version in build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

}

Also refer this answers also if doesn't work in case

Upvotes: 0

Related Questions