playify 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 48

Playify #

Playify is a Flutter plugin for playing music and fetching music metadata. Currently supports only iOS. Still in development. Checkout the Development Log.

Requirements:

Usage #

import 'package:playify/playify.dart';

//Create an instance
Playify myplayer = Playify();

//Play from the latest queue.
Future<void> play() async {
	await myplayer.play();
}

//Fetch all songs from iOS's Apple Music.
Future<List<Artist>> getAllSongs() async {
	var artist = await myplayer.getAllSongs(sort: true);
	return artists;
}

//Fetch song information about the currently playing song in the queue.
Future<SongInfo> nowPlaying() async {
	var artist = await myplayer.nowPlaying();
	return artists;
}

//Set the queue using songIDs for iOS.
Future<void> setQueue(songs: List<String>, index: int) async {
	await myplayer.setQueue(songIDs: songs, startIndex: index);
}

//Skip to the next song in the queue.
Future<void> next() async {
	await myplayer.next();
}

//Skip to the previous song in the queue.
Future<void> previous() async {
	await myplayer.previous();
}

//Set the playback time of the song.
Future<void> setPlaybackTime(double time) async {
	await myplayer.setPlaybackTime(time);
}

//Set the shuffle mode.
Future<void> setShuffleMode(Shuffle mode) async {
	await myplayer.setShuffleMode(mode);
}

iOS #

  • For iOS, Playify uses iOS's MusicKit framework. This makes Playify available only on iOS >= 10.1. Make sure to specify the minimum version of the supported iOS version in your app from XCode.

  • Getting All Songs: For geting all songs from the Apple Music library of the iPhone, you can specify whether to sort the artists. The songs are sorted by their track number, and the albums are sorted alphabetically. The cover art of each album is fetched individually, and you can specify the size of the cover art. The larger the cover art, the more amount of RAM it consumes and longer it takes to fetch. The default value takes about 1-2 seconds with 800+ songs.

Screenshots #

Screenshot Screenshot Screenshot Screenshot

0.0.3 #

  • Added shuffle and repeat.
  • Added setting and getting playback time.
  • Added seeking forward and backward.

0.0.2 #

  • Minor code formatting changes
  • Added return values for non-iOS devices

0.0.1 #

  • Initial release.
  • Currently only iOS supported.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:playify/playify.dart';
import 'package:playify_example/artists.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Playify',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePage createState() => _MyHomePage();
}

class _MyHomePage extends State<MyHomePage> {
  bool fetchingAllSong = false;
  bool playing = false;
  SongInfo data;
  Shuffle shufflemode = Shuffle.off;
  Repeat repeatmode = Repeat.none;
  var myplayer = Playify();
  List<Artist> artists = [];
  double time = 0.0;

  updateInfo() async {
    SongInfo res = await myplayer.nowPlaying();
    setState(() {
      data = res;
    });
  }

  @override
  void initState() {
    super.initState();
    updateInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Playify'),
      ),
      body: SingleChildScrollView(
        child: Center(
          child: IgnorePointer(
            ignoring: fetchingAllSong,
            child: Column(
              children: <Widget>[
                if (data != null)
                  Container(
                    child: Column(
                      children: <Widget>[
                        if (data.album.coverArt != null)
                          Image(
                            image: data.album.coverArt.image,
                            height: MediaQuery.of(context).size.height * 0.3,
                          ),
                        Slider(
                          divisions: data.song.duration.toInt(),
                          value: time,
                          min: 0,
                          max: data.song.duration,
                          onChanged: (val) async {
                            print(val);
                            setState(() {
                              time = val;
                            });
                            await myplayer.setPlaybackTime(val);
                          },
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            IconButton(
                              icon: Icon(Icons.arrow_back_ios),
                              onPressed: () async {
                                await myplayer.previous();
                                await updateInfo();
                              },
                            ),
                            Column(
                              children: <Widget>[
                                Text(data.artist.name),
                                Text(data.album.title),
                                Text(data.song.title),
                                Text(data.song.trackNumber.toString() +
                                    "/" +
                                    data.album.albumTrackCount.toString()),
                              ],
                            ),
                            IconButton(
                              icon: Icon(Icons.arrow_forward_ios),
                              onPressed: () async {
                                await myplayer.next();
                                await updateInfo();
                              },
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                if (!playing)
                  IconButton(
                    icon: Icon(Icons.play_arrow),
                    onPressed: () async {
                      var res = await myplayer.play();
                      setState(() {
                        playing = true;
                      });
                    },
                  )
                else
                  IconButton(
                    icon: Icon(Icons.pause),
                    onPressed: () async {
                      var res = await myplayer.pause();
                      setState(() {
                        playing = false;
                      });
                    },
                  ),
                FlatButton(
                  child: Text("Get Now Playing Info"),
                  onPressed: () async {
                    await updateInfo();
                  },
                ),
                FlatButton(
                  child: Text("All Songs"),
                  onPressed: () async {
                    setState(() {
                      fetchingAllSong = true;
                    });
                    var res = await myplayer.getAllSongs(sort: true);
                    setState(() {
                      artists = res;
                      fetchingAllSong = false;
                    });
                  },
                ),
                FlatButton(
                  child: Text("Artists"),
                  onPressed: () async {
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => Artists(
                                  artists: artists,
                                )));
                  },
                ),
                FlatButton(
                  child: Text("Get Playback Time"),
                  onPressed: () async {
                    var res = await myplayer.getPlaybackTime();
                    print(res);
                  },
                ),
                FlatButton(
                  child: Text("Seek Forward"),
                  onPressed: () async {
                    var res = await myplayer.seekForward();
                  },
                ),
                FlatButton(
                  child: Text("Seek Backward"),
                  onPressed: () async {
                    var res = await myplayer.seekBackward();
                  },
                ),
                FlatButton(
                  child: Text("End Seek"),
                  onPressed: () async {
                    var res = await myplayer.endSeeking();
                  },
                ),
                DropdownButton<Shuffle>(
                  hint: Text("Shuffle"),
                  onChanged: (mode) async {
                    await myplayer.setShuffleMode(mode);
                    setState(() {
                      shufflemode = mode;
                    });
                  },
                  value: shufflemode,
                  items: [
                    DropdownMenuItem(
                      value: Shuffle.off,
                      child: Text("Off"),
                    ),
                    DropdownMenuItem(
                      value: Shuffle.songs,
                      child: Text("Songs"),
                    ),
                    DropdownMenuItem(
                      value: Shuffle.albums,
                      child: Text("Albums"),
                    )
                  ],
                ),
                DropdownButton<Repeat>(
                  hint: Text("Repeat"),
                  onChanged: (mode) async {
                    await myplayer.setRepeatMode(mode);
                    setState(() {
                      repeatmode = mode;
                    });
                  },
                  value: repeatmode,
                  items: [
                    DropdownMenuItem(
                      value: Repeat.none,
                      child: Text("None"),
                    ),
                    DropdownMenuItem(
                      value: Repeat.one,
                      child: Text("Songs"),
                    ),
                    DropdownMenuItem(
                      value: Repeat.all,
                      child: Text("Albums"),
                    )
                  ],
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  playify: ^0.0.3

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:playify/playify.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:playify/playify.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:playify/playify.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:playify/playify.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:playify/playify.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • playify that is a package requiring null.

Maintenance suggestions

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.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test