我想添加背景音频在我的飞溅屏幕。所以尝试了下面的代码。但我有一些例外。任何人,请帮助我解决this.Here,我使用的包颤音。
--这是我的密码
import 'dart:async';
import 'package:FlutterNewApp/Screens/HomeMain.dart';
import 'package:flutter/material.dart';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter_sound/flutter_sound.dart';
class Splash extends StatefulWidget {
@override
_SplashState createState() => _SplashState();
}
class _SplashState extends State<Splash> {
@override
void initState() {
FlutterSound flutterSound = FlutterSound();
flutterSound.thePlayer.startPlayer(fromURI: 'assets/audio/splash.mp3');//My splash.mp3 is inside the audio folder in assets folder
super.initState();
Timer(
Duration(minutes: 50),
() => Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => HomeMain())));
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: AnimatedTextKit(
totalRepeatCount: 1,
//repeatForever: true,
animatedTexts: [
TyperAnimatedText(
'Tofee Ride',
//speed: Duration(milliseconds: 50),
textStyle: TextStyle(
fontFamily: 'Ultra-Regular',
color: Colors.pink[600],
fontSize: 30,
)
),
]),
),
Center
(child:AnimatedTextKit(
totalRepeatCount: 1,
//repeatForever: true,
animatedTexts: [
TyperAnimatedText('Learning App for classes I - IV')
]) ,)
],)
);
}
}例外情况如下所示。请帮帮忙。这里我用的是包裹颤振声。
发布于 2021-06-12 08:06:53
正如异常消息中所解释的:"Player不打开“
Flutter_sound文档说:
在调用startPlayer()之前,必须打开会话.
当您完成它时,您必须关闭会话。放置这些谓词的好地方是在过程initState()和good ()中。
@override
void initState() {
super.initState();
// Be careful : openAudioSession return a Future.
// Do not access your FlutterSoundPlayer or FlutterSoundRecorder before the completion of the Future
_myPlayer.openAudioSession().then((value) {
setState(() {
_mPlayerIsInited = true;
});
});
}
@override
void dispose() {
// Be careful : you must `close` the audio session when you have finished with it.
_myPlayer.closeAudioSession();
_myPlayer = null;
super.dispose();
}https://stackoverflow.com/questions/67946306
复制相似问题