Sign Up

Talk Programming , Career, Mental Health, Talk Personal Finance ❤️‍ Post a query and receive responses ✅

Have an account? Sign In


Have an account? Sign In Now

Sign In

Post a query and receive responses. Ask anything, Ask Mitra ❤️‍

Sign Up Here


Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.


Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.


Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Ask Mitra

Ask Mitra Logo Ask Mitra Logo

Ask Mitra Navigation

  • Home
  • About Us
  • Find Jobs
  • Blogs
    • Add New Blog !
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Ask a Question
  • Home
  • All Categories
  • Find Jobs
  • Points and Swags
    • Badges and Points
    • Ask Mitra Swags
  • Blog
    • Add New Blog !
  • FAQs
  • Community Members 💓
  • About Us
  • Contact Us
Home| Questions|Q 55524
Next
In Process
Virtual Wiz
Virtual WizTech Nerd
Asked: May 18, 20222022-05-18T19:50:33+05:45 2022-05-18T19:50:33+05:45In: —Flutter

help needed for my flutter project

help needed for my flutter project
  • 0
  • 4 4 Answers
  • 73 Views
  • 0 Followers
  • 0
Share
  • Facebook

    Related Questions

    • Can someone briefly explain me difference between Hot reload and Hot restart?
    • Hello guys, ma chai bachelor pass out ho ani I am looking for a place to learn more about flutter. ...
    • How to convert flutterflow project into flutter code?
    • Internship on flutter
    • Flutter Push Notification with One Signal

    You must login to add an answer.


    Forgot Password?

    Need An Account, Sign Up Here

    4 Answers

    • Voted
    • Oldest
    • Recent
    • Random
    1. Sangam AKA Ronnie Professional https://youtube.com/@codersangam
      2022-05-18T20:24:51+05:45Added an answer on May 18, 2022 at 8:24 pm

      what you need help? Please elaborate your question properly.

      • 0
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
      • Virtual Wiz Tech Nerd Love to Code | Just a Tech Enthusiast
        2022-05-18T20:32:13+05:45Replied to answer on May 18, 2022 at 8:32 pm
        This answer was edited.

        i am trying to make a music player app and using flutter_audio_query and just_audio packages..the app works but the only problem is i can play it in background….i went through some docs and found that there is another package audio_service that suits my needs perfectly but all references point out that i will have to make alot of code changes…like almost all of it except the ui ….so i want to know if there is any workaroud to make the music player work in background and lockscreen with minimal changes to my existing code

         

        heres what my code looks like

        
        import 'dart:io';
        import 'package:flutter/material.dart';
        import 'package:flutter_audio_query/flutter_audio_query.dart';
        import 'package:just_audio/just_audio.dart';
        
        class MusicPlayer extends StatefulWidget {
          SongInfo songInfo;
          Function changeTrack;
          final GlobalKey<MusicPlayerState> key;
          MusicPlayer({required this.songInfo, required this.changeTrack, required this.key}):super(key: key);
        
          @override
          MusicPlayerState createState() => MusicPlayerState();
        }
        
        class MusicPlayerState extends State<MusicPlayer> {
          double minimumValue = 0.0, maximumValue = 0.0, currentValue = 0.0;
          String currentTime = '', endTime = '';
          bool isPlaying = false;
        
          final AudioPlayer player = AudioPlayer();
        
          void initState() {
            super.initState();
            setSong(widget.songInfo);
          }
        
          void dispose(){
            super.dispose();
            player?.dispose();
          }
        
          void setSong(SongInfo songInfo) async {
            widget.songInfo = songInfo;
            await player.setUrl(widget.songInfo.uri);
            currentValue = minimumValue;
            maximumValue = player.duration!.inMilliseconds.toDouble();
            setState(() {
              currentTime = getDuration(currentValue);
              endTime = getDuration(maximumValue);
            });
            isPlaying=false;
            changeStatus();
            player.positionStream.listen((duration) {
              currentValue=duration.inMilliseconds.toDouble();
              setState((){
                currentTime=getDuration(currentValue);
              });
            });
          }
        
          void changeStatus(){
            setState((){
              isPlaying=!isPlaying;
        
            });
            if(isPlaying){
              player.play();
            }else{
              player.pause();
            }
          }
        
        
          String getDuration(double value) {
            Duration duration = Duration(milliseconds: value.round());
            return [duration.inMinutes, duration.inSeconds]
                .map((e) => e.remainder(60).toString().padLeft(2, '0'))
                .join(':');
          }
        
          Widget build(context) {
            return Scaffold(
              backgroundColor: Colors.black38,
              appBar: AppBar(
                backgroundColor: Colors.black,
                leading: IconButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  icon: Icon(
                    Icons.arrow_back,
                    color: Colors.white,
                  ),
                ),
                title: const Text(
                  'Now Playing',
                  style: TextStyle(color: Colors.white),
                ),
              ),
              body: Container(
                margin: EdgeInsets.fromLTRB(15, 50, 5, 0),
                child: Column(
                  children: <Widget>[
                    CircleAvatar(
                      backgroundImage: widget.songInfo.albumArtwork == null
                          ? AssetImage('assets/images/album_image.jpg')
                          : FileImage(
                              File(widget.songInfo.albumArtwork),
                            ) as ImageProvider,
                      radius: 95,
                    ),
                    Container(
                      color: Colors.black,
                      margin: EdgeInsets.fromLTRB(0, 10, 0, 7),
                      child: Text(
                        widget.songInfo.title,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 16,
                            fontWeight: FontWeight.w600),
                      ),
                    ),
                    Container(
                      color: Colors.black,
                      margin: EdgeInsets.fromLTRB(0, 0, 0, 15),
                      child: Text(
                        widget.songInfo.artist,
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: 12,
                            fontWeight: FontWeight.w500),
                      ),
                    ),
                    Slider(
                      value: currentValue,
                      min: minimumValue,
                      max: maximumValue,
                      onChanged: (value) {
                        currentValue = value;
                        player.seek(Duration(milliseconds: currentValue.round()));
                      },
                      inactiveColor: Colors.grey,
                      activeColor: Colors.green,
                    ),
                    Container(
                      transform: Matrix4.translationValues(0, -5, 0),
                      margin: EdgeInsets.fromLTRB(5, 0, 5, 15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            currentTime,
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 12,
                                fontWeight: FontWeight.w500),
                          ),
                          Text(
                            endTime,
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: 12,
                                fontWeight: FontWeight.w500),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          GestureDetector(
                            child: Icon(Icons.skip_previous,
                                color: Colors.white, size: 55,),
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              widget.changeTrack(false);
                            },
                          ),
                          GestureDetector(
                            child: Icon(isPlaying?Icons.pause:Icons.play_arrow,
                                color: Colors.white, size: 75,),
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              changeStatus();
                            },
                          ),
                          GestureDetector(
                            child: Icon(Icons.skip_next,
                                color: Colors.white, size: 55,),
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              widget.changeTrack(true);
                            },
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            );
          }
        }
        


         

        • 0
        • Share
          Share
          • Share on Facebook
          • Share on Twitter
          • Share on LinkedIn
          • Share on WhatsApp
        • Sangam AKA Ronnie Professional https://youtube.com/@codersangam
          2022-05-18T20:44:44+05:45Replied to answer on May 18, 2022 at 8:44 pm

          I understand. Besides that packages, you can use:

          1.  Flutter Playout

          2. Audio Manager

          packages with minimum code. Try these out. Please leave message if you need more help.

          • 0
          • Share
            Share
            • Share on Facebook
            • Share on Twitter
            • Share on LinkedIn
            • Share on WhatsApp
          • Virtual Wiz Tech Nerd Love to Code | Just a Tech Enthusiast
            2022-05-18T20:46:48+05:45Replied to answer on May 18, 2022 at 8:46 pm

            thanks alot i will give it a try🤗

            • 0
            • Share
              Share
              • Share on Facebook
              • Share on Twitter
              • Share on LinkedIn
              • Share on WhatsApp

    Sidebar

    Ask A Question

    Your Favourite Topics

    • Announcements
    • Blockchain
    • Books

        • —Non Tech Books
        • —technical books
    • Business and Entrepreneurship
    • Careers
    • College
    • Content and Blog
    • CyberSecurity
    • Design and Arts
    • Devices and Gadgets
    • Digital Marketing
    • Entertainment

        • —Movies-Series-TV
        • —Music
        • —Sports
    • Events
    • For Admins only.
    • Health

        • —Fitness
    • Money

        • —Personal Finance
        • —Stock Market
    • Operating System

        • —linux
        • —windows
    • Other
    • Paid Internship
    • Programming

        • —AI/ML
        • —APIs
        • —C & C#
        • —Django
        • —Flutter
        • —Go
        • —HTML&CSS
        • —Java
        • —JavaScript
        • —Mobile Apps Development
        • —Node Js
        • —NoSQL
        • —Php
        • —Python
        • —React JS
        • —SQL

    Stats

    • Questions 1k
    • Answers 10k
    • Best Answers 394
    • Users 2k

    Top 6 Members This Month

    Vicky

    Vicky

    • 0 Questions
    • 78 Points
    Sensei
    puppet

    puppet

    • 0 Questions
    • 23 Points
    Beginner
    wtfixair

    wtfixair

    • 0 Questions
    • 22 Points
    Beginner
    Dhanmaya

    Dhanmaya

    • 0 Questions
    • 20 Points
    Beginner
    Riyesh

    Riyesh

    • 0 Questions
    • 20 Points
    Beginner
    pranitkarki

    pranitkarki

    • 0 Questions
    • 20 Points
    Beginner

    Trending Tags

    blockchain c++ career coding College cybersecurity Django Flutter help html javascript laptop laravel linux poll Programming python question react web web development wordpress
    • Popular
    • Answers
    • Rounak Agrawal

      Ask Mitra Udemy Courses Giveaway

      • 76 Answers
    • Subedi Bibek

      The Complete JavaScript Course 2022: From Zero to Expert! Udemy ...

      • 73 Answers
    • Subedi Bibek

      Mega Giveaway at askmitra.com 🔥

      • 69 Answers
    • Sandeep Poudel
      Sandeep Poudel added an answer SOLVED: It was due to unfinished SSL certificate installation January 27, 2023 at 7:11 pm
    • Aashutosh_k
      Aashutosh_k added an answer Software piracy protection system Fingerprint voting system Stock price prediction… January 26, 2023 at 7:37 pm
    • Sangam AKA Ronnie
      Sangam AKA Ronnie added an answer Did you miss my video. https://youtu.be/Wo0NxEivd7A watch at end to… January 24, 2023 at 9:13 pm

    Related Questions

    • Can someone briefly explain me difference between Hot reload and ...

      • 2 Answers
    • Hello guys, ma chai bachelor pass out ho ani I ...

      • 1 Answer
    • How to convert flutterflow project into flutter code?

      • 2 Answers
    • Internship on flutter

      • 2 Answers
    • Flutter Push Notification with One Signal

      • 1 Answer

    Explore

    • Home
    • Trending Category
      • Programming
      • Web Development
      • —Mobile Apps Development
      • —Stock Market
      • Business and Entrepreneurship
      • Blockchain
      • College
      • —Personal Finance
      • —HTML&CSS
      • —JavaScript
      • —Python
      • —React JS
      • —Node Js
      • —C & C#
      • Content and Blog
      • Careers
    • All Categories
      • Go to All Categories
      • Health
      • —Go
      • —Flutter
      • Digital Marketing
      • —APIs
      • Devices and Gadgets
    • Find Job and Internships
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • All Blogs
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • Questions
      • Un Answered
      • New Questions
      • Most Seen Questions
      • Most Answered
      • Trending Questions
    • Tags

    Footer

    Ask Mitra

    Ask Mitra

    Ask Mitra is a social question and answer engine that will assist you in forming a community and connecting with others. Talk about programming, your career, your mental health, and your personal finances. ❤️‍ Post a query and receive responses ✅

    Quick Navigation

    • Ask a Question
    • Home
    • All Categories
    • Find Jobs
    • Points and Swags
      • Badges and Points
      • Ask Mitra Swags
    • Blog
      • Add New Blog !
    • FAQs
    • Community Members 💓
    • About Us
    • Contact Us

    Legal Stuff

    • Terms of use and policy