add success, error, status handlers

fixes #186
This commit is contained in:
Gaven Henry 2016-06-03 15:09:55 +08:00
parent a250bd3e81
commit 5df447a02f

View File

@ -1,4 +1,5 @@
import {CordovaInstance, Plugin} from './plugin'; import {CordovaInstance, Plugin} from './plugin';
import {Observable} from 'rxjs/Rx';
declare var Media: any; declare var Media: any;
/** /**
* @name MediaPlugin * @name MediaPlugin
@ -14,6 +15,13 @@ declare var Media: any;
* // Playing a file * // Playing a file
* var file = new MediaPlugin("path/to/file.mp3"); * var file = new MediaPlugin("path/to/file.mp3");
* *
* // Catch the Success & Error Output
* file.init.then(() => {
* console.log("Playback Finished");
* }, (err) => {
* console.log("somthing went wrong! error code: "+err.code+" message: "+err.message);
* });
*
* // play the file * // play the file
* file.play(); * file.play();
* *
@ -52,6 +60,8 @@ export class MediaPlugin {
// Properties // Properties
private _objectInstance: any; private _objectInstance: any;
status: Observable<any>;
init: Promise<any>;
// Methods // Methods
/** /**
@ -59,8 +69,10 @@ export class MediaPlugin {
* @param src {string} A URI containing the audio content. * @param src {string} A URI containing the audio content.
*/ */
constructor (src: string) { constructor (src: string) {
// TODO handle success, error, and status let res, rej, next;
this._objectInstance = new Media(src); this.init = new Promise<any>((resolve, reject) => {res = resolve; rej = reject;});
this.status = new Observable((observer) => {next = observer.next;});
this._objectInstance = new Media(src, res, rej, next);
} }
/** /**