Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Latest commit

 

History

History
170 lines (134 loc) · 2.88 KB

examples.md

File metadata and controls

170 lines (134 loc) · 2.88 KB

Get all tracks

import iTunes from 'react-native-itunes';

iTunes.getTracks().then((tracks) => {
  console.log(tracks);
});

Get all tracks and extract only genre and title

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  fields: ['title', 'genre'],
}).then((tracks) => {
  console.log(tracks);
});

Filter track by title and album artist

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  query: {
    title: 'digital',
    albumArtist: 'daft',
  },
}).then((tracks) => {
  console.log(tracks);
});

Get all podcasts

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  type: 'podcasts',
}).then((tracks) => {
  console.log(tracks);
});

Get all audiobooks

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  type: 'audiobooks',
}).then((tracks) => {
  console.log(tracks);
});

Play searched track

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  query: {
    title: 'digital',
    albumArtist: 'daft',
  },
}).then((tracks) => {
  iTunes.playTrack(tracks[0])
    .then(res => {
      console.log('is playing');
    })
    .catch(err => {
      alert('err');
    });
});

Show album cover

import iTunes from 'react-native-itunes';

iTunes.getTracks({
  fields: ['title', 'artwork'],
}).then((tracks) => {
  this.setState({
    track: tracks[0],
  });
});

...

render() {
  return <Image source={{uri: this.state.track.artwork }} style={{ width: 100, height: 100 }} />
}

Get all playlists

import iTunes from 'react-native-itunes';

iTunes.getPlaylists().then(playlists => {
  console.log(playlists);
});

Get all playlists names

import iTunes from 'react-native-itunes';

iTunes.getPlaylists({
  fields: ['name'], // more performant to filter by `fields`:name, and then `query`:name
}).then(playlists => {
  console.log(playlists);
});

Search playlists

import iTunes from 'react-native-itunes';

iTunes.getPlaylists({
  query: {
    name: 'recently',
  },
}).then(playlists => {
  console.log(playlists);
});

Get all artists

import iTunes from 'react-native-itunes';

iTunes.getArtists().then(artists => {
  console.log(artists); // ['Daft Punk', 'Pharell Williams', ...]
});

Get all albums

import iTunes from 'react-native-itunes';

iTunes.getAlbums().then(albums => {
  console.log(albums); // [TrackItem] with 3 properties: albumTitle, albumArtist and artwork
});

Get current track (with playing time and artwork)

import iTunes from 'react-native-itunes';

iTunes.getCurrentTrack().then(track => {
  console.log(track); // TrackItem with additional properties: artwork and currentPlayTime
});

Get current play time of the playing track

import iTunes from 'react-native-itunes';

iTunes.getCurrentPlayTime()
.then(time => console.log(time))
.catch(err => console.error('time read failure', err));