Access your iTunes library (iOS only)
For RN older than 0.40.0, use the release 0.4.2+ of this library
If you have questions, ask them on Twitter @kadiks
In the command line, first you need to install react-native-itunes:
npm install react-native-itunes --save
- Add the key Privacy - Apple Music usage Description
NSAppleMusicUsageDescription
in your Info.plist with a description:$(PRODUCT_NAME) wants access to your Music library
react-native link react-native-itunes
You need rnpm
(npm install -g rnpm
)
rnpm link react-native-itunes
In XCode, in the project navigator, right click Libraries âžś Add Files to [your project's name] Go to node_modules âžś react-native-itunes and add the .xcodeproj file
In XCode, in the project navigator, select your project. Add the lib*.a from the react-native-itunes project to your project's Build Phases âžś Link Binary With Libraries Click .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React
and $(SRCROOT)/../../React
- mark both as recursive.
Run your project (Cmd+R)
Note: it works on the device (it even shows on the cloud Apple Music saved songs)
import iTunes from 'react-native-itunes';
iTunes.getTracks().then((tracks) => {
console.log(tracks);
});
Beware, check other examples for better performances
import iTunes from 'react-native-itunes';
iTunes.getPlaylists().then(playlists => {
console.log(playlists);
});
import iTunes from 'react-native-itunes';
iTunes.getTracks({
query: {
title: 'digital',
albumArtist: 'daft',
},
}).then((tracks) => {
iTunes.playTracks(tracks)
.then(res => {
console.log('is playing');
})
.catch(err => {
alert('err');
});
});
More examples
Note: it works on the device (it even shows on the cloud Apple Music saved songs)
Returns [String] of artists
Returns [TrackItem]
[DEPRECATED]
use getCurrentTrack()
instead
Returns TrackItem with additional properties: currentPlayTime and artwork
Returns [PlaylistItem]
- fields: Array
- name
- tracks
- playCount
- query: Object
- name
Returns [TrackItem]
- fields: Array https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMediaItem_ClassReference/
- query: Object
- title
- albumArtist
- albumTitle
- artist
- genre
- playlistName
- type: String
- default to
''
and will return songs audiobooks
will return the list of audiobookspodcasts
will return the list of podcasts
- default to
- name
- playCount
- tracks: [TrackItem]
- albumArtist
- albumTitle
- duration (in seconds)
- genre
- playCount
- title
-
The Apple documentation on the MPMediaItem used: https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPMediaItem_ClassReference/
- If you need more info, check out those properties list and do not hesitate doing a pull request (PR) with your addition
- Play list of searched items
playTracks()
- Get current playing track
getCurrentTrack()
- Play next item in playlist
next()
- Play previous item in playlist
previous()
Thanks to Haggai Shapira
- Get the current play time
getCurrentPlayTime()
- Seek to functionality
seekTo()
Thanks to kurokky
- Get all albums
getAlbums()
- Get all artists
getArtists()
- Get audiobooks and podcasts
- Field validation and conversion
- Get playlists
- Access artwork as base64
- Play track from TrackItem.title & TrackItem.albumTitle
- Play/Pause
- Query tracks
- Filter tracks
- Get specific fields
- Search all tracks
- Add tests
- Create a query builder function to be called from all public methods
- Refactor #getTracks to always return TrackItem.title & TrackItem.albumTitle
- Remove default
artwork
property ingetAlbums()
to avoid performances issues - Change
getArtists()
to return [TrackItem] and not [String] - Add same filtering capabilities from
getTracks()
togetAlbums()
&getArtists()
Remove playable capabilities all together (now with iOS11, it needs a new authorization process)- Change all code and examples to ES6
- Change all code and examples to ES7 (async/await)
- Get playlist
- Query tracks from Apple Music #19
- Play a searched item
- play()/pause()
- Play a list of searched items
- Play next item in playlist
- Play previous item in playlist
- Object [params.query={}]
- Object [params.fields={}]
For some reasons some tracks are not playing while they can be searched. If you have a clue why, please share.
Some playlist tracks cannot be played. Maybe those which are not cached. Might be related to first bug, but the first bug does not through a warning Investigating to flag them as unplayable before getting an error...
Persistent IDs are uint64_t (unsigned long long)
, a basic conversion to int turn them into negative number.
Malone Hedges for the getPlaylists(). I discovered that some Apple Music songs are only available via playlists Gracias a Indesign Colombia for this PR that fixes a lot of obvious and preventable mistakes