deezer_playback 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

Deezer Playback #

Deezer Playback Plugin.

No iOS Implementation yet, WIP..

Features #

  • Connect / Authorize
  • Play (track)
  • Resume / pause
  • Queue
  • Playback position
  • Seek
  • Seek to relative position
  • Play Next
  • Play Previous
  • Repeat
  • Search For Tracks
  • Get Track

Installation #

IMPORTANT: Make sure you have the Deezer app installed and that you are logged in or your test device!

First, add deezer_playback as a dependency in your pubspec.yaml file.

Afterwards, download the Deezer Android SDK here and move the deezer-sdk--x.x.x.aar file to android/app/libs/ in your project.

IMPORTANT: Make sure you add permissions bellow to your Android Manifest located in /android/app/src/main/AndroidManifest.xml !

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-library android:name="org.apache.http.legacy" android:required="false" />

Then initialize the deezer playback sdk like this

@override
  void initState() {
    super.initState();
    initConnector();
    connect();
  }

  /// Initialize the Deezer playback sdk, by calling iniatilizeDeezer
  Future<void> initConnector() async {
    try {
      await DeezerPlayBack.iniatilizeDeezer(appId: "").then(
          (connected) {
        if (!mounted) return;
        // If the method call is successful, update the state to reflect this change
        setState(() {
          _connectedToDeezer = connected;
        });
      }, onError: (error) {
        // If the method call trows an error, print the error to see what went wrong
        print(error);
      });
    } on PlatformException {
      print('Failed to connect.');
    }
  }
  /// Initialize the Deezer playback sdk, by calling DeezerConnect
  Future<void> connect() async {
    try {
      await DeezerPlayback.connectToDeezer().then((authorised) {
        if (!mounted) return;
        // If the method call is successful, update the state to reflect this change
        setState(() {
          _connectedToDeezer = authorised;
        });
        print("we authorized deezer"+_connectedToDeezer.toString());
      }, onError: (error) {
        // If the method call trows an error, print the error to see what went wrong
        print(error);
      });
    } on PlatformException {
      print('Failed to connect.');
    }
  }

After this you can use all the available methods

Available methods #

Methoddescriptionparametersnotes
iniatilizeDeezerInitilizes the deezer playback sdkappId,
connectToDeezerConnect to deezer account
playPlay's a deezer track, album or playlisttrack Id
pausePause's the currently playing track
resumeResumes the currently paused track
skipNextPlay's the next track
skipPreviousPlay's the previous track
seekToSeeks to the passed timetime(mS)
seekToRelativePositionSeeks to relative position+-time(mS)
toggleRepeatToggle Repeat options
getPlaybackPositionGet's the current tracks playback position
searchTracksGet tracks by searchingany keyword
getTrackGet track by IDid(string)

Changelog #

See CHANGELOG.md.

Contributing #

Feel free to contribute by opening issues and/or pull requests. Your feedback is very welcome!

License #

MIT License

Copyright (c) [2019] [NARU ENTREPRISE]

[0.0.2] - 2019-11-10 #

  • Fixing Bugs

[0.0.1] - 2019-10-20 #

  • Deezer Remote Playback for Android
  • Deezer Web API
  • Fixing Minor Bugs

example/lib/main.dart

