3433关注10952浏览
微信小程序,在启动地图之前,播放声音手机和模拟器均正常,启动模拟器之后,模拟器正常,手机无声音
代码如下:
//index.js
//获取应用实例
const app = getApp()
var EARTH_RADIUS = 6378137.0; //单位M
var PI = Math.PI;
Page({
data: {
latitude: '',
longtitude: '',
curLatitude: '',
curLongitude: '',
precision: '30',
exenum: '0',
distance: '0'
},
onLoad: function () {
var that = this;
/////////////////////// 在地图被调用前,手机播放正常,模拟器正常
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'res/Young.mp3'
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
});
setTimeout(function () {
console.log("before等待============")
////////////////////////
if (that.data.precision > 0) {
wx.chooseLocation({ //调用地图
success: function (res) {
console.log(res);
wx.openLocation({
latitude: res.latitude,
longitude: res.longitude,
name: res.name,
address: res.address
});
that.setData(
{
//latitude: res.latitude,
//longitude: res.longitude
latitude: 39.928712,
longitude: 116.393345
}
);
console.log("destination latitude is " + " " + that.data.latitude);
console.log("destination longitude is " + " " + that.data.longitude);
wx.getLocation({
success: function (res) {
console.log("current latitude is " + " " + res.latitude);
console.log("current longitude is " + " " + res.longitude);
that.setData(
{
curLatitude: res.latitude,
curLongitude: res.longitude
});
var mydis = getFlatternDistance(that.data.curLatitude, that.data.curLongitude, that.data.latitude, that.data.longitude);
console.log("distance" + " " + mydis);
// if (that.data.distance < 5000000) {
//start play, 这里再次播放音频,手机无声音,模拟器正常。
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'res/Young.mp3'
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
in
-
至过去的我
2044人对此回答表示赞同
我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>