Skip to content

React Native module to display Now playing Info on lockscreen and handle remove control events

License

Notifications You must be signed in to change notification settings

ghinwallc/react-native-music-control

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-music-control

React Native module to control remote controls on lockscreen + display Now playing Info on lockscreen (MPNowPlayingInfoCenter)

Play well with React Native Sound

Mix between :

Install

Add it to your project

npm install react-native-music-control --save

iOS

In XCode, right click Libraries. Click Add Files to "[Your project]". Navigate to node_modules/react-native-music-control. Add the file MusicControl.xcodeproj.

In the Project Navigator, select your project. Click the build target. Click Build Phases. Expand Link Binary With Libraries. Click the plus button and add libMusicControl.a under Workspace.

Android

app/build.gradle

 compile project(':react-native-music-control')

MainActivity.java

import com.tanguyantoine.react.MusicControlPackage;

settings.gradle

include ':react-native-music-control'

project(':react-native-music-control').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-music-control/android')

Use

import MusicControl from 'react-native-music-control';

Now Playing

NB: You should call this method after a sound is playing

MusicControl.setNowPlaying({
  title: 'Billie Jean',
  artwork: 'http://lorempixel.com/400/400',
  ...
})

Reset now playing

MusicControl.resetNowPlaying()

Enable/disable controls on lockscreen

MusicControl.enableControl('nextTrack', true)
MusicControl.enableControl('previousTrack', false)

skipBackward and skipForward controls on iOS accept additional configuration options with interval key:

MusicControl.enableControl('skipBackward', true, {interval: 15}))
MusicControl.enableControl('skipForward', true, {interval: 30}))

Register to events

MusicControl.on('play', ()=> {
  console.log("Play");
})

MusicControl.on('nextTrack', ()=> {
  console.log("nextTrack");
})

MusicControl.on('previousTrack', ()=> {
  console.log("previousTrack");
})

MusicControl.on('pause', ()=> {
  console.log("pause");
})

TODOS

  • Android support
  • Test
  • Publish package
  • rnpm configuration
  • Android : Handle remote events
  • Android : Display cover artwork

Contributing

Of coursssssseeeeee. I'm waiting your PR :)

About

React Native module to display Now playing Info on lockscreen and handle remove control events

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 45.8%
  • Java 44.8%
  • JavaScript 9.4%