import 'package:deezer_playback_example/deezerTrack.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'credentials.dart';
import 'package:deezer_playback/deezer_playback.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  bool _connectedToDeezer = false;
  bool _initDeezer = false;
  bool isPlaying = false;
  Dio dio = new Dio();

  @override
  void initState() {
    super.initState();
    initPlatformState();
    initConnector();
    connect();
    search("metallica");
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await DeezerPlayback.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  /// Initialize the Deezer playback sdk, by calling DeezerConnect
  Future<void> initConnector() async {
    try {
      await DeezerPlayback.iniatilizeDeezer(appId: Credentials.appId).then(
          (connected) {
        if (!mounted) return;
        // If the method call is successful, update the state to reflect this change
        setState(() {
          _initDeezer = connected;
        });
        print(_initDeezer);
      }, onError: (error) {
        // If the method call trows an error, print the error to see what went wrong
        print(error);
      });
    } on PlatformException {
      print('Failed to connect.');
    }
  }

  /// Initialize the Deezer playback sdk, by calling DeezerConnect
  Future<void> connect() async {
    try {
      await DeezerPlayback.connectToDeezer().then((authorised) {
        if (!mounted) return;
        // If the method call is successful, update the state to reflect this change
        setState(() {
          _connectedToDeezer = authorised;
        });
        print("we authorized deezer" + _connectedToDeezer.toString());
      }, onError: (error) {
        // If the method call trows an error, print the error to see what went wrong
        print(error);
      });
    } on PlatformException {
      print('Failed to connect.');
    }
  }

  //Search for Tracks using wWb API
  Future<List<DeezerTrack>> search(String search) async {
    try {
      List response = await DeezerPlayback.searchTracks(search);

      List<DeezerTrack> deezerTracks = [];
      response
          .forEach((json) => {deezerTracks.add(DeezerTrack.fromDeezer(json))});
      print(deezerTracks[0].title);

      return deezerTracks;
    } catch (e) {
      print(e);
      return null;
    }
  }

  Future<DeezerTrack> getTrack(String id) async {
    try {
      Object response = await DeezerPlayback.getTrack(id);

      DeezerTrack deezerTracks = DeezerTrack.fromDeezer(response);

      return deezerTracks;
    } catch (e) {
      print(e);
      return null;
    }
  }

  /// Play an song by Deezer track/album/playlist id
  Future<void> play(String id) async {
    try {
      await DeezerPlayback.play(id).then((success) {
        print(success);
        isPlaying = true;
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to play.');
    }
  }

  Future<void> pauseorResume() async {
    if (isPlaying) {
      pause();
    } else {
      resume();
    }
  }

  /// Pause the currently playing track
  Future<void> pause() async {
    try {
      await DeezerPlayback.pause().then((success) {
        print(success);
        isPlaying = false;
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to pause.');
    }
  }

  /// Resume the currently paused track
  Future<void> resume() async {
    try {
      await DeezerPlayback.resume().then((success) {
        print(success);
        isPlaying = true;
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to resume.');
    }
  }

  /// Seek to a defined time in a song
  Future<void> seekTo() async {
    try {
      await DeezerPlayback.seekTo(20000).then((success) {
        print(success);
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to play.');
    }
  }

  /// Seek to a a defined time relative to the current time
  Future<void> seekToRelativePosition() async {
    try {
      await DeezerPlayback.seekToRelativePosition(5000).then((success) {
        print(success);
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to play.');
    }
  }

  /// Gets the currently playing track's playback position
  Future<void> getPlaybackPosition() async {
    try {
      await DeezerPlayback.getPlaybackPosition().then((position) {
        print(
            "playback position -->\nmin:${DateTime.fromMillisecondsSinceEpoch(position).minute}\nseconds:${DateTime.fromMillisecondsSinceEpoch(position).second}");
        return position;
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to resume.');
    }
  }

  /// Play the previous song
  Future<void> skipPrevious() async {
    try {
      await DeezerPlayback.skipPrevious().then((success) {
        print(success);
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to play.');
    }
  }

  ///Play the next song
  Future<void> skipNext() async {
    try {
      await DeezerPlayback.skipNext().then((success) {
        print(success);
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to play next song.');
    }
  }

  /// Toggle repeat
  Future<void> toggleRepeat() async {
    try {
      await DeezerPlayback.toggleRepeat().then((success) {
        print(success);
      }, onError: (error) {
        print(error);
      });
    } on PlatformException {
      print('Failed to toggle repeat.');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Deezer PlayBack Example'),
        ),
        body: Center(
            child: FlatButton(
          color: Colors.blue,
          textColor: Colors.white,
          disabledColor: Colors.grey,
          disabledTextColor: Colors.black,
          padding: EdgeInsets.all(8.0),
          splashColor: Colors.blueAccent,
          onPressed: () {
            seekTo();
          },
          child: Text(
            "Play/Pause",
          ),
        )),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  deezer_playback: ^0.0.2

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:deezer_playback/deezer_playback.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
16
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
50
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.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:deezer_playback/deezer_playback.dart]

Package does not support Flutter platform macos

Because of import path [package:deezer_playback/deezer_playback.dart]

Package does not support Flutter platform web

Because of import path [package:deezer_playback/deezer_playback.dart]

Package does not support Flutter platform windows

Because of import path [package:deezer_playback/deezer_playback.dart]

Package not compatible with SDK dart

because of import path [deezer_playback]

Health suggestions

Format lib/deezer_playback.dart.

Run flutter format to format lib/deezer_playback.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (dio).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dio ^2.1.16 2.2.2 3.0.9
flutter 0.0.0
json_annotation ^3.0.0 3.0.1
Transitive dependencies
collection 1.14.12 1.14.13
cookie_jar 1.0.1
meta 1.1.8 1.2.0
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test