/flutter_spotify_clone

Flutter project cloning some features of Spotify app

Primary LanguageDart

spotify_clone

A new Flutter project.

Packages explanation

In the project we have used just_audio and audio_service packages

audio_service package works to handle audio in the background and show the media notification, it offer a framework by implement the [BaseAudioHandler] class using any audio package, here we used just_audio package

    class MyAudioHandler extends BaseAudioHandler {

        final _player = AudioPlayer();
        @override
        Future<void> play() => _player.play();

        @override
        Future<void> pause() => _player.pause();

        @override
        Future<void> seek(Duration position) => _player.seek(position);

        @override
        Future<void> setRepeatMode(AudioServiceRepeatMode repeatMode) async {
            return _player.setLoopMode(
            AudioPackagesHelper.serviceToJustAudioLoopMode(repeatMode),
            );
        }

        @override
        Future<void> skipToNext() async {
            return _player.seekToNext();
        }

        @override
        Future<void> skipToPrevious() async {
            return _player.seekToPrevious();
        }

        //...

    }

Integration

we add required changes for android and ios after in the main methode we initialize the audio service

    void main() async {
        WidgetsFlutterBinding.ensureInitialized();

        await setupInjection();

        runApp(const SpotifyApp());
    }


    final sl = GetIt.instance;

    Future<void> setupInjection() async {
        final audioService = await initAudioService();

        sl.registerLazySingleton<AudioHandler>(() => audioService);

        sl.registerLazySingleton(() => SongRepository(audioHandler: sl()));

        sl.registerFactory(() => MusicPlayerCubit(songRepository: sl()));
    }

Resources :