This plugin is already obsolete. They say that android 4.X already incorporates codecs for .aac+
Besides, it has 32-bit libraries that I never recompiled.
Este plugin ya está obsoleto. Dicen que android 4.X ya incorpora codecs para .aac+
Aparte tiene librerías en 32 bits que nunca recompilé.
This plugin provides the ability to play back audio streaming on a device. Support AAC, AAC+ and MP3 format.
NOTE: The current implementation does not adhere to a W3C specification for media capture, and is provided for convenience only. A future implementation will adhere to the latest W3C specification and may deprecate the current APIs.
This plugin defines a global Mediaac
Constructor.
Although in the global scope, it is not available until after the deviceready
event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(Mediaac);
}
cordova plugin add https://github.com/AlexisCaffa/cordova-plugin-mediaac.git
- Android (tested)
Without aac decoders:
- iOS
- Windows
- Browser
var media = new Mediaac(src, mediaSuccess, [mediaError], [mediaStatus]);
-
src: A URI containing the audio content. (DOMString)
-
mediaSuccess: (Optional) The callback that executes after a
Mediaac
object has completed the current play, record, or stop action. (Function) -
mediaError: (Optional) The callback that executes if an error occurs. (Function)
-
mediaStatus: (Optional) The callback that executes to indicate status changes. (Function)
NOTE: cdvfile
path is supported as src
parameter:
var my_media = new Mediaac('cdvfile://localhost/temporary/recording.mp3', ...);
The following constants are reported as the only parameter to the
mediaStatus
callback:
Mediaac.MEDIA_NONE
= 0;Mediaac.MEDIA_STARTING
= 1;Mediaac.MEDIA_RUNNING
= 2;Mediaac.MEDIA_PAUSED
= 3;Mediaac.MEDIA_STOPPED
= 4;
-
media.play
: Start or resume playing an audio file. -
media.pause
: Pause playback of an audio file. -
media.release
: Releases the underlying operating system's audio resources. -
media.stop
: Stop playing an audio file.
Pauses playing an audio file.
media.pause();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Mediaac(url,
// success callback
function () { console.log("playAudio():Audio Success"); },
// error callback
function (err) { console.log("playAudio():Audio Error: " + err); }
);
// Play audio
my_media.play();
// Pause after 10 seconds
setTimeout(function () {
media.pause();
}, 10000);
}
Starts or resumes playing an audio file.
media.play();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Mediaac(url,
// success callback
function () {
console.log("playAudio():Audio Success");
},
// error callback
function (err) {
console.log("playAudio():Audio Error: " + err);
}
);
// Play audio
my_media.play();
}
-
numberOfLoops: Pass this option to the
play
method to specify the number of times you want the media file to play, e.g.:var myMediaac = new Mediaac("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3") myMediaac.play({ numberOfLoops: 2 })
-
playAudioWhenScreenIsLocked: Pass in this option to the
play
method to specify whether you want to allow playback when the screen is locked. If set totrue
(the default value), the state of the hardware mute button is ignored, e.g.:var myMediaac = new Mediaac("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3") myMediaac.play({ playAudioWhenScreenIsLocked : false }) myMedia.setVolume('1.0');
Note: To allow playback with the screen locked or background audio you have to add
audio
toUIBackgroundModes
in theinfo.plist
file. See Apple documentation. Also note that the audio has to be started before going to background.
-
order of file search: When only a file name or simple path is provided, iOS searches in the
www
directory for the file, then in the application'sdocuments/tmp
directory:var myMediaac = new Mediaac("audio/beer.mp3") myMediaac.play() // first looks for file in www/audio/beer.mp3 then in <application>/documents/tmp/audio/beer.mp3
Releases the underlying operating system's audio resources.
This is particularly important for Android, since there are a finite amount of
OpenCore instances for media playback. Applications should call the release
function for any Mediaac
resource that is no longer needed.
media.release();
// Audio player
//
var my_media = new Mediaac(src, onSuccess, onError);
my_media.play();
my_media.stop();
my_media.release();
Stops playing an audio file.
media.stop();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Mediaac(url,
// success callback
function() {
console.log("playAudio():Audio Success");
},
// error callback
function(err) {
console.log("playAudio():Audio Error: "+err);
}
);
// Play audio
my_media.play();
// Pause after 10 seconds
setTimeout(function() {
my_media.stop();
}, 10000);
}
A MediaacError
object is returned to the mediaError
callback
function when an error occurs.
-
code: One of the predefined error codes listed below.
-
message: An error message describing the details of the error.
MediaacError.MEDIA_ERR_ABORTED
= 1MediaacError.MEDIA_ERR_NETWORK
= 2MediaacError.MEDIA_ERR_DECODE
= 3MediaacError.MEDIA_ERR_NONE_SUPPORTED
= 4