I want to add background audio in my splash screen. So tried the below code. But I got some exceptions. ( Flutter )

Jithu Hari

I want to add background audio in my splash screen. So tried the below code. But I got some exceptions. Anyone pls help me to solve this.Here I use the package Flutter Sound.

-------------This is My Code-----------------

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')
        ]) ,)
      ],)
    );
  }
}

Exception is given below. Pls Help. Here I use the Package Flutter Sound.

This is the Exception I got

Danaru

As explained in the exception message: "Player is not open"

Flutter_sound documentation say:

  1. Open and close the audio session

Before calling startPlayer() you must open the Session.

When you have finished with it, you must close the session. A good places to put those verbs are in the procedures initState() and dispose().

@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://tau.canardoux.xyz/guides_getting_started.html#2-open-and-close-the-audio-session

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I remove the default white Splash Screen in Flutter. I do not want a Splash Screen at all

I want to add single quotes in the below code ('')

Flutter: I want my screen to automatically scroll up when selecting Textfield so that my submit button is not hidden?

I want to make a type bot which will join my classes automatically i have tried it but got the error

How to add a Appbar to my code, i have tried so many tutorials and i cannot stitch the code code together

How can i add UIActivityIndicator to Splash screen of my app?

My Splash Screen Doent Seen If I Add Sleep Method

What should I add in my code so I will get the output I want

why is Youtube loading so fast, I tried many time with my flutter code, every time I move the progress,

flutter - got stuck at splash screen

I want to add bullets to my code , in unity

i tried implementing "srmklive/paypal": "~1.0", into my laravel project locally, while testing the implementation, i got an error below

i want to remove any from this catch block , below is my code

I tried updating the php in my laragon but I got this

In the below code I want to add if statement for GridViewBind() where in the else case I want to say "NO DATA TO DISPLAY"

i am trying to create foreign keys but i got error 1822 .. please see my code below

i got the error When i printing the inorder traversing in my C code which is given below

How can I make an Android splash screen with text & background color that changes if my phone is in light or dark mode?

I want to add a transparent overlay to my background image in android

I want to add a column in my Data Frame according to some condition

i want to add some info in my entry widget in tkinter

I want to add some variation to the colours of my sprites in unity

I want to have 3 div in a row in my page, i tried flex,grid,inline, but i am unable to do so

I want to add an Alert Dialog in my Catch block in flutter

I want to add a void function to my stack class in flutter

when i want to integration testing with a payment method on my code i got this error. Expected declaration

I want to convert the below code to a lambda expression so that i can remove ugly for loops

I want to make a splash screen made with multiple images

I have one array in javascript, i want to convert that as objects, here is my below code