cordova-plugin-music-controls
Advanced tools
Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "cordova-plugin-music-controls", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Music controls for Cordova apps", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -20,7 +20,13 @@ # Cordova Music Controls Plugin | ||
MusicControls.create({ | ||
track : 'Time is Running Out', // optional, default: '' | ||
artist : 'Muse', // optional, default: '' | ||
cover : 'albums/absolution.jpg', // optional, default: nothing | ||
isPlaying : true, // optional, default: true | ||
track : 'Time is Running Out', // optional, default : '' | ||
artist : 'Muse', // optional, default : '' | ||
cover : 'albums/absolution.jpg', // optional, default : nothing | ||
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 | ||
@@ -53,2 +59,5 @@ // text displayed in the status bar when the notification (and the ticker) are updated | ||
break; | ||
case 'music-controls-destroy': | ||
// Do something | ||
break; | ||
@@ -55,0 +64,0 @@ // Headset events (Android only) |
@@ -1,21 +0,26 @@ | ||
var mc = Windows.Media.MediaControl; | ||
// Copyright © 2015 filfat Studios AB | ||
/* global Windows, cordova */ | ||
var mc; | ||
var onUpdate = function (event) { }; | ||
var onPlay = function () { | ||
onUpdate('music-controls-play'); | ||
}, | ||
onPause = function () { | ||
onUpdate('music-controls-pause'); | ||
}, | ||
onPlayPause = function () { | ||
if (mc.isPlaying) | ||
onPause(); | ||
else | ||
onPlay(); | ||
}, | ||
onNext = function () { | ||
onUpdate('music-controls-next'); | ||
}, | ||
onPrev = function () { | ||
onUpdate('music-controls-previous'); | ||
var onKey = function (event) { | ||
var Button = Windows.Media.SystemMediaTransportControlsButton; | ||
switch (event.button) { | ||
case Button.play: | ||
onUpdate('music-controls-play'); | ||
break; | ||
case Button.pause: | ||
onUpdate('music-controls-pause'); | ||
break; | ||
case Button.stop: | ||
onUpdate('music-controls-stop'); | ||
break; | ||
case Button.next: | ||
onUpdate('music-controls-next'); | ||
break; | ||
case Button.previous: | ||
onUpdate('music-controls-previous'); | ||
break; | ||
} | ||
}; | ||
@@ -26,27 +31,38 @@ | ||
var data = datas[0]; | ||
mc = Windows.Media.SystemMediaTransportControls.getForCurrentView(); | ||
//Handle events | ||
mc.addEventListener("playpausetogglepressed", onPlayPause, false); | ||
mc.addEventListener("playpressed", onPlay, false); | ||
mc.addEventListener("pausepressed", onPause, false); | ||
mc.addEventListener("previoustrackpressed", onPrev, false); | ||
mc.addEventListener("nexttrackpressed", onNext, false); | ||
mc.addEventListener("buttonpressed", onKey, false); | ||
//Set data | ||
mc.isEnabled = true; | ||
mc.isPlayEnabled = true; | ||
mc.isPauseEnabled = true; | ||
mc.isNextEnabled = true; | ||
mc.isStopEnabled = true; | ||
mc.isPreviousEnabled = true; | ||
mc.displayUpdater.type = Windows.Media.MediaPlaybackType.music; | ||
//Is Playing | ||
if (data.isPlaying) | ||
mc.playbackStatus = Windows.Media.MediaPlaybackStatus.playing; | ||
else | ||
mc.playbackStatus = Windows.Media.MediaPlaybackStatus.stopped; | ||
if (!/^(f|ht)tps?:\/\//i.test(data.cover)) { | ||
var cover = new Windows.Foundation.Uri("ms-appdata://" + data.cover); | ||
mc.albumArt = cover; | ||
mc.displayUpdater.thumbnail = cover; | ||
} else { | ||
//TODO: Store image locally | ||
} | ||
//Set data | ||
mc.artistName = data.artist; | ||
mc.isPlaying = data.isPlaying; | ||
mc.trackName = data.track; | ||
mc.displayUpdater.musicProperties.albumArtist = data.artist; | ||
mc.displayUpdater.musicProperties.albumTitle = (data.album === undefined ? ' ' : data.album); | ||
mc.displayUpdater.musicProperties.artist = data.artist; | ||
mc.displayUpdater.musicProperties.title = data.track; | ||
mc.displayUpdater.update(); | ||
}, | ||
destroy: function (successCallback, errorCallback, datas) { | ||
//Remove events | ||
mc.removeEventListener("playpausetogglepressed", onPlayPause); | ||
mc.removeEventListener("playpressed", onPlay); | ||
mc.removeEventListener("pausepressed", onPause); | ||
mc.displayUpdater.clearAll(); | ||
}, | ||
@@ -53,0 +69,0 @@ watch: function (_onUpdate, errorCallback, datas) { |
module.exports = { | ||
updateCallback : function(){}, | ||
create: function(data, successCallback, errorCallback) { | ||
if (data.artist === undefined){ | ||
data.artist = ''; | ||
} | ||
if (data.track === undefined){ | ||
data.track = ''; | ||
} | ||
if (data.cover === undefined){ | ||
data.cover = ''; | ||
} | ||
if (data.ticker === undefined){ | ||
data.ticker = ''; | ||
} | ||
if (data.isPlaying === undefined){ | ||
data.isPlaying = true; | ||
} | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'create', [data]); | ||
}, | ||
updateIsPlaying: function(isPlaying,successCallback,errorCallback){ | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'updateIsPlaying', [{isPlaying : isPlaying}]); | ||
}, | ||
destroy: function(successCallback,errorCallback){ | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'destroy', []); | ||
}, | ||
// Register callback | ||
subscribe: function(onUpdate){ | ||
module.exports.updateCallback = onUpdate; | ||
}, | ||
// Start listening for events | ||
listen : function(){ | ||
cordova.exec(module.exports.receiveCallbackFromNative, function(res){ }, 'MusicControls', 'watch', []); | ||
}, | ||
receiveCallbackFromNative : function(messageFromNative){ | ||
module.exports.updateCallback(messageFromNative); | ||
cordova.exec(module.exports.receiveCallbackFromNative, function(res){ }, 'MusicControls', 'watch', []); | ||
} | ||
updateCallback: function () {}, | ||
create: function (data, successCallback, errorCallback) { | ||
if (data.artist === undefined) { | ||
data.artist = ''; | ||
} | ||
if (data.track === undefined) { | ||
data.track = ''; | ||
} | ||
if (data.cover === undefined) { | ||
data.cover = ''; | ||
} | ||
if (data.ticker === undefined) { | ||
data.ticker = ''; | ||
} | ||
if (data.isPlaying === undefined) { | ||
data.isPlaying = true; | ||
} | ||
if (data.hasPrev === undefined) { | ||
data.hasPrev = true; | ||
} | ||
if (data.hasNext === undefined) { | ||
data.hasNext = true; | ||
} | ||
if (data.hasClose === undefined) { | ||
data.hasClose = false; | ||
} | ||
if (data.dismissable === undefined) { | ||
data.dismissable = false; | ||
} | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'create', [data]); | ||
}, | ||
updateIsPlaying: function (isPlaying, successCallback, errorCallback) { | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'updateIsPlaying', [{isPlaying: isPlaying}]); | ||
}, | ||
destroy: function (successCallback, errorCallback) { | ||
cordova.exec(successCallback, errorCallback, 'MusicControls', 'destroy', []); | ||
}, | ||
// Register callback | ||
subscribe: function (onUpdate) { | ||
module.exports.updateCallback = onUpdate; | ||
}, | ||
// Start listening for events | ||
listen: function () { | ||
cordova.exec(module.exports.receiveCallbackFromNative, function (res) { | ||
}, 'MusicControls', 'watch', []); | ||
}, | ||
receiveCallbackFromNative: function (messageFromNative) { | ||
module.exports.updateCallback(messageFromNative); | ||
cordova.exec(module.exports.receiveCallbackFromNative, function (res) { | ||
}, 'MusicControls', 'watch', []); | ||
} | ||
}; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26535
117
98