在锁屏和iOS和Android通知中心显示并管理媒体控制.
⚠️ NO LONGER MAINTAINED ⚠️
Please use react-native-track-player instead ✅
Display and manage media controls on lock screen and notification center for iOS and Android.
With Yarn:
yarn add react-native-music-control
or with NPM:
npm install react-native-music-control --save
pod install --project-directory=ios/android.permission.FOREGROUND_SERVICE permission to your AndroidManifest.xml:
launchMode of MainActivity to singleTask by adding in AndroidManifest.xml:
this.props.dispatch(playRemoteControl());
})
// on iOS this event will also be triggered by audio router change events
// happening when headphones are unplugged or a bluetooth audio peripheral disconnects from the device
MusicControl.on(Command.pause, ()=> {
this.props.dispatch(pauseRemoteControl());
})
MusicControl.on(Command.stop, ()=> {
this.props.dispatch(stopRemoteControl());
})
MusicControl.on(Command.nextTrack, ()=> {
this.props.dispatch(nextRemoteControl());
})
MusicControl.on(Command.previousTrack, ()=> {
this.props.dispatch(previousRemoteControl());
})
MusicControl.on(Command.changePlaybackPosition, (playbackPosition)=> {
this.props.dispatch(updateRemoteControl(playbackPosition));
})
MusicControl.on(Command.seekForward, ()=> {});
MusicControl.on(Command.seekBackward, ()=> {});
MusicControl.on(Command.seek, (pos)=> {}); // Android only (Seconds)
MusicControl.on(Command.volume, (volume)=> {}); // Android only (0 to maxVolume) - Only fired when remoteVolume is enabled
// Android Only (Boolean for RATING_HEART or RATING_THUMBS_UP_DOWN, Number for other types)
MusicControl.on(Command.setRating, (rating)=> {});
MusicControl.on(Command.togglePlayPause, ()=> {}); // iOS only
MusicControl.on(Command.enableLanguageOption, ()=> {}); // iOS only
MusicControl.on(Command.disableLanguageOption, ()=> {}); // iOS only
MusicControl.on(Command.skipForward, ()=> {});
MusicControl.on(Command.skipBackward, ()=> {});
// Android Only
MusicControl.on(Command.closeNotification, ()=> {
this.props.dispatch(onAudioEnd());
})
}
…
MusicControl.on(Command.play, () => { // A valid funcion must be present player.play() })
## Customization
It is possible to customize the icon used in the notification on Android. By default you can add a drawable resource to your package with the file name `music_control_icon` and the notification will use your custom icon. If you need to specify a custom icon name, or change your notification icon during runtime, the `setNowPlaying` function accepts a string for an Android drawable resource name in the `notificationIcon` prop. Keep in mind that just like with `music_control_icon` the resource specified has to be in the drawable package of your Android app.
```javascript
MusicControl.setCustomNotificationIcon('my_custom_icon')
Of course! We are waiting for your PR :)
暂无开放 Issues,或尚未同步最近议题。