问题描述
我想在单击按钮时播放声音,所以我使用了“audioplayers”依赖项:
我将其导入到 pubspec.yaml 文件中:
dependencies:
Flutter:
sdk: Flutter
//...Other dependencies
audioplayers: ^0.15.1
assets_audio_player: ^2.0.14
这是我的 PlayerPage.dart
import 'dart:math';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:Flutter/material.dart';
class FlipCardPage2 extends StatefulWidget {
@override
_FlipCardPage2State createState() => _FlipCardPage2State();
}
class _FlipCardPage2State extends State<FlipCardPage2> {
var firstColor = Color(0xFFD7C26A),secondColor = Color(0xFF451428);
AudioPlayer audioPlayer = AudioPlayer();
AudioPlayerState audioPlayerState = AudioPlayerState.PAUSED;
AudioCache audioCache;
String path = "goalceleb.mp3";
@override
void initState() {
// Todo: implement initState
super.initState();
audioCache = AudioCache(fixedplayer: audioPlayer);
audioPlayer.onPlayerStateChanged.listen((AudioPlayerState state) {
setState(() {
audioPlayerState = state;
});
});
}
@override
void dispose() {
// Todo: implement dispose
super.dispose();
audioPlayer.release();
audioPlayer.dispose();
audioCache.clearCache();
}
playMusic() async{
await audioCache.play(path);
}
pauseMusic() async{
await audioPlayer.pause();
}
@override
Widget build(BuildContext context) {
return Container(
),),width: double.infinity,child: Column(
mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,children: [
FlipCard(),SizedBox(
height: 90.0,SliderButton(
action: () {
///Do something here OnSlide
playMusic();
},icon: Icon(
Icons.power_settings_new,color: Colors.red,size: 40.0,semanticLabel: 'Text to announce in accessibility modes',)),],);
}
}
//... Other code
}
当我尝试使用我的 Android 模拟器对其进行测试时,收到此错误消息:
Running Gradle task 'assembleDebug'...
e: /home/coach/Documents/development/Flutter/.pub-cache/hosted/pub.dartlang.org /assets_audio_player-2.0.15/android/src/main/kotlin/com/github/florent37/assets_audio_player/notification/ImageDownloader.kt: (12,19): Unresolved reference: FlutterInjector
e: /home/coach/Documents/development/Flutter/.pub-cache/hosted/pub.dartlang.org/assets_audio_player-2.0.15/android/src/main/kotlin/com/github/florent37/assets_audio_player/notification/ImageDownloader.kt: (61,53): Unresolved reference: FlutterInjector
FAILURE: Build Failed with an exception.
* What went wrong:
Execution Failed for task ':assets_audio_player:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD Failed in 12s
Exception: Gradle task assembleDebug Failed with exit code 1
我在网上做了一些研究,我执行了很多命令,例如“Flutter clean”和“Flutter doctor”等......我不知道这是不是与我的Android上安装的Flutter版本有关工作室...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)