头像

微信小程序audio标签 播放背景音乐

在使用过程中有一些注意事项:

1、不能使用本地文件,需要使用远程服务器上的地址

在开发者工作使用本地文件可以播放,但在手机预览或体验版时不能播放,报错:uncaught(in promise)。

 

其它后续更新。

以下是我的代码:

wxml
<audio id=”myAudio” src=”http://www.xxx.com/broken.mp3″ loop=”false” ></audio>
js
this.audioCtx = wx.createAudioContext(‘myAudio’);
this.audioCtx.play();
//播放指定时间后停止
setTimeout(function () {
that.audioCtx.pause();
},1000);
头像

微信小程序动态改变导航栏标题和背景颜色

1、动态的改变标题字体和背景颜色

.wxml文件:

<view class=”container”>

<button type=”primary” bindtap=”modalcnt1″>改变标题1</button>

<button type=”primary” bindtap=”modalcnt2″>改变标题2</button>

<button type=”primary” bindtap=”modalcnt3″>改变标题3</button>

</view>

.wxss文件:

button{margin: 10px}

.js文件:

Page({

data: {},

modalcnt1: function() {

wx.setNavigationBarTitle({

title: ‘——百家号(标题1)——‘,});

},

modalcnt2: function() {

wx.setNavigationBarTitle({

title: ‘******百家号(标题2)******’,});

},

modalcnt3: function() {

wx.setNavigationBarTitle({

title: ‘++++++百家号(标题3)++++++’,});

},})

 

2、动态的改变标题背景颜色

.wxml文件:

<view class=”container”>

<button type=”primary” bindtap=”modalcnt1″>改变标题背景颜色为米白</button>

<button type=”primary” bindtap=”modalcnt2″>改变标题背景颜色为灰色</button>

<button type=”primary” bindtap=”modalcnt3″>改变标题背景颜色为雅红</button>

</view>

.wxss文件:

button{margin: 10px}

.js文件:

const app = getApp()

Page({

data: {},

modalcnt1: function() {

wx.setNavigationBarColor({

frontColor: ‘#000000′,

backgroundColor: ‘#ffa’,

animation: {

duration: 500,

timingFunc: ‘linear’}});},

modalcnt2: function() {

wx.setNavigationBarColor({

frontColor: ‘#000000′,

backgroundColor: ‘#ccc’,

animation: {

duration: 500,

timingFunc: ‘linear’}});},

modalcnt3: function() {

wx.setNavigationBarColor({

frontColor: ‘#000000′,

backgroundColor: ‘#f20′,

animation: {

duration: 500,

timingFunc: ‘linear’}});},})