Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»FLUTTER APP»How to Create Music Player UI screen with fully functional in flutter
    FLUTTER APP

    How to Create Music Player UI screen with fully functional in flutter

    DeepikaBy DeepikaAugust 30, 2024Updated:March 15, 2025No Comments3 Mins Read

    To create a fully functional music player UI in Flutter using GetX, follow these steps: How to Create Music Player UI screen with fully functional in flutter with step by step

    Table of Contents

    Toggle
    • 1. Set Up Your Flutter Project
    • 2. Add Dependencies
    • 3. Create the Music Controller
    • 4. Create the Music Player UI
    • 5. Update the Main Entry Point
    • 6. Run Your App
    • Output
    • Explanation
    • Related Articles

    1. Set Up Your Flutter Project

    Create a new Flutter project if you haven’t already:

    flutter create music_player
    cd music_player

    2. Add Dependencies

    Update your pubspec.yaml to include get for state management and audioplayers for audio playback:

    dependencies:
      flutter:
        sdk: flutter
      get: ^4.6.5
      audioplayers: ^0.20.1

    Run flutter pub get to install the packages.

    3. Create the Music Controller

    Create a file named music_controller.dart to handle the music playback logic:

    import 'package:get/get.dart';
    import 'package:audioplayers/audioplayers.dart';
    
    class MusicController extends GetxController {
      final AudioPlayer _audioPlayer = AudioPlayer();
      var isPlaying = false.obs;
      var duration = Duration.zero.obs;
      var position = Duration.zero.obs;
    
      @override
      void onInit() {
        super.onInit();
    
        _audioPlayer.onPlayerStateChanged.listen((state) {
          isPlaying.value = state == PlayerState.PLAYING;
        });
    
        _audioPlayer.onDurationChanged.listen((d) {
          duration.value = d;
        });
    
        _audioPlayer.onAudioPositionChanged.listen((p) {
          position.value = p;
        });
      }
    
      void playPause() {
        if (isPlaying.value) {
          _audioPlayer.pause();
        } else {
          _audioPlayer.play('https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3');
        }
      }
    
      void seekTo(Duration pos) {
        _audioPlayer.seek(pos);
      }
    
      @override
      void onClose() {
        _audioPlayer.dispose();
        super.onClose();
      }
    }

    4. Create the Music Player UI

    Create a file named music_player_screen.dart for the UI:

    import 'package:flutter/material.dart';
    import 'package:get/get.dart';
    import 'music_controller.dart';
    
    class MusicPlayerScreen extends StatelessWidget {
      final MusicController musicController = Get.put(MusicController());
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Music Player'),
          ),
          body: Obx(() {
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'Now Playing',
                  style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
                ),
                SizedBox(height: 20),
                Icon(
                  musicController.isPlaying.value ? Icons.music_note : Icons.music_off,
                  size: 100,
                  color: Colors.blue,
                ),
                SizedBox(height: 20),
                Slider(
                  value: musicController.position.value.inSeconds.toDouble(),
                  min: 0,
                  max: musicController.duration.value.inSeconds.toDouble(),
                  onChanged: (value) {
                    musicController.seekTo(Duration(seconds: value.toInt()));
                  },
                ),
                Text(
                  '${musicController.position.value.toString().split('.').first} / ${musicController.duration.value.toString().split('.').first}',
                  style: TextStyle(fontSize: 18),
                ),
                SizedBox(height: 20),
                ElevatedButton(
                  onPressed: () => musicController.playPause(),
                  child: Text(musicController.isPlaying.value ? 'Pause' : 'Play'),
                ),
              ],
            );
          }),
        );
      }
    }

    5. Update the Main Entry Point

    Ensure your main.dart uses GetMaterialApp:

    import 'package:flutter/material.dart';
    import 'package:get/get.dart';
    import 'music_player_screen.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return GetMaterialApp(
          title: 'Flutter Music Player',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MusicPlayerScreen(),
        );
      }
    }

    6. Run Your App

    Finally, run your app:

    flutter run

    Output

    Explanation

    1. MusicController:
    • Manages the audio player state, including play/pause, seeking, and tracking position.
    • Uses Rx types from GetX (obs properties) to automatically update the UI.
    1. MusicPlayerScreen:
    • Uses Obx to reactively rebuild the UI when the controller’s state changes.
    • Provides a play/pause button, a slider for seeking, and displays the current position and duration of the track.

    This setup keeps your UI reactive and state management clean, leveraging GetX for efficient and effective state handling.

    Related Articles

    • How to make Ludo app in Flutter with Source Code Step by step
    • How to make PDF Reader app in Flutter with Source Code Step by step
    • How to make QR Scanner app in Flutter with Source Code Step by step
    • How to Make a ToDo App with Flutter with source Code StepWise in 2024
    • What is package in Flutter (Dart) with example in 2024
    • What is class in Flutter(Dart) with example step by step
    • Advantage of Flutter with examples in 2024
    • Top 15 Amazing Applications Built with Flutter Framework
    • Specialized PDF reader designed specifically for music sheets
    • Christmas Quote Generator app built with flutter source code
    • How to make review and rating ui with flutter stepwise
    • Create custom social login button Google, Facebook and Apple ui

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticleHow to make ListView Builder Ui in flutter with Source Code
    Next Article How to make Diary App using flutter stepwise using getx

    Related Posts

    Animated Backgrounds in Flutter: A Complete Guide

    FLUTTER 4 Mins Read

    How to make Diary App using flutter stepwise using getx

    FLUTTER APP 4 Mins Read

    How to make ListView Builder Ui in flutter with Source Code

    FLUTTER UI 5 Mins Read

    How to create TabBar view in flutter with source code step wise

    FLUTTER UI 5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.