Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(music-controls): add music controls plugin support #494

Merged
merged 1 commit into from
Aug 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { NativeStorage } from './plugins/nativestorage';
import { Market } from './plugins/market';
import { MediaPlugin } from './plugins/media';
import { Mixpanel } from './plugins/mixpanel';
import { MusicControls } from './plugins/music-controls';
import { Network } from './plugins/network';
import { NFC } from './plugins/nfc';
import { OneSignal } from './plugins/onesignal';
Expand Down Expand Up @@ -181,6 +182,7 @@ InAppPurchase,
Insomnia,
Instagram,
Keyboard,
MusicControls,
NativeAudio,
NativeStorage,
Network,
Expand Down Expand Up @@ -271,6 +273,7 @@ window['IonicNative'] = {
MediaCapture: MediaCapture,
MediaPlugin: MediaPlugin,
Mixpanel: Mixpanel,
MusicControls: MusicControls,
NativeAudio: NativeAudio,
NativePageTransitions: NativePageTransitions,
NativeStorage: NativeStorage,
Expand Down
128 changes: 128 additions & 0 deletions src/plugins/music-controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import {Plugin, Cordova} from './plugin';
import {Observable} from 'rxjs/Observable';
/**
* @name MusicControls
* @description
* 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).
*
* @usage
* ```
* import {MusicControls} from 'ionic-native';
*
* MusicControls.create({
* track : 'Time is Running Out', // optional, default : ''
* artist : 'Muse', // optional, default : ''
* cover : 'albums/absolution.jpg', // optional, default : nothing
* // cover can be a local path (use fullpath 'file:///storage/emulated/...', or only 'my_image.jpg' if my_image.jpg is in the www folder of your app)
* // or a remote url ('http://...', 'https://...', 'ftp://...')
* isPlaying : true, // optional, default : true
* dismissable : true, // optional, default : false
*
* // hide previous/next/close buttons:
* hasPrev : false, // show previous button, optional, default: true
* hasNext : false, // show next button, optional, default: true
* hasClose : true, // show close button, optional, default: false
*
* // Android only, optional
* // text displayed in the status bar when the notification (and the ticker) are updated
* ticker : 'Now playing "Time is Running Out"'
* });
*
* MusicControls.subscribe().subscribe(action => {
*
* switch(action) {
* case 'music-controls-next':
* // Do something
* break;
* case 'music-controls-previous':
* // Do something
* break;
* case 'music-controls-pause':
* // Do something
* break;
* case 'music-controls-play':
* // Do something
* break;
* case 'music-controls-destroy':
* // Do something
* break;
*
* // Headset events (Android only)
* case 'music-controls-media-button' :
* // Do something
* break;
* case 'music-controls-headset-unplugged':
* // Do something
* break;
* case 'music-controls-headset-plugged':
* // Do something
* break;
* default:
* break;
* }
*
* });
*
* MusicControls.listen(); // activates the observable above
*
* MusicControls.updateIsPlaying(true);
*
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-music-controls',
pluginRef: 'MusicControls',
repo: 'https://github.com/homerours/cordova-music-controls-plugin'
})
export class MusicControls {
/**
* Create the media controls
* @param options {MusicControlsOptions}
* @returns {Promise<any>}
*/
@Cordova()
static create(options: MusicControlsOptions): Promise<any> {return; }

/**
* Destroy the media controller
* @returns {Promise<any>}
*/
@Cordova()
static destroy(): Promise<any> {return; }

/**
* Subscribe to the events of the media controller
* @returns {Observable<any>}
*/
@Cordova({
observable: true
})
static subscribe(): Observable<any> {return; }

/**
* Start listening for events, this enables the Observable from the subscribe method
*/
@Cordova({sync: true})
static listen(): void {}

/**
* Toggle play/pause:
* @param isPlaying {boolean}
*/
@Cordova({sync: true})
static updateIsPlaying(isPlaying: boolean): void {}
}
export interface MusicControlsOptions {
track: string;
artist: string;
cover: string;
isPlaying: boolean;
dismissable: boolean;
hasPrev: boolean;
hasNext: boolean;
hasClose: boolean;
ticker: string;
}