Cordova Music Controls Plugin
Music controls for Cordova applications. Display a 'media' notification with play/pause, previous, next buttons, allowing the user to control the play. Handle also headset event (plug, unplug, headset button).
Supported platforms
Installation
cordova plugin add https://github.com/homerours/cordova-music-controls-plugin
Methods
- Create the media controls:
MusicControls.create({
track : 'Time is Running Out',
artist : 'Muse',
cover : 'albums/absolution.jpg',
isPlaying : true,
dismissable : true,
hasPrev : false,
hasNext : false,
hasClose : true,
album : 'Absolution',
duration : 60,
elapsed : 10,
hasSkipForward : true,
hasSkipBackward : true,
skipForwardInterval : 15,
skipBackwardInterval : 15,
hasScrubbing : false,
ticker : 'Now playing "Time is Running Out"',
playIcon: 'media_play',
pauseIcon: 'media_pause',
prevIcon: 'media_prev',
nextIcon: 'media_next',
closeIcon: 'media_close',
notificationIcon: 'notification'
}, onSuccess, onError);
- Destroy the media controller:
MusicControls.destroy(onSuccess, onError);
- Subscribe events to the media controller:
function events(action) {
const message = JSON.parse(action).message;
switch(message) {
case 'music-controls-next':
break;
case 'music-controls-previous':
break;
case 'music-controls-pause':
break;
case 'music-controls-play':
break;
case 'music-controls-destroy':
break;
case 'music-controls-toggle-play-pause' :
break;
case 'music-controls-seek-to':
const seekToInSeconds = JSON.parse(action).position;
MusicControls.updateElapsed({
elapsed: seekToInSeconds,
isPlaying: true
});
break;
case 'music-controls-media-button' :
break;
case 'music-controls-headset-unplugged':
break;
case 'music-controls-headset-plugged':
break;
default:
break;
}
}
MusicControls.subscribe(events);
MusicControls.listen();
MusicControls.updateIsPlaying(true);
MusicControls.updateDismissable(true);
- iOS Specific Events:
Allows you to listen for iOS events fired from the scrubber in control center.
MusicControls.updateElapsed({
elapsed: 208,
isPlaying: true
});
List of media button events
'music-controls-media-button'
'music-controls-media-button-next', 'music-controls-media-button-pause', 'music-controls-media-button-play',
'music-controls-media-button-play-pause', 'music-controls-media-button-previous', 'music-controls-media-button-stop',
'music-controls-media-button-fast-forward', 'music-controls-media-button-rewind', 'music-controls-media-button-skip-backward',
'music-controls-media-button-skip-forward', 'music-controls-media-button-step-backward', 'music-controls-media-button-step-forward',
'music-controls-media-button-meta-left', 'music-controls-media-button-meta-right', 'music-controls-media-button-music',
'music-controls-media-button-volume-up', 'music-controls-media-button-volume-down', 'music-controls-media-button-volume-mute',
'music-controls-media-button-headset-hook'
'music-controls-skip-forward', 'music-controls-skip-backward'
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request