我想播放一首存储在我的assets文件夹中的歌曲,但据我所知,只有一种方法,那就是临时文件夹方法。还有别的办法吗?下面是我尝试使用的音频播放器包,虽然它使用了一个URL,但它仍然不能工作。
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class songPage extends StatefulWidget {
@override
_songPageState createState() => _songPageState();
}
AudioPlayer audioPlayer = AudioPlayer();
class _songPageState extends State<songPage> {
@override
Widget build(BuildContext context) {
return Container(
decoration: new BoxDecoration(color: Colors.blue),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Page 2',
style: TextStyle(
fontFamily: 'FlamanteRoma' ,
fontSize: 50,
color: Colors.white,
),
),
RaisedButton(
child: Icon(Icons.play_arrow),
onPressed: (){
playLocal() async {
int result = await audioPlayer.play('assets\audio\lovesong.mp3', isLocal: true);
}
print('It runs');
})
],
),
);
}
}
这是我得到的输出:
I/flutter (30875): It runs
但它不能播放,可能是应用程序中的音量?(我的设备音量设置为最大)
发布于 2020-02-07 07:00:50
根据docs的说法
如果你有一部MissingPluginException,试着在安卓上使用
flutter build apk
,或者使用flutter build ios
发布于 2020-02-07 07:47:41
您是否在pubspec.yaml中包含了您的资产?
flutter:
assets:
- assets/
发布于 2020-02-08 16:00:35
为了只播放一首歌曲,我设法使用音频缓存,只需在实现后声明音频缓存,然后声明路径,最后在onpressee按钮中声明audiocache.play
https://stackoverflow.com/questions/60108513
复制相似问题