简体   繁体   English

在我的 flutter 应用程序中使用音频播放器 package 时遇到问题

[英]Trouble using the audioplayers package in my flutter app

I started with flutter last week and I got this problem with the audioplayer package.我上周从 flutter 开始,我在音频播放器 package 上遇到了这个问题。 I am doing a Flutter Development Bootcamp with Dart at Udemy.我正在 Udemy 使用 Dart 进行 Flutter 开发训练营。 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.这是我收到的错误消息:正在运行 Gradle 任务“assembleDebug”... e:在依赖项中发现了不兼容的类。 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.从类路径中删除它们或使用“-Xskip-metadata-version-check”来抑制错误 e: C:/Users/victo/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-std-lib 1.5.10.jar./META-INF/kotlin-stdlib:kotlin_module。 Module was compiled with an incompatible version of Kotlin.使用不兼容版本的 Kotlin 编译模块。 The binary version of its metadata is 1.5,1.其元数据的二进制版本是 1.5,1。 expected version is 1.1.15... (The message is much more larger than this)预期版本是 1.1.15...(消息比这大得多)

  • What went wrong: Execution failed for task ':audioplayers:compileDebugKotlin'.出了什么问题:任务“:audioplayers:compileDebugKotlin”执行失败。

Compilation error.编译错误。 See log for more details有关详细信息,请参阅日志

  • Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志 output。 Run with --scan to get full insights.运行 --scan 以获得完整的见解。

  • Get more help at https://help.gradle.orghttps://help.gradle.org获得更多帮助

BUILD FAILED in 21s Exception: Gradle task assembleDebug failed with exit code 1 21 秒内构建失败异常:Gradle 任务 assembleDebug 失败,退出代码为 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.我看过这条消息 The binary version of its metadata is 1.5.1, expected version is 1.1.15 ,但我不知道如何处理它或如何解决它。

This is my pubspec.yaml:这是我的 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/

In gradle files, go to build.gradle (Project: YourApp).在 gradle 文件中,转到 build.gradle(项目:YourApp)。 Then, change the following code (in buildscript):然后,更改以下代码(在 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或者最新版本的 Kotlin 可用,并确保在 Android Studio 上更新 Kotlin 版本

After following the instructions, your error will be resolved.按照说明操作后,您的错误将得到解决。

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您可以查看错误日志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 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 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但尝试1.1.15 1.3.50版本卸载应用程序并运行flutter clean并再次运行

Try downgrade to a lower kotlin version in build.gradle尝试在 build.gradle 中降级到较低的 kotlin 版本

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

}

Also refer this answers also if doesn't work in case如果万一不起作用,也请参考此答案

Migration Guide迁移指南

dependencies: audioplayers: ^0.xx依赖项:音频播放器:^0.xx

to

dependencies: audioplayers: ^1.0.1依赖项:音频播放器:^1.0.1

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

try with this试试这个[1]:https://i.stack.imgur.com/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). AudioCache 已死,源源不断主要变化之一是我希望“杀死”AudioCache API,因为它给用户造成了巨大的混乱(尽管我们尽最大努力记录一切)。

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.我们仍然有 AudioCache 类,但它的 API 专门用于将资产文件转换为本地文件、缓存它们并提供路径。 It however doesn't normally need be used by end users because the AudioPlayer itself is now capable of playing audio from any Source.然而,最终用户通常不需要使用它,因为 AudioPlayer 本身现在能够播放来自任何来源的音频。

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). UrlSource:从 Internet 的远程 URL 获取音频 DeviceFileSource:访问用户设备中的文件,可能由文件选择器选择 AssetSource:播放与您的应用程序捆绑的资产,通常在资产目录中 BytesSource(仅限某些平台):直接传递音频的字节(从任何地方读取)。 If you use AssetSource, the AudioPlayer will use its instance of AudioCache (which defaults to the global cache if unchanged) automatically.如果您使用 AssetSource,AudioPlayer 将自动使用其 AudioCache 实例(如果未更改,则默认为全局缓存)。 This unifies all playing APIs under AudioPlayer and entirely removes the AudioCache detail for most users.这统一了 AudioPlayer 下的所有播放 API,并为大多数用户完全删除了 AudioCache 细节。

If you are using the latest version of audioplayers in my case ^1.0.1 then your code should look like this instead如果您在我的案例^1.0.1中使用最新版本的音频播放器,那么您的代码应该看起来像这样

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

Wishing you all the best in your learning祝你在学习中一切顺利

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Flutter 应用程序启动时使用音频播放器 package 开始循环播放音乐? - How to start playing music in loop using audioplayers package on start of Flutter app? 如何使用audioplayers package播放本地音频flutter - how to use audioplayers package to play local audio flutter 为什么我在使用音频播放器时出错:^0.17.3 package,错误是“任务':app:processDebugManifest'执行失败,构建失败” - why i am getting error while using audioplayers: ^0.17.3 package, error is “Execution failed for task ':app:processDebugManifest', Build failed” 无法运行我的第一个 flutter 应用程序 - having trouble to run my first flutter app Flutter 播放器没有声音 - Flutter no sound with audioplayers 我的 Flutter 应用程序的 package 名称是正确的? - Which is right package name for my Flutter app? Flutter 音频播放器无法加载资产 - Flutter Audioplayers Unable to load asset 创建我的应用的第二个版本时,更改包名很麻烦 - Creating a second version of my app trouble changing package name Flutter 应用程序在使用 flutter_pdfview package 时崩溃 - Flutter app crashing while using flutter_pdfview package 添加 cloud_firebase 包后,我的 Flutter 应用程序未运行 - My Flutter App is not running after adding cloud_firebase package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM