Commit 6008207102b6cea88546143df161d6d5179a7153

Authored by vking
1 parent e2d06991

test map audio

@@ -34,7 +34,9 @@ @@ -34,7 +34,9 @@
34 "pages/me/history", 34 "pages/me/history",
35 "pages/reserve/remark", 35 "pages/reserve/remark",
36 "pages/reserve/findSeller", 36 "pages/reserve/findSeller",
37 - "pages/customer/cancel" 37 + "pages/customer/cancel",
  38 + "pages/test/index",
  39 + "pages/test/index2"
38 ], 40 ],
39 "subpackages": [ 41 "subpackages": [
40 { 42 {
@@ -173,6 +175,7 @@ @@ -173,6 +175,7 @@
173 "usingComponents": { 175 "usingComponents": {
174 "layout": "/components/layout" 176 "layout": "/components/layout"
175 }, 177 },
  178 + "requiredBackgroundModes": ["audio"],
176 "debug": true, 179 "debug": true,
177 "sitemapLocation": "sitemap.json" 180 "sitemapLocation": "sitemap.json"
178 } 181 }
  1 +// pages/test/index.js
  2 +Page({
  3 +
  4 + /**
  5 + * 页面的初始数据
  6 + */
  7 + data: {
  8 +
  9 + },
  10 +
  11 + /**
  12 + * 生命周期函数--监听页面加载
  13 + */
  14 + onLoad: function (options) {
  15 + this.audio()
  16 + },
  17 +
  18 + /**
  19 + * 生命周期函数--监听页面初次渲染完成
  20 + */
  21 + onReady: function () {
  22 +
  23 + },
  24 +
  25 + /**
  26 + * 生命周期函数--监听页面显示
  27 + */
  28 + onShow: function () {
  29 +
  30 + },
  31 +
  32 + /**
  33 + * 生命周期函数--监听页面隐藏
  34 + */
  35 + onHide: function () {
  36 +
  37 + },
  38 +
  39 + /**
  40 + * 生命周期函数--监听页面卸载
  41 + */
  42 + onUnload: function () {
  43 +
  44 + },
  45 +
  46 + /**
  47 + * 页面相关事件处理函数--监听用户下拉动作
  48 + */
  49 + onPullDownRefresh: function () {
  50 +
  51 + },
  52 +
  53 + /**
  54 + * 页面上拉触底事件的处理函数
  55 + */
  56 + onReachBottom: function () {
  57 +
  58 + },
  59 +
  60 + /**
  61 + * 用户点击右上角分享
  62 + */
  63 + onShareAppMessage: function () {
  64 +
  65 + },
  66 + audio(){
  67 + wx.setInnerAudioOption({
  68 + mixWithOther:true,//混响
  69 + obeyMuteSwitch:false,//静音播放
  70 + })
  71 + const innerAudioContext = wx.createInnerAudioContext()
  72 + innerAudioContext.autoplay = true
  73 + innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/1.mp3'
  74 + innerAudioContext.volume=1 //0~1
  75 + innerAudioContext.loop=true
  76 + innerAudioContext.onPlay(() => {
  77 + console.log('开始播放')
  78 + })
  79 + innerAudioContext.onError((res) => {
  80 + console.log('innerAudioContext.onError',res)
  81 + })
  82 + },
  83 + bgAudio(){
  84 + const innerAudioContext =wx.getBackgroundAudioManager()
  85 + innerAudioContext.title = 'BackgroundAudioManager'
  86 + innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/2.mp3'
  87 + innerAudioContext.volume=1 //0~1
  88 + innerAudioContext.loop=true
  89 + innerAudioContext.onPlay(() => {
  90 + console.log('开始播放')
  91 + })
  92 + innerAudioContext.onError((res) => {
  93 + console.log('innerAudioContext.onError',res)
  94 + })
  95 + setTimeout(()=>{
  96 + this.bgAudio()
  97 + },2000)
  98 + },
  99 +})
  1 +{
  2 + "usingComponents": {}
  3 +}
  1 +<!--pages/test/index.wxml-->
  2 +<map id="map" scale="18"
  3 + longitude="108.892000" latitude="34.216529"
  4 + markers="{{markers}}" polygons="{{polygons}}"
  5 + bindmarkertap="markertap"
  6 + bindcallouttap="markertap"
  7 + bindregionchange="regionchange"
  8 + bindupdated="mapUpdated"
  9 + show-location="{{false}}"
  10 + enable-3D="{{false}}"
  11 + enable-zoom
  12 + enable-scroll
  13 + enable-rotate
  14 + subkey="SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ"
  15 + layer-style="1"
  16 + style="width: 100%; height: 500px;"></map>
  17 +
  18 +<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>
  19 +使用 innerAudioContext 方式播放音频
  1 +/* pages/test/index.wxss */
  1 +// pages/test/index2.js
  2 +Page({
  3 +
  4 + /**
  5 + * 页面的初始数据
  6 + */
  7 + data: {
  8 +
  9 + },
  10 +
  11 + /**
  12 + * 生命周期函数--监听页面加载
  13 + */
  14 + onLoad: function (options) {
  15 + this.bgAudio()
  16 + },
  17 +
  18 + /**
  19 + * 生命周期函数--监听页面初次渲染完成
  20 + */
  21 + onReady: function () {
  22 +
  23 + },
  24 +
  25 + /**
  26 + * 生命周期函数--监听页面显示
  27 + */
  28 + onShow: function () {
  29 +
  30 + },
  31 +
  32 + /**
  33 + * 生命周期函数--监听页面隐藏
  34 + */
  35 + onHide: function () {
  36 +
  37 + },
  38 +
  39 + /**
  40 + * 生命周期函数--监听页面卸载
  41 + */
  42 + onUnload: function () {
  43 +
  44 + },
  45 +
  46 + /**
  47 + * 页面相关事件处理函数--监听用户下拉动作
  48 + */
  49 + onPullDownRefresh: function () {
  50 +
  51 + },
  52 +
  53 + /**
  54 + * 页面上拉触底事件的处理函数
  55 + */
  56 + onReachBottom: function () {
  57 +
  58 + },
  59 +
  60 + /**
  61 + * 用户点击右上角分享
  62 + */
  63 + onShareAppMessage: function () {
  64 +
  65 + },
  66 + audio(){
  67 + wx.setInnerAudioOption({
  68 + mixWithOther:true,//混响
  69 + obeyMuteSwitch:false,//静音播放
  70 + })
  71 + const innerAudioContext = wx.createInnerAudioContext()
  72 + innerAudioContext.autoplay = true
  73 + innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/1.mp3'
  74 + innerAudioContext.volume=1 //0~1
  75 + innerAudioContext.loop=true
  76 + innerAudioContext.onPlay(() => {
  77 + console.log('开始播放')
  78 + })
  79 + innerAudioContext.onError((res) => {
  80 + console.log('innerAudioContext.onError',res)
  81 + })
  82 + },
  83 + bgAudio(){
  84 + const innerAudioContext =wx.getBackgroundAudioManager()
  85 + innerAudioContext.title = 'BackgroundAudioManager'
  86 + innerAudioContext.src = 'http://nosqn.colorcun.com/mp3/2.mp3'
  87 + innerAudioContext.volume=1 //0~1
  88 + innerAudioContext.loop=true
  89 + innerAudioContext.onPlay(() => {
  90 + console.log('开始播放')
  91 + })
  92 + innerAudioContext.onError((res) => {
  93 + console.log('innerAudioContext.onError',res)
  94 + })
  95 + setTimeout(()=>{
  96 + this.bgAudio()
  97 + },2000)
  98 + },
  99 +})
  1 +{
  2 + "usingComponents": {
  3 + "nav":"/components/nav/nav"
  4 + }
  5 +}
  1 +<!--pages/test/index2.wxml-->
  2 +<nav></nav>
  3 +<map id="map2" scale="18"
  4 + longitude="108.892000" latitude="34.216529"
  5 + markers="{{markers}}" polygons="{{polygons}}"
  6 + bindmarkertap="markertap"
  7 + bindcallouttap="markertap"
  8 + bindregionchange="regionchange"
  9 + bindupdated="mapUpdated"
  10 + show-location="{{false}}"
  11 + enable-3D="{{false}}"
  12 + enable-zoom
  13 + enable-scroll
  14 + enable-rotate
  15 + subkey="SDEBZ-I74W4-QLGUX-XXYXU-HIR23-3QFBJ"
  16 + layer-style="2"
  17 + style="width: 100%; height: 500px;"></map>
  18 +
  19 +使用 BackgroundAudioManager 方式播放音频
  1 +/* pages/test/index2.wxss */
@@ -674,6 +674,13 @@ @@ -674,6 +674,13 @@
674 "pathName": "pack-activity/pack/list", 674 "pathName": "pack-activity/pack/list",
675 "query": "", 675 "query": "",
676 "scene": null 676 "scene": null
  677 + },
  678 + {
  679 + "id": -1,
  680 + "name": "pages/test/index",
  681 + "pathName": "pages/test/index",
  682 + "query": "id=1001",
  683 + "scene": null
677 } 684 }
678 ] 685 ]
679 } 686 }