cordova-plugin-playlist
Advanced tools
Comparing version 0.5.2 to 0.5.5
@@ -96,2 +96,5 @@ /** | ||
// This returns a promsie that you can wait for if you want. | ||
this.AudioPlayer.initialize(); | ||
this.AudioPlayer.on('status', (data: OnStatusCallbackData | OnStatusErrorCallbackData) => { | ||
@@ -296,2 +299,3 @@ this.statusStream.next(data); | ||
} | ||
return this.AudioPlayer.ready(); | ||
}); | ||
@@ -298,0 +302,0 @@ } |
{ | ||
"name": "cordova-plugin-playlist", | ||
"description": "A Cordova plugin for Android and iOS with native support for audio playlists, background support, and lock screen controls", | ||
"version": "0.5.2", | ||
"version": "0.5.5", | ||
"homepage": "https://github.com/Rolamix/cordova-plugin-playlist#readme", | ||
@@ -55,3 +55,3 @@ "author": "Patrick <patrick@rolamix.com>", | ||
"cordova": ">=7.1.0", | ||
"cordova-android": ">=6.4.0", | ||
"cordova-android": ">=7.1.0", | ||
"cordova-ios": ">=4.3.0" | ||
@@ -58,0 +58,0 @@ } |
@@ -39,2 +39,4 @@ # cordova-plugin-playlist | ||
* If you are running this on iOS 9.3, this plugin requires a promise polyfill for the JS layer. | ||
## 2. Installation | ||
@@ -41,0 +43,0 @@ |
@@ -30,3 +30,3 @@ /* global cordova:false */ | ||
const exec = typeof cordova !== 'undefined' ? cordova.require('cordova/exec') : null; | ||
const channel = typeof cordova !== 'undefined' ? cordova.require('cordova/channel') : null; | ||
// const channel = typeof cordova !== 'undefined' ? cordova.require('cordova/channel') : null; | ||
const log = console; | ||
@@ -43,2 +43,8 @@ | ||
options: AudioPlayerOptions = { verbose: false, resetStreamOnPause: true }; | ||
private _inititialized: boolean = false; | ||
private _initPromise: Promise<boolean>; | ||
private _readyResolve: any;; | ||
private _readyReject: any; | ||
private _currentState: 'unknown' | 'ready' | 'error' | 'playing' | 'loading' | 'paused' | 'stopped' = 'unknown'; | ||
@@ -62,3 +68,3 @@ private _hasError: boolean = false; | ||
get isInitialized() { | ||
return this._currentState !== 'unknown'; | ||
return this._inititialized; | ||
} | ||
@@ -119,2 +125,6 @@ | ||
this.handlers = {}; | ||
this._initPromise = new Promise((resolve, reject) => { | ||
this._readyResolve = resolve; | ||
this._readyReject = reject; | ||
}); | ||
} | ||
@@ -127,2 +137,39 @@ | ||
/** | ||
* Returns a promise that resolves when the plugin is ready. | ||
*/ | ||
ready = () => { | ||
return this._initPromise; | ||
} | ||
initialize = () => { | ||
// Initialize the plugin to send and receive messages | ||
// channel.createSticky('onRmxAudioPlayerReady'); | ||
// channel.waitForInitialization('onRmxAudioPlayerReady'); | ||
const onNativeStatus = (msg: any) => { | ||
// better or worse, we got an answer back from native, so we resolve. | ||
this._inititialized = true; | ||
this._readyResolve(true); | ||
if (msg.action === 'status') { | ||
this.onStatus(msg.status.trackId, msg.status.msgType, msg.status.value); | ||
} else { | ||
console.warn('Unknown audio player onStatus message:', msg.action); | ||
} | ||
}; | ||
// channel.onCordovaReady.subscribe(() => { | ||
const error = (args: any) => { | ||
const message = 'CORDOVA RMXAUDIOPLAYER: Error storing message channel:'; | ||
console.warn(message, args); | ||
this._readyReject({ message, args }); | ||
}; | ||
exec(onNativeStatus, error, 'RmxAudioPlayer', 'initialize', []); | ||
// channel.initializationComplete('onRmxAudioPlayerReady'); | ||
// }); | ||
return this._initPromise; | ||
} | ||
/** | ||
* Sets the player options. This can be called at any time and is not required before playback can be initiated. | ||
@@ -337,3 +384,3 @@ */ | ||
*/ | ||
onStatus(trackId: string, type: RmxAudioStatusMessage, value: OnStatusCallbackUpdateData | OnStatusTrackChangedData | OnStatusErrorCallbackData) { | ||
protected onStatus(trackId: string, type: RmxAudioStatusMessage, value: OnStatusCallbackUpdateData | OnStatusTrackChangedData | OnStatusErrorCallbackData) { | ||
const status = { type, trackId, value }; | ||
@@ -466,23 +513,2 @@ if (this.options.verbose) { | ||
// Initialize the plugin to send and receive messages | ||
if (typeof cordova != 'undefined') { | ||
channel.createSticky('onRmxAudioPlayerReady'); | ||
channel.waitForInitialization('onRmxAudioPlayerReady'); | ||
function onNativeStatus(msg: any) { | ||
if (msg.action === 'status') { | ||
playerInstance.onStatus(msg.status.trackId, msg.status.msgType, msg.status.value); | ||
} else { | ||
throw new Error(`Unknown audio player action ${msg.action}`); | ||
} | ||
} | ||
channel.onCordovaReady.subscribe(() => { | ||
const error = (args: any) => console.warn('CORDOVA RMXAUDIOPLAYER: Error storing message channel:', args); | ||
exec(onNativeStatus, error, 'RmxAudioPlayer', 'storeMessageChannel', []); | ||
channel.initializationComplete('onRmxAudioPlayerReady'); | ||
}); | ||
} | ||
/*! | ||
@@ -489,0 +515,0 @@ * AudioPlayer Plugin instance. |
@@ -12,2 +12,6 @@ import { RmxAudioStatusMessage } from './Constants'; | ||
options: AudioPlayerOptions; | ||
private _inititialized; | ||
private _initPromise; | ||
private _readyResolve; | ||
private _readyReject; | ||
private _currentState; | ||
@@ -64,2 +68,7 @@ private _hasError; | ||
/** | ||
* Returns a promise that resolves when the plugin is ready. | ||
*/ | ||
ready: () => Promise<boolean>; | ||
initialize: () => Promise<boolean>; | ||
/** | ||
* Sets the player options. This can be called at any time and is not required before playback can be initiated. | ||
@@ -192,3 +201,3 @@ */ | ||
*/ | ||
onStatus(trackId: string, type: RmxAudioStatusMessage, value: OnStatusCallbackUpdateData | OnStatusTrackChangedData | OnStatusErrorCallbackData): void; | ||
protected onStatus(trackId: string, type: RmxAudioStatusMessage, value: OnStatusCallbackUpdateData | OnStatusTrackChangedData | OnStatusErrorCallbackData): void; | ||
/** | ||
@@ -195,0 +204,0 @@ * Subscribe to events raised by the plugin, e.g. on('status', (data) => { ... }), |
@@ -25,4 +25,4 @@ /** | ||
var exec = typeof cordova !== 'undefined' ? cordova.require('cordova/exec') : null; | ||
var channel = typeof cordova !== 'undefined' ? cordova.require('cordova/channel') : null; | ||
var exec = typeof cordova !== 'undefined' ? cordova.require('cordova/exec') : null; // const channel = typeof cordova !== 'undefined' ? cordova.require('cordova/channel') : null; | ||
var log = console; | ||
@@ -57,3 +57,3 @@ /** | ||
get: function get() { | ||
return this._currentState !== 'unknown'; | ||
return this._inititialized; | ||
} | ||
@@ -144,2 +144,26 @@ }, { | ||
}); | ||
Object.defineProperty(this, "_inititialized", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: false | ||
}); | ||
Object.defineProperty(this, "_initPromise", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "_readyResolve", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "_readyReject", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "_currentState", { | ||
@@ -169,2 +193,48 @@ configurable: true, | ||
}); | ||
Object.defineProperty(this, "ready", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
return _this._initPromise; | ||
} | ||
}); | ||
Object.defineProperty(this, "initialize", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
// Initialize the plugin to send and receive messages | ||
// channel.createSticky('onRmxAudioPlayerReady'); | ||
// channel.waitForInitialization('onRmxAudioPlayerReady'); | ||
var onNativeStatus = function onNativeStatus(msg) { | ||
// better or worse, we got an answer back from native, so we resolve. | ||
_this._inititialized = true; | ||
_this._readyResolve(true); | ||
if (msg.action === 'status') { | ||
_this.onStatus(msg.status.trackId, msg.status.msgType, msg.status.value); | ||
} else { | ||
console.warn('Unknown audio player onStatus message:', msg.action); | ||
} | ||
}; // channel.onCordovaReady.subscribe(() => { | ||
var error = function error(args) { | ||
var message = 'CORDOVA RMXAUDIOPLAYER: Error storing message channel:'; | ||
console.warn(message, args); | ||
_this._readyReject({ | ||
message, | ||
args | ||
}); | ||
}; | ||
exec(onNativeStatus, error, 'RmxAudioPlayer', 'initialize', []); // channel.initializationComplete('onRmxAudioPlayerReady'); | ||
// }); | ||
return _this._initPromise; | ||
} | ||
}); | ||
Object.defineProperty(this, "setOptions", { | ||
@@ -378,2 +448,6 @@ configurable: true, | ||
this.handlers = {}; | ||
this._initPromise = new Promise(function (resolve, reject) { | ||
_this._readyResolve = resolve; | ||
_this._readyReject = reject; | ||
}); | ||
} | ||
@@ -385,3 +459,3 @@ /** | ||
/** | ||
* Sets the player options. This can be called at any time and is not required before playback can be initiated. | ||
* Returns a promise that resolves when the plugin is ready. | ||
*/ | ||
@@ -571,24 +645,3 @@ | ||
exports.RmxAudioPlayer = RmxAudioPlayer; | ||
var playerInstance = new RmxAudioPlayer(); // Initialize the plugin to send and receive messages | ||
if (typeof cordova != 'undefined') { | ||
var onNativeStatus = function onNativeStatus(msg) { | ||
if (msg.action === 'status') { | ||
playerInstance.onStatus(msg.status.trackId, msg.status.msgType, msg.status.value); | ||
} else { | ||
throw new Error(`Unknown audio player action ${msg.action}`); | ||
} | ||
}; | ||
channel.createSticky('onRmxAudioPlayerReady'); | ||
channel.waitForInitialization('onRmxAudioPlayerReady'); | ||
channel.onCordovaReady.subscribe(function () { | ||
var error = function error(args) { | ||
return console.warn('CORDOVA RMXAUDIOPLAYER: Error storing message channel:', args); | ||
}; | ||
exec(onNativeStatus, error, 'RmxAudioPlayer', 'storeMessageChannel', []); | ||
channel.initializationComplete('onRmxAudioPlayerReady'); | ||
}); | ||
} | ||
var playerInstance = new RmxAudioPlayer(); | ||
/*! | ||
@@ -598,3 +651,2 @@ * AudioPlayer Plugin instance. | ||
var AudioPlayer = playerInstance; | ||
@@ -601,0 +653,0 @@ exports.AudioPlayer = AudioPlayer; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
688565
4662
118