1.0.2 • Published 3 years ago
capacitor-music-control v1.0.2
This plugin is forked from a fork of the original Cordova plugin that can be found here: https://github.com/ingageco/capacitor-music-controls-plugin
Observations
- This currently only works on Android
- Custom cover images are not implemented yet
- There's many bugs for sure
Installation
yarn add capacitor-music-control
Sync native files to capacitor:
npx cap sync
Configuration
If you don't want the notifications you can add this to your capacitor config file.
Default is true
[...]
"plugins": {
"MusicControl": {
showNotification: false
}
}
[...]
Using your own icon
The notification will try to use the resource named cmc_small_icon located on the app project. If it's not there, the play icon will be used
Usage
import { MusicControl } from 'capacitor-music-controls';
Available methods
// creates the media player and starts loading the music file
MusicControl.create({
track: "cool music",
url: "https://random.site/music.mp3",
album: "album name",
artist: "artist name"
});
// toggles play/pause, state is handled by the plugin
MusicControl.togglePlayPause();
// stops the whole thing
MusicControl.destroy();
Events
import { MusicControlEvents } from "capacitor-music-controls";
// isPlaying
MusicControl.addListener(
MusicControlEvents.IS_PLAYING,
(data: { isPlaying: boolean } ) => {
// triggered whenever the music is played or stopped
}
);
// songFinished
MusicControl.addListener(
MusicControlEvents.FINISHED,
(data: { isPlaying: boolean } ) => {
// triggered whenever the music ends
}
);
// mediaActions
MusicControl.addListener(
MusicControlEvents.NOTIFICATION_ACTIONS,
(data: { action: 'play' | 'pause' | 'previous' | 'next' | 'destroy' } ) => {
// triggered when the user interacts with the notification
}
);
// mediaSessionActions
MusicControl.addListener(
"mediaSessionActions",
(data: { action: 'play' | 'pause' | 'previous' | 'next' } ) => {
// triggered trough the media session, currently not implemented
}
);
Credits
Original plugin by ingageco
Original cordova plugin by homerours
Documentation shamelessly copied from capacitor-community
2.1.0-beta.1
3 years ago
2.1.0-beta.0
4 years ago
2.0.2-beta.0
4 years ago
2.0.1
4 years ago
1.0.2
5 years ago