Cordova plugin to stream remote audio data.
This cordova plug-in provides the ability to queue remote urls and create playlists. To gauge a songs media penetration it's possible to track the amount of network calls from an apps instance.
- iOS (including iOS8)
The plugin can either be installed from git repository, from local file system through the Command-line Interface.
From master:
# ~~ from master branch ~~
cordova plugin add https://github.com/katzer/phonegap-plugin-mediaplayer.git
from a local folder:
# ~~ local folder ~~
cordova plugin add cordova-plugin-audioplayer --searchpath path
To remove the plug-in, run the following command:
cordova plugin rm cordova-plugin-audioplayer
- queue Tracks
- start playing the queue
- pause/resume playing the queue
- clear the queue
- fade in/out
- register callbacks on playback events
The plugin creates the object cordova.plugins.audioPlayer
with the following methods:
- audioPlayer.play
- audioPlayer.queue
- audioPlayer.pause
- audioPlayer.resume
- audioPlayer.stop
- audioPlayer.playNext
- audioPlayer.setup
- audioPlayer.fadeInVolume
- audioPlayer.fadeOutVolume
- audioPlayer.getCurrentTrack
The plugin and its methods are not available before the deviceready event has been fired.
document.addEventListener('deviceready', function () {
// cordova.plugins.audioPlayer is now available
}, false);
Initialize a new queue, append a song object to it and start palying.
var song = {
id: '22',
title: 'California Lullabye',
album: 'The Beautiful Machine',
artist: 'Josh Woodward',
file: 'https://www.joshwoodward.com/mp3/JoshWoodward-TheBeautifulMachine-01-CaliforniaLullabye.mp3',
cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}
var callbackFunc = function() {
console.log('Song started');
}
cordova.plugins.audioPlayer.play(song, callbackFunc);
Append one ore more song objects to the existing queue (Initialize a new one if there is none). It's possible to replace the existing playlist by setting the replace flag to true. If play is set to true the playback is started on appending the track.
var song1 = {
id: '22',
title: 'California Lullabye',
album: 'The Beautiful Machine',
artist: 'Josh Woodward',
file: 'https://www.joshwoodward.com/mp3/JoshWoodward-TheBeautifulMachine-01-CaliforniaLullabye.mp3',
cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}
var song2 = {
id: '11',
title: 'Let it in',
album: 'Ashes',
artist: 'Josh Woodward',
file: 'https://www.joshwoodward.com/mp3/Ashes/JoshWoodward-Ashes-01-LetItIn.mp3',
cover: 'https://upload.wikimedia.org/wikipedia/en/5/54/Public_image_ltd_album_cover.jpg'
}
var callbackFunc = function() {
console.log('Song started');
}
var failureCallback = function(reason) {
console.log('Error:' + reason);
}
var options = {
replace: false,
play: false,
};
cordova.plugins.audioPlayer.queue([song1, song2], options, callbackFunc, failureCallback);
Pause playback.
var callback = function() {
console.log('Song paused');
};
cordova.plugins.audioPlayer.pause(callback);
Resume playback after pause.
var callback = function() {
console.log('Playback resumed');
};
cordova.plugins.audioPlayer.resume(callback);
Stop playing and clears the actual queue.
var callback = function() {
console.log('Playback stopped');
};
cordova.plugins.audioPlayer.stop(callback);
Got to the next track.
var callback = function() {
console.log('Skiped track');
};
cordova.plugins.audioPlayer.playNext(callback);
Set a trackingUrl.
var url = 'www.an-example-url.com/this/one/is/invalid';
var successCallback = function() {
console.log('Url succesfully added');
};
var failureCallback = function() {
console.log('Some error occured');
};
cordova.plugins.audioPlayer.setup(url, successCallback, failureCallback);
Fade the volume out.
var callback = function() {
console.log('muted');
};
cordova.plugins.audioPlayer.fadeOutVolume(callback);
Fade in the volume.
var callback = function() {
console.log('faded in volume');
};
cordova.plugins.audioPlayer.fadeInVolume(callback);
Get information about the currently played track.
var callback = function(id) {
console.log('Song ' + id + 'is played.');
};
cordova.plugins.audioPlayer.getCurrentTrack(callback);
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This software is released under the Apache 2.0 License.
ยฉ 2013-2016 appPlant GmbH, All rights reserved