Commit 6008207102b6cea88546143df161d6d5179a7153

Authored by vking
1 parent e2d06991

test map audio

... ... @@ -34,7 +34,9 @@
"pages/me/history",
"pages/reserve/remark",
"pages/reserve/findSeller",
"pages/customer/cancel"
"pages/customer/cancel",
"pages/test/index",
"pages/test/index2"
],
"subpackages": [
{
... ... @@ -173,6 +175,7 @@
"usingComponents": {
"layout": "/components/layout"
},
"requiredBackgroundModes": ["audio"],
"debug": true,
"sitemapLocation": "sitemap.json"
}
\ No newline at end of file
... ...
// pages/test/index.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.audio()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
audio(){
wx.setInnerAudioOption({
mixWithOther:true,//混响
obeyMuteSwitch:false,//静音播放
})
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/1.mp3'
innerAudioContext.volume=1 //0~1
innerAudioContext.loop=true
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log('innerAudioContext.onError',res)
})
},
bgAudio(){
const innerAudioContext =wx.getBackgroundAudioManager()
innerAudioContext.title = 'BackgroundAudioManager'
innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/2.mp3'
innerAudioContext.volume=1 //0~1
innerAudioContext.loop=true
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log('innerAudioContext.onError',res)
})
setTimeout(()=>{
this.bgAudio()
},2000)
},
})
\ No newline at end of file
... ...
{
"usingComponents": {}
}
\ No newline at end of file
... ...
<!--pages/test/index.wxml-->
<map id="map" scale="18"
longitude="108.892000" latitude="34.216529"
markers="{{markers}}" polygons="{{polygons}}"
bindmarkertap="markertap"
bindcallouttap="markertap"
bindregionchange="regionchange"
bindupdated="mapUpdated"
show-location="{{false}}"
enable-3D="{{false}}"
enable-zoom
enable-scroll
enable-rotate
subkey="SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ"
layer-style="1"
style="width: 100%; height: 500px;"></map>
<navigator style="width: 100%; height: 100rpx; line-height:100rpx;text-align:center;margin-top: 100rpx; background-color: #1AAD19;color:#fefefe;" url="./index2" hover-class="navigator-hover">跳转清爽地图页</navigator>
使用 innerAudioContext 方式播放音频
\ No newline at end of file
... ...
/* pages/test/index.wxss */
\ No newline at end of file
... ...
// pages/test/index2.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.bgAudio()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
audio(){
wx.setInnerAudioOption({
mixWithOther:true,//混响
obeyMuteSwitch:false,//静音播放
})
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/1.mp3'
innerAudioContext.volume=1 //0~1
innerAudioContext.loop=true
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log('innerAudioContext.onError',res)
})
},
bgAudio(){
const innerAudioContext =wx.getBackgroundAudioManager()
innerAudioContext.title = 'BackgroundAudioManager'
innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/2.mp3'
innerAudioContext.volume=1 //0~1
innerAudioContext.loop=true
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log('innerAudioContext.onError',res)
})
setTimeout(()=>{
this.bgAudio()
},2000)
},
})
\ No newline at end of file
... ...
{
"usingComponents": {
"nav":"/components/nav/nav"
}
}
\ No newline at end of file
... ...
<!--pages/test/index2.wxml-->
<nav></nav>
<map id="map2" scale="18"
longitude="108.892000" latitude="34.216529"
markers="{{markers}}" polygons="{{polygons}}"
bindmarkertap="markertap"
bindcallouttap="markertap"
bindregionchange="regionchange"
bindupdated="mapUpdated"
show-location="{{false}}"
enable-3D="{{false}}"
enable-zoom
enable-scroll
enable-rotate
subkey="SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ"
layer-style="2"
style="width: 100%; height: 500px;"></map>
使用 BackgroundAudioManager 方式播放音频
... ...
/* pages/test/index2.wxss */
\ No newline at end of file
... ...
... ... @@ -674,6 +674,13 @@
"pathName": "pack-activity/pack/list",
"query": "",
"scene": null
},
{
"id": -1,
"name": "pages/test/index",
"pathName": "pages/test/index",
"query": "id=1001",
"scene": null
}
]
}
... ...