spotify_auth_player 0.1.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

Spotify Plugin for android #

A new Flutter plugin.

A new Flutter plugin.Spotidy Sdk which handles authorization as well as playing playlist of your choice free.

Getting Started #

2 step Configurations #

1 . Get client id

This project is a starting point for a Flutter Just go to the spotify developers site login and register your application. plug-in package, You just need to follow and prepare your environment from Quick Start . a specialized package that includes platform-specific implementation code for Android

How to register

Set redirect uri as spotify-sdk://auth and app name as your app nameand android section package name and debug,release fingerprint in registration. Your registreation is complete. you will be provided with client id.

2. Import them as module

Just goto this site and download spotify-app-remote-release-0.7.0.aar and spotify-auth-release-1.2.3.aar and import them as module in your android app

step1

step2

step3

Initialize Spotifire #

      await Spotifire.init(clientid: "Your client id");

Connect Remote #

      await Spotifire.connectRemote.then(print);

Play a playlist #

 if (await Spotifire.isRemoteConnected)
              await Spotifire.playPlaylist(
                  playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");

Disconnect remote #

 if (await Spotifire.isRemoteConnected) await Spotifire.disconnectRemote;

play #

  await Spotifire.playPlaylist(
                  playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");

You can get playlistUrl from spotify App and convert it easily with Spotifire's getSpotifyUri method passing it the url and directly play it.without specifically getting the uris from dekstop app.

directly get uri from mobile

  await Spotifire.playPlaylist(
                  playlistUri: Spotifire.getSpotifyUri(spotify_url));

pause #

                await Spotifire.pauseMusic ;

resume #

                await Spotifire.resumeMusic;

skip previous #

                await Spotifire.skipPrevious;

skip next #

                await Spotifire.skipNext;

seekTo #

   await Spotifire.seekTo(Duration position);
   

Listen to music stream #

  Spotifire.musicStream.listen((music) {
      // print("Music" + music.runtimeType.toString());
      if (mounted && music is Music)
        setState(() {
          _music = music;
        });
    }).onError((error) {
      print(error);
    });

Position Stream #


Spotifire.positonStream.listen(print)

Demo #

example

0.1.7 #

Spotify Plugin for android #

A new Flutter plugin.

A new Flutter plugin.Spotidy Sdk which handles authorization as well as playing playlist of your choice free.

Getting Started #

2 step Configurations #

1 . Get client id

This project is a starting point for a Flutter Just go to the spotify developers site login and register your application. plug-in package, You just need to follow and prepare your environment from Quick Start . a specialized package that includes platform-specific implementation code for Android

How to register

Set redirect uri as spotify-sdk://auth and app name as your app nameand android section package name and debug,release fingerprint in registration. Your registreation is complete. you will be provided with client id.

2. Import them as module

Just goto this site and download spotify-app-remote-release-0.7.0.aar and spotify-auth-release-1.2.3.aar and import them as module in your android app

step1

step2

step3

Initialize Spotifire #

      await Spotifire.init(clientid: "Your client id");

Connect Remote #

      await Spotifire.connectRemote.then(print);

Play a playlist #

 if (await Spotifire.isRemoteConnected)
              await Spotifire.playPlaylist(
                  playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");

Disconnect remote #

 if (await Spotifire.isRemoteConnected) await Spotifire.disconnectRemote;

play #

  await Spotifire.playPlaylist(
                  playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");

You can get playlistUrl from spotify App and convert it easily with Spotifire's getSpotifyUri method passing it the url and directly play it.without specifically getting the uris from dekstop app.

directly get uri from mobile

  await Spotifire.playPlaylist(
                  playlistUri: Spotifire.getSpotifyUri(spotify_url));

pause #

                await Spotifire.pauseMusic ;

resume #

                await Spotifire.resumeMusic;

skip previous #

                await Spotifire.skipPrevious;

skip next #

                await Spotifire.skipNext;

seekTo #

   await Spotifire.seekTo(Duration position);
   

Listen to music stream #

  Spotifire.musicStream.listen((music) {
      // print("Music" + music.runtimeType.toString());
      if (mounted && music is Music)
        setState(() {
          _music = music;
        });
    }).onError((error) {
      print(error);
    });

Position Stream #


Spotifire.positonStream.listen(print)

Demo #

example

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:spotify_auth_player/spotify_auth_player.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Music _music;
  int totaldurationinmilli = 0;
  bool ispaused = false;
  @override
  void initState() {
    super.initState();

    initPlatformState();
  }

  Future<void> initPlatformState() async {
    await Spotifire.init(clientid: "Your client id");

    if (!mounted) return;

    Spotifire.musicStream.listen((music) {
      // print("Music" + music.runtimeType.toString());
      if (mounted)
        setState(() {
          totaldurationinmilli = music.duration.inMilliseconds;
          print(music.duration);
          _music = music;
        });
    }).onError((error) {
      print(error);
    });
  }

  double val = 0.01;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.black87,
          title: const Text('Spotifire'),
        ),
        body: Stack(
          children: <Widget>[
            Container(
              height: 900,
              // width: MediaQuery.of(context).size.width,
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                      begin: AlignmentDirectional.topStart,
                      end: AlignmentDirectional.bottomEnd,
                      colors: <Color>[
                    Color.fromRGBO(29, 185, 84, 1.0),
                    Color.fromRGBO(25, 20, 20, 1.0)
                  ])),
            ),
            ListView(
              padding: const EdgeInsets.all(12),
              children: <Widget>[
                Column(
                  children: <Widget>[
                    if (_music != null)
                      Material(
                          elevation: 7.0,
                          child: Image.memory(_music.musicImage)),
                    Text(_music != null ? _music.name : "Loding ... ",
                        style: Theme.of(context)
                            .textTheme
                            .display1
                            .copyWith(color: Colors.white.withOpacity(0.95))),
                    Text(
                      _music != null ? _music.album : "Loding ... ",
                      style: Theme.of(context)
                          .textTheme
                          .headline
                          .copyWith(color: Colors.white70),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 228.0),
                      child: Text(
                        _music != null
                            ? _music.duration.toString()
                            : "Loding ... ",
                        style: TextStyle(color: Colors.white54),
                      ),
                    ),
                    SizedBox(
                      height: 17,
                    ),
                    StreamBuilder<Duration>(
                        stream: Spotifire.positonStream,
                        // initialData: Duration.zero,
                        builder: (context, snapshot) {
                          if (!snapshot.hasData)
                           return Slider.adaptive(
                              value: 0.0,
                              onChanged: (d) {},
                            );
                            print(snapshot.hasData);
                          val = snapshot.hasData
                              ? _getValue(snapshot.data.inMilliseconds)
                              : val;

                          return Slider.adaptive(
                            value: val,
                            onChanged: (double cv) async {
                              final int skd =
                                  (totaldurationinmilli * cv).floor();
                              final Duration dur = Duration(milliseconds: skd);
                              await Spotifire.seekTo(
                                  seekDuration: dur,
                                  totalDuration: Duration(
                                      milliseconds: totaldurationinmilli));
                            },
                          );
                        }),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        IconButton(
                            icon: Icon(
                              Icons.skip_previous,
                              size: 40,
                              color: Colors.white70,
                            ),
                            onPressed: () async {
                              await Spotifire.skipPrevious;
                            }),
                        AnimatedCrossFade(
                            firstChild: IconButton(
                                icon: Icon(
                                  Icons.play_arrow,
                                  color: Colors.white,
                                  size: 40,
                                ),
                                onPressed: () async {
                                  await Spotifire.resumeMusic.whenComplete(() {
                                    setState(() {
                                      ispaused = false;
                                    });
                                  });
                                }),
                            secondChild: IconButton(
                                icon: Icon(Icons.pause,
                                    size: 40, color: Colors.white),
                                onPressed: () async {
                                  await Spotifire.pauseMusic.whenComplete(() {
                                    setState(() {
                                      ispaused = true;
                                    });
                                  });
                                }),
                            crossFadeState: ispaused
                                ? CrossFadeState.showFirst
                                : CrossFadeState.showSecond,
                            duration: const Duration(milliseconds: 700)),
                        IconButton(
                            icon: Icon(Icons.skip_next,
                                size: 40, color: Colors.white70),
                            onPressed: () async {
                              await Spotifire.skipNext;
                            }),
                      ],
                    )
                  ],
                )
              ],
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
            child: Icon(
              Icons.playlist_play,
              size: 35,
            ),
            onPressed: () async {
              await Spotifire.getAccessToken.then(print);

              await Spotifire.connectRemote
                  .then(print)
                  .whenComplete(() => print("compl"));
              try {
                if (await Spotifire.isRemoteConnected)
                  await Spotifire.playPlaylist(
                      playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");
              } catch (e) {
                print(e);
              }
            }),
      ),
    );
  }

  double _getValue(int milliseconds) {
    double percentage = (milliseconds / totaldurationinmilli) * 100;

    print(percentage.toString() + " % ");

    double tpo = (percentage / 100) * 1.0;
    return tpo;
  }

  @override
  void dispose() {
    Spotifire.close();

    super.dispose();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  spotify_auth_player: ^0.1.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:spotify_auth_player/spotify_auth_player.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
34
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:spotify_auth_player/spotify_auth_player.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:spotify_auth_player/spotify_auth_player.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:spotify_auth_player/spotify_auth_player.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:spotify_auth_player/spotify_auth_player.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [spotify_auth_player] that is in a package requiring null.

Health issues and suggestions

Document public APIs. (-0.33 points)

43 out of 44 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test