디바이스의 오디오 파일을 재생 또는 녹음 할 수 있는
API
<plugin name="Media" value="org.apache.cordova.AudioHandler" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<feature name="Media">
<param name="ios-package" value="CDVSound"/>
</feature>
media.getCurrentPosition(mediaSuccess, [mediaError]);
// Audio player
//
var my_media = new Media(src, onSuccess, onError);
// Update media position every second
var mediaTimer = setInterval(function() {
// get media position
my_media.getCurrentPosition(
// success callback
function(position) {
if (position > -1) {
console.log((position) + " sec");
}
},
// error callback
function(e) {
console.log("Error getting pos=" + e);
}
);
}, 1000);
media.getDuration();
// Audio player
//
var my_media = new Media(src, onSuccess, onError);
// Get duration
var counter = 0;
var timerDur = setInterval(function() {
counter = counter + 100;
if (counter > 2000) {
clearInterval(timerDur);
}
var dur = my_media.getDuration();
if (dur > 0) {
clearInterval(timerDur);
document.getElementById('audio_duration').innerHTML = (dur) + " sec";
}
}, 100);
media.pause();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Media(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);
}
media.play();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Media(url,
// success callback
function() {
console.log("playAudio():Audio Success");
},
// error callback
function(err) {
console.log("playAudio():Audio Error: "+err);
});
// Play audio
my_media.play();
}
운영체제(
OS) 혹은 메모리 내의 Media 객체에 등록된 오디오 파일을 해제한다
media.release();
// Audio player
//
var my_media = new Media(src, onSuccess, onError);
my_media.play();
my_media.stop();
my_media.release();
media.seekTo(milliseconds);
// Audio player
//
var my_media = new Media(src, onSuccess, onError);
my_media.play();
// SeekTo to 10 seconds after 5 seconds
setTimeout(function() {
my_media.seekTo(10000);
}, 5000);
media.startRecord();
// Record audio
//
function recordAudio() {
var src = "myrecording.mp3";
var mediaRec = new Media(src,
// success callback
function() {
console.log("recordAudio():Audio Success");
},
// error callback
function(err) {
console.log("recordAudio():Audio Error: "+ err.code);
});
// Record audio
mediaRec.startRecord();
}
media.stop();
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Media(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);
}
media.stopRecord();
// Record audio
//
function recordAudio() {
var src = "myrecording.mp3";
var mediaRec = new Media(src,
// success callback
function() {
console.log("recordAudio():Audio Success");
},
// error callback
function(err) {
console.log("recordAudio():Audio Error: "+ err.code);
});
// Record audio
mediaRec.startRecord();
// Stop recording after 10 seconds
setTimeout(function() {
mediaRec.stopRecord();
}, 10000);
}
function(error) {
// Handle the error
}
유형 |
MediaError.MEDIA_ERR_ABORTED |
MediaError.MEDIA_ERR_NETWORK |
MediaError.MEDIA_ERR_DECODE |
MediaError.MEDIA_ERR_NONE_SUPPORTED |