captureOptions对象 - 属性
varcaptureOptions = {duration: 5, limit: 3};
• duration:时⻓长
• limit:采集次数限制
• mode:模式
不同采集类型的可⽤用选项
Capture选项
Capture类型 Duration Limit Mode
Audio X X X
Image X X
Video X X X
创建⼀一个联系⼈人
• 返回⼀一个新的Contact对象
function addContact(){
alert("Adding " + contactInfo.FullName + " to contacts application");
var contact = navigator.contacts.create();
contact.displayName = contactInfo.FullName;
contact.nickname = contactInfo.FullName;
var tmpName = new ContactName();
tmpName.givenName = contactInfo.FirstName;
tmpName.familyName = contactInfo.LastName;
tmpName.formatted = contactInfo.FullName;
contact.name = tmpName;
var phoneNums = [2];
phoneNums[0] = new ContactField('work', contactInfo.OfficePhone, false);
phoneNums[1] = new ContactField('mobile', contactInfo.MobilePhone, true);
contact.phoneNumbers = phoneNums;
var emailAddresses = [1];
emailAddresses[0] = new ContactField('home', contactInfo.EmailAddress, true);
contact.emails = emailAddresses;
// 保存到设备
contact.save(onContactSaveSuccess, onContactSaveError);
}
88.
Contact对象
• id: A globally unique identifier. (DOMString)
• displayName: The name of this Contact, suitable for display to end-users.
(DOMString)
• name: An object containing all components of a persons name. (ContactName)
• nickname: A casual name to address the contact by. (DOMString)
• phoneNumbers: An array of all the contact's phone numbers. (ContactField[])
• emails: An array of all the contact's email addresses. (ContactField[])
• addresses: An array of all the contact's addresses. (ContactAddress[])
• ims: An array of all the contact's IM addresses. (ContactField[])
• organizations: An array of all the contact's organizations. (ContactOrganization[])
• birthday: The birthday of the contact. (Date)
• note: A note about the contact. (DOMString)
• photos: An array of the contact's photos. (ContactField[])
• categories: An array of all the contacts user defined categories. (ContactField[])
• urls: An array of web pages associated to the contact. (ContactField[])
89.
成功和失败的回调函数
function onContactSaveSuccess() {
alert(contactInfo.FullName + " 已经成功保存到设备联系⼈人数据库。");
}
function onContactSaveError(e) {
var msgText;
switch(e.code) {
case ContactError.UNKNOWN_ERROR:
msgText = "An Unknown Error was reported while saving the contact.";
break;
case ContactError.INVALID_ARGUMENT_ERROR:
msgText = "An invalid argument was used with the Contact API.";
break;
case ContactError.TIMEOUT_ERROR:
msgText = "Timeout Error.";
break;
case ContactError.PENDING_OPERATION_ERROR:
msgText = "Pending Operation Error.";
break;
case ContactError.IO_ERROR:
msgText = "IO Error.";
break;
case ContactError.NOT_SUPPORTED_ERROR:
msgText = "Not Supported Error.";
break;
case ContactError.PERMISSION_DENIED_ERROR:
msgText = "Permission Denied Error.";
创建⼀一个Media对象
var media =new Media(mediaFileURI, onMediaSuccess,
[mediaError], [mediaStatus];
注意:这⾥里的onMediaSuccess不会在new Media完成后执⾏行,⽽而是会在
每次播放或者录⾳音完成后调⽤用。
new Media完成后,可以对media判断时⻓长或者读设当前位置,但是这些
操作都不会得到任何值,除⾮非已经开始播放。
// var fileName = "http://192.168.1.103/~tom/dan.mp3";
var fileName = "/android_asset/www/eye.mp3";
theMedia = new Media(fileName, onMediaSuccess, onMediaError,
onMediaStatus);
138.
File URI
• ⽂文件既可以是本地⽂文件系统⽂文件,
•也可以是located在⽂文件服务器的⽂文件;
• 或者是项⺫⽬目中的⽂文件。
var fileName = "/android_asset/www/eye.mp3";
var fileName = "http://192.168.1.103/~tom/dan.mp3";
Current Position
返回声⾳音⽂文件内的当前位置
media.getCurrentPosition(mediaSuccess, [mediaError]);
参数
mediaSuccess:带着以秒为单位的当前位置进⾏行回调。
mediaError:可选,出错时调⽤用。 需要设置⼀一个定时器来获取当前位置
说明:media.getCurrentPosition函数是⼀一个返回Media对象底层声⾳音⽂文件的当前位置的异
步函数。同时更新Media对象的_position参数。
function updateUI() {
console.log("updateUI");
theMedia.getCurrentPosition(onGetPosition, onMediaError);
}
function onGetPosition(filePos) {
console.log("onGetPosition");
//We won't have any information about the file until it's
// actually played. Update the counter on the page
$('#pos').html('时间: ' + Math.floor(filePos) + ' , 共: ' +
theMedia.getDuration() + ' seconds');
}