ios真机测背景音频播放,暂停再播发从头开始播什么原因?
- 复现路径:第1步,第一次点击播放正常播放;第二步,暂停;第三次,第二次点击播放,从头开始播放; [代码]/* 音频start */[代码][代码].audioBox{}[代码][代码].audioBox>.top{[代码][代码] [代码][代码]text-align: center;[代码][代码]}[代码][代码].audioBox>.top>image{[代码][代码] [代码][代码]width: 220rpx;[代码][代码] [代码][代码]height: 297rpx;[代码][代码] [代码][代码]border-radius: 8rpx;[代码][代码] [代码][代码]box-shadow: 2rpx 2rpx 4rpx 2rpx #D4D4D4;[代码][代码]}[代码][代码].audioBox>.top>.top_title{[代码][代码] [代码][代码]font-size: 32rpx;[代码][代码] [代码][代码]font-weight: bold;[代码][代码] [代码][代码]margin: 36rpx 0 12rpx;[代码][代码]}[代码][代码].audioBox>.top>.price{[代码][代码] [代码][代码]font-size: 26rpx;[代码][代码] [代码][代码]color: #a0a0a0;[代码][代码]}[代码][代码].progress{[代码][代码] [代码][代码]margin-top: 53rpx;[代码][代码]}[代码][代码].progress>.[代码][代码]time[代码] [代码]{[代码][代码] [代码][代码]display: flex;[代码][代码] [代码][代码]justify-content: space-between;[代码][代码] [代码][代码]margin: 0 20rpx;[代码][代码]}[代码][代码].progress>.[代码][代码]time[代码][代码]>text{[代码][代码] [代码][代码]font-size: 26rpx;[代码][代码] [代码][代码]color: #a0a0a0;[代码][代码]}[代码][代码].control{[代码][代码] [代码][代码]position: relative;[代码][代码] [代码][代码]display: flex;[代码][代码] [代码][代码]align-items: center;[代码][代码] [代码][代码]justify-content: center;[代码][代码] [代码][代码]margin: 20rpx 0 56rpx;[代码][代码]}[代码][代码].control>icon{[代码][代码] [代码][代码]font-size: 53rpx;[代码][代码] [代码][代码]color: #ff3f61;[代码][代码]}[代码][代码].control>.stateBtn {[代码][代码] [代码][代码]position: relative;[代码][代码] [代码][代码]width: 94rpx;[代码][代码] [代码][代码]height: 94rpx;[代码][代码] [代码][代码]border-radius: 50%;[代码][代码] [代码][代码]background-color: #ff3f61;[代码][代码] [代码][代码]text-align: center;[代码][代码] [代码][代码]margin: 0 60rpx;[代码][代码]}[代码][代码].control>.stateBtn>icon{[代码][代码] [代码][代码]line-height: 93rpx;[代码][代码] [代码][代码]font-size: 43rpx;[代码][代码] [代码][代码]color: white;[代码][代码]}[代码][代码].control>.speed {[代码][代码] [代码][代码]position: absolute;[代码][代码] [代码][代码]top: 26rpx;[代码][代码] [代码][代码]right: 62rpx;[代码][代码] [代码][代码]font-size: 28rpx;[代码][代码] [代码][代码]color: #a0a0a0;[代码][代码] [代码][代码]text-align: center;[代码][代码]}[代码][代码].control>.speed>view {[代码][代码] [代码][代码]display: block;[代码][代码] [代码][代码]font-size: 23rpx;[代码][代码] [代码][代码]color: #a0a0a0;[代码][代码] [代码][代码]margin-top: 10rpx;[代码][代码]}[代码][代码].audioBox>.bottom {[代码][代码] [代码] [代码]}[代码][代码].audioCover {[代码][代码] [代码][代码]position: absolute;[代码][代码] [代码][代码]width: 94rpx;[代码][代码] [代码][代码]height: 94rpx;[代码][代码] [代码][代码]top: 0;[代码][代码] [代码][代码]left: 0;[代码][代码] [代码][代码]background-color: transparent;[代码][代码] [代码][代码]z-index: 9998;[代码][代码]}[代码][代码]/* 音频end */[代码][代码]<!-- 音频start -->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'audioBox'[代码] [代码]wx:elif[代码][代码]=[代码][代码]"{{courseInfo.course_carrier == 2}}"[代码][代码]>[代码][代码] [代码][代码]<!-- 音频图片和标题 -->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'top'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]'{{courseInfo.course_pictures}}'[代码][代码]></[代码][代码]image[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'top_title'[代码][代码]>{{courseInfo.course_name}}</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码] [代码]class[代码][代码]=[代码][代码]'price'[代码][代码]>¥{{courseInfo.course_price}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'bottom'[代码][代码]>[代码][代码] [代码][代码]<!-- 进度条 -->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'progress'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]slider[代码] [代码]class[代码][代码]=[代码][代码]'slider'[代码][代码] [代码][代码]bindchange[代码][代码]=[代码][代码]"sliderChange"[代码][代码] [代码][代码]activeColor[代码][代码]=[代码][代码]'red'[代码][代码] [代码][代码]block-size[代码][代码]=[代码][代码]"12"[代码][代码] [代码][代码]max[代码][代码]=[代码][代码]"{{max}}"[代码][代码] [代码][代码]value[代码][代码]=[代码][代码]'{{offset}}'[代码] [代码]/>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'time'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码][代码]>{{starttime}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码][代码]>{{courseInfo.duration}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!-- 音频控制 -->[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'control'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]icon[代码] [代码]class[代码][代码]=[代码][代码]'leftBtn iconfont iconai10'[代码] [代码]bindtap[代码][代码]=[代码][代码]'prev'[代码][代码]></[代码][代码]icon[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'stateBtn'[代码] [代码]wx:if[代码][代码]=[代码][代码]"{{!isOpen}}"[代码] [代码]bindtap[代码][代码]=[代码][代码]"listenerButtonPlay"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'audioCover'[代码] [代码]wx:if[代码][代码]=[代码][代码]"{{audioCover}}"[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]icon[代码] [代码]class[代码][代码]=[代码][代码]'startBtn iconfont iconbofang2'[代码][代码]></[代码][代码]icon[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'stateBtn'[代码] [代码]wx:if[代码][代码]=[代码][代码]"{{isOpen}}"[代码] [代码]bindtap[代码][代码]=[代码][代码]"listenerButtonPause"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]icon[代码] [代码]class[代码][代码]=[代码][代码]'iconfont iconstop'[代码][代码]></[代码][代码]icon[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]icon[代码] [代码]class[代码][代码]=[代码][代码]'rightBtn iconfont iconai09'[代码] [代码]bindtap[代码][代码]=[代码][代码]'next'[代码][代码]></[代码][代码]icon[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'speed'[代码] [代码]bindtap[代码][代码]=[代码][代码]"audioPlaybackRateSpeedUp"[代码][代码]>[代码][代码] [代码][代码]1.5X[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]>倍速播放</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<!-- 音频end -->[代码]小程序开发工具上测没问题,ios真机测试时暂停再播放是从头播。 [代码]//播放按钮[代码][代码] [代码][代码]listenerButtonPlay: [代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]let that = [代码][代码]this[代码][代码];[代码][代码] [代码][代码]//bug ios 播放时必须加title 不然会报错导致音乐不播放[代码][代码] [代码][代码]bgMusic.title = that.data.courseInfo.course_name;[代码][代码] [代码][代码]bgMusic.epname = that.data.courseInfo.course_name;[代码][代码] [代码][代码]bgMusic.src = that.data.src;[代码][代码] [代码] [代码] [代码][代码]//播放进度发生变化时[代码][代码] [代码][代码]bgMusic.onTimeUpdate(() => {[代码][代码] [代码][代码]//bgMusic.duration总时长 bgMusic.currentTime当前进度[代码][代码] [代码][代码]let duration = bgMusic.duration;[代码][代码] [代码][代码]let offset = bgMusic.currentTime;[代码][代码] [代码][代码]let currentTime = parseInt(bgMusic.currentTime);[代码][代码] [代码][代码]let min = [代码][代码]"0"[代码] [代码]+ parseInt(currentTime / 60);[代码][代码] [代码][代码]let max = parseInt(bgMusic.duration);[代码][代码] [代码][代码]let sec = currentTime % 60;[代码][代码] [代码][代码]if[代码] [代码](sec < 10) {[代码][代码] [代码][代码]sec = [代码][代码]"0"[代码] [代码]+ sec;[代码][代码] [代码][代码]};[代码][代码] [代码][代码]let starttime = min + [代码][代码]':'[代码] [代码]+ sec; [代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]offset: currentTime,[代码][代码] [代码][代码]starttime: starttime,[代码][代码] [代码][代码]max: max,[代码][代码] [代码][代码]});[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]//开始播放[代码][代码] [代码][代码]bgMusic.play();[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]isOpen: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]});[代码] [代码] [代码][代码]//播放结束[代码][代码] [代码][代码]bgMusic.onEnded(() => {[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]starttime: [代码][代码]'00:00'[代码][代码],[代码][代码] [代码][代码]isOpen: [代码][代码]false[代码][代码],[代码][代码] [代码][代码]offset: 0[代码][代码] [代码][代码]})[代码][代码] [代码][代码]that.updateViewTime();[代码][代码] [代码][代码]console.log([代码][代码]"音乐播放结束"[代码][代码]);[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码]//暂停[代码][代码] [代码][代码]listenerButtonPause:[代码][代码]function[代码] [代码]() {[代码][代码] [代码][代码]let that = [代码][代码]this[代码][代码] [代码][代码]bgMusic.pause();[代码][代码] [代码][代码]that.setData({[代码][代码] [代码][代码]isOpen: [代码][代码]false[代码][代码] [代码][代码]});[代码][代码] [代码][代码]that.updateViewTime();[代码][代码] [代码][代码]},[代码]