Skip to content

Commit

Permalink
fix(media): create will always return MediaObject even if plugin does…
Browse files Browse the repository at this point in the history
…nt exist
  • Loading branch information
ihadeed committed May 17, 2017
1 parent 975a65d commit ee4b61e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/@ionic-native/plugins/media/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { CordovaInstance, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core';
import { CordovaInstance, Plugin, checkAvailability, IonicNativePlugin } from '@ionic-native/core';

declare const Media: any;
// TODO for ionic native 4.x ... rename plugin class to Media and use Media.getPlugin() to retrieve the original media object
Expand Down Expand Up @@ -287,15 +287,19 @@ export class MediaPlugin extends IonicNativePlugin {
* @param [onError] {MediaErrorCallback} A callback function is be invoked if an error occurs.
* @return {MediaObject}
*/
@CordovaCheck({ sync: true })
create(src: string,
onStatusUpdate?: MediaStatusUpdateCallback,
onSuccess?: Function,
onError?: MediaErrorCallback): MediaObject {

let instance: any;

if (checkAvailability(MediaPlugin.getPluginRef(), null, MediaPlugin.getPluginName()) === true) {
// Creates a new media object
const instance = new Media(src, onSuccess, onError, onStatusUpdate);
return new MediaObject(instance);
instance = new Media(src, onSuccess, onError, onStatusUpdate);
}

return new MediaObject(instance);

}

Expand Down

0 comments on commit ee4b61e

Please sign in to comment.