Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #7, more stability of iOS version and readme update #10

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 120 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This plugin supports PhoneGap/Cordova apps running on both iOS and Android.

This plugin is meant to work with Cordova 3.5.0+ and PlayerHater (Android)/PRXPlayer (iOS).

PlayerHater references:
https://github.com/PRX/PlayerHater
https://github.com/PRX/PRXPlayer
PlayerHater references:
https://github.com/PRX/PlayerHater
https://github.com/PRX/PRXPlayer

## Installation

Expand All @@ -24,118 +24,123 @@ https://github.com/PRX/PRXPlayer

cordova local plugin add https://github.com/wnyc/cordova-plugin-playerhater.git

3. For android you should change all packages with suffix `.R` and `.BuildConfig`, watch my commit here

https://github.com/pouriaMaleki/cordova-plugin-playerhater/commit/c33862e3b078e6c4dff5b344308c06dab73bd798


## Usage

// all responses from the audio player are channeled through successCallback and errorCallback

// initialize the audio player - call after 'deviceready' event is fired
window.audioplayer.configure( successCallback, failureCallback);

// play a stream
window.audioplayer.playstream( successCallback,
failureCallback,
// stream urls to play on android/ios
{
android: "http://fm939.wnyc.org/wnycfm-app.aac",
ios: "http://fm939.wnyc.org/wnycfm-app.aac"}
},
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "Cuomo; NJ Candidates; and Candy Etiquette",
"artist": "The Brian Lehrer Show",
"image": {
"url": "https://media2.wnyc.org/i/300/300/l/80/1/governor_andrew_cuomo.jpg"
},
"imageThumbnail": {
"url": "https://media2.wnyc.org/i/60/60/l/80/1/governor_andrew_cuomo.jpg"
},
"name": "WNYC 93.9 FM",
"description": "News, Culture & Talk"
},
// javascript-specific json represenation of audio to be played, which will be passed back to
// javascript via successCallback when a stream is launched from a local notification (eg, the
// alarm clock
extra
);
// play a file - looks first for the file on device, in the app's Documents/audio directory, and if not found there, plays the url
window.audioplayer.playfile( successCallback,
failureCallback,
"http://www.podtrac.com/pts/redirect.mp3/audio.wnyc.org/moneytalking/moneytalking20141031pod.mp3",
10, // position in track 10=10 seconds
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "The Myth of the Self-Driving Car",
"artist": "Money Talking",
"image": {
"url": "https://media2.wnyc.org/i/1500/1208/c/80/1/google_self_driving_car_1.jpg"
},
"imageThumbnail": {}
},
extra // not currently used
);

// pause audio playback
window.audioplayer.pause( successCallback, failureCallback);

// pause audio playback
window.audioplayer.stop( successCallback, failureCallback);

// seek forward in on-demand track
window.audioplayer.seek( successCallback, failureCallback, 10 ); // 10=10 seconds (verify this...)

// seek backward in on-demand track
window.audioplayer.seek( successCallback, failureCallback, -10 ); // -10=-10 seconds
// seek to a specific position in on-demand track
window.audioplayer.seekto( successCallback, failureCallback, 20 ); // 20=20 seconds

// request state of audio player
window.audioplayer.getaudiostate( successCallback, failureCallback ); // state returned via successCallback

// set audio player meta data (for lock screen on iOS) -- call this to change metadata for currently playing audio
window.audioplayer.setaudioinfo( successCallback,
failureCallback,
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "Cuomo; NJ Candidates; and Candy Etiquette",
"artist": "The Brian Lehrer Show",
"image": {
"url": "https://media2.wnyc.org/i/300/300/l/80/1/governor_andrew_cuomo.jpg"
},
"imageThumbnail": {
"url": "https://media2.wnyc.org/i/60/60/l/80/1/governor_andrew_cuomo.jpg"
},
"name": "WNYC 93.9 FM",
"description": "News, Culture & Talk"
},
);

// callback method
var successCallback = function(result) {
console.log('audio callback ' + JSON.stringify(result));
if (result.type==='progress') {
console.log('progress/duration/available - ' + result.progress + '/' + result.duration + '/' + result.available); // available not currently supported
} else if (result.type==='state') {
console.log('status - ' + result.state + '/' + result.description);
} else if (result.type==='error') {
console.log('error - ' + result.reason);
} else if (result.type==='current') {
console.log('current audio ' + JSON.stringify(result.audio));
} else if (result.type==='next') {
console.log('skip to next audio track'); // typically fired by remote control/lock screen controls
} else if (result.type==='previous') {
// all responses from the audio player are channeled through successCallback and errorCallback

// initialize the audio player - call after 'deviceready' event is fired
window.audioplayer.configure( successCallback, failureCallback);

// play a stream
window.audioplayer.playstream( successCallback,
failureCallback,
// stream urls to play on android/ios
{
android: "http://fm939.wnyc.org/wnycfm-app.aac",
ios: "http://fm939.wnyc.org/wnycfm-app.aac"
},
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "Cuomo; NJ Candidates; and Candy Etiquette",
"artist": "The Brian Lehrer Show",
"image": {
"url": "https://media2.wnyc.org/i/300/300/l/80/1/governor_andrew_cuomo.jpg"
},
"imageThumbnail": {
"url": "https://media2.wnyc.org/i/60/60/l/80/1/governor_andrew_cuomo.jpg"
},
"name": "WNYC 93.9 FM",
"description": "News, Culture & Talk"
},
// javascript-specific json represenation of audio to be played, which will be passed back to
// javascript via successCallback when a stream is launched from a local notification (eg, the
// alarm clock
extra
);

// play a file - looks first for the file on device, in the app's Documents/audio directory, and if not found there, plays the url
window.audioplayer.playfile( successCallback,
failureCallback,
"http://www.podtrac.com/pts/redirect.mp3/audio.wnyc.org/moneytalking/moneytalking20141031pod.mp3",
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "The Myth of the Self-Driving Car",
"artist": "Money Talking",
"image": {
"url": "https://media2.wnyc.org/i/1500/1208/c/80/1/google_self_driving_car_1.jpg"
},
"imageThumbnail": {}
},
10, // position in track 10=10 seconds
extra // not currently used
);

// pause audio playback
window.audioplayer.pause( successCallback, failureCallback);

// pause audio playback
window.audioplayer.stop( successCallback, failureCallback);

// seek forward in on-demand track
window.audioplayer.seek( successCallback, failureCallback, 10 ); // 10=10 seconds (verify this...)

// seek backward in on-demand track
window.audioplayer.seek( successCallback, failureCallback, -10 ); // -10=-10 seconds

// seek to a specific position in on-demand track
window.audioplayer.seekto( successCallback, failureCallback, 20 ); // 20=20 seconds

// request state of audio player
window.audioplayer.getaudiostate( successCallback, failureCallback ); // state returned via successCallback

// set audio player meta data (for lock screen on iOS) -- call this to change metadata for currently playing audio
window.audioplayer.setaudioinfo( successCallback,
failureCallback,
// metadata used for iOS lock screen, Android 'Now Playing' notification
{
"title": "Cuomo; NJ Candidates; and Candy Etiquette",
"artist": "The Brian Lehrer Show",
"image": {
"url": "https://media2.wnyc.org/i/300/300/l/80/1/governor_andrew_cuomo.jpg"
},
"imageThumbnail": {
"url": "https://media2.wnyc.org/i/60/60/l/80/1/governor_andrew_cuomo.jpg"
},
"name": "WNYC 93.9 FM",
"description": "News, Culture & Talk"
},
);

// callback method
var successCallback = function(result) {
console.log('audio callback ' + JSON.stringify(result));
if (result.type==='progress') {
console.log('progress/duration/available - ' + result.progress + '/' + result.duration + '/' + result.available); // available not currently supported
} else if (result.type==='state') {
console.log('status - ' + result.state + '/' + result.description);
} else if (result.type==='error') {
console.log('error - ' + result.reason);
} else if (result.type==='current') {
console.log('current audio ' + JSON.stringify(result.audio));
} else if (result.type==='next') {
console.log('skip to next audio track'); // typically fired by remote control/lock screen controls
} else if (result.type==='previous') {
console.log('skip to previous track'); // typically fired by remote/control/lock screen controls
} else {
console.log('AudioCallback unhandled type (' + result.type + ')');
}
};

// audio states
MEDIA_NONE : 0
MEDIA_STARTING : 1
MEDIA_RUNNING : 2
MEDIA_PAUSED : 3
MEDIA_STOPPED : 4
MEDIA_LOADING : 5
MEDIA_COMPLETED : 6
} else {
console.log('AudioCallback unhandled type (' + result.type + ')');
}
};

// audio states
MEDIA_NONE : 0
MEDIA_STARTING : 1
MEDIA_RUNNING : 2
MEDIA_PAUSED : 3
MEDIA_STOPPED : 4
MEDIA_LOADING : 5
MEDIA_COMPLETED : 6
Loading