1.监听摇一摇
var shakeOn =false;
function deviceMotionHandler(eventData,callback) {
if(shakeOn === false){return}
var acceleration = eventData.accelerationIncludingGravity;
var curTime = new Date().getTime();
if ((curTime - last_update) > 100) {
var diffTime = curTime - last_update;
last_update = curTime;
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;
if (speed > SHAKE_THRESHOLD) {
if(new Date() - lTime > _timeLimit){
lTime = new Date();
callback();
};
}
last_x = x;
last_y = y;
last_z = z;
}
}
window.addEventListener('devicemotion', function(){
deviceMotionHandler(eventData,callback)
}, false);
2.微信分享
1.请求拿到配置微信appId等信息的对象 (如下)
//wx.config ({
//debug : false, // true:调试时候弹窗
//appId : $wx_account[0], // 微信appid
//timestamp : $wx_account[1], // 时间戳
//nonceStr : $wx_account[2], // 随机字符串
//signature : $wx_account[3], // 签名
//});
<script type="text/javascript">
var src = "http://xxx.com.cn/weixinJS.action?url="
+encodeURIComponent(location.href.split('#')[0]);
var left = unescape('%3c');
var right = unescape('%3E');
document.write(left + 'script src="' + src + '"' + right + left + '/script' + right);
</script>
function initWXShare() {
wx.onMenuShareAppMessage({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.imgUrl
}), wx.onMenuShareTimeline({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.imgUrl
}), wx.onMenuShareQQ({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.imgUrl
}), wx.onMenuShareWeibo({
title: shareData.title,
desc: shareData.desc,
link: shareData.link,
imgUrl: shareData.imgUrl
})
}
var shareData = {
imgUrl: "",
link: "",
title: "",
desc: ""
};
//WXConfig是上方js请求回来的config对象
//添加配置需要使用的API :分享到朋友圈,好友,qq,微博。。。
WXConfig.jsApiList = ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo"],
wx.config(WXConfig), //微信config配置文件
wx.ready(initWXShare); //初始化添加分享信息
3.自动播放音频(否则只有触摸屏幕才会开始播放)
wx.ready(function () {
wx.getNetworkType({
success: function (res) {
video.play()
}
})
})
4.录音及播放
//调用微信录音接口
wx.startRecord({
success: function success() {
START = new Date().getTime();
var i = 1;
var timer1 = setInterval(function () {
i += 1;
if (i == 60) {
clearInterval(timer1);
}
}, 1000);
wx.onVoiceRecordEnd({
// 录音时间超过一分钟没有停止的时候会执行 complete 回调
complete: function complete(res) {
alert('最多只能录制一分钟');
localId = res.localId;
}
});
},
cancel: function cancel() {
alert('用户拒绝授权录音');
return false;
}
});
//调用录音结束接口
wx.stopRecord({
success: function success(res) {
localId = res.localId;
wx.playVoice({ //播放用户的录音
localId: localId // 需要播放的音频的本地ID,由stopRecord接口获得
});
wx.translateVoice({ //语音识别功能,汉字比对,以读对字数的百分比计分。
localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得
isShowProgressTips: 1, // 默认为1,显示进度提示
success: function success(res) {
var txt = res.translateResult; // 语音识别的结果
},
error: function error() {
}
});
});