Commit 1b916d55 by 李伟康

测试IOS播放音频

1 parent 9029c5f6
......@@ -68,6 +68,8 @@
.icon-music {
animation: move 3s infinite ease-in-out;
border: 1px solid #fff;
border-radius: 100%;
}
}
}
......@@ -108,6 +110,9 @@
z-index: 2;
background: #E9E8EC;
box-sizing: border-box;
img{
object-fit: contain;
}
.line-box {
position: absolute;
left: 0;
......@@ -117,11 +122,11 @@
background: linear-gradient(360deg, #292929 0%, #474747 100%);
.line {
width: 54%;
width: 73%;
height: 2px;
background: #fff;
border-radius: 1px;
margin-left: 6px;
margin-left: 4%;
}
.duration{
font-size: 8px;
......
......@@ -10,7 +10,7 @@
module.exports = {
title: '加载中...',
request: {
baseURL: 'http://scrm.dev.glsx.com.cn', // 本地测试项目地址,
baseURL: 'http://scrm.test.glsx.com.cn', // 本地测试项目地址,
// 设置超时时间
timeout: 180000,
// 携带凭证
......
......@@ -43,7 +43,8 @@ const ua = navigator.userAgent.toLowerCase()
let body = document.getElementsByTagName('head')[0],
WXJDK = document.createElement('script'),
WWJDK = document.createElement('script'),
ISWXWORK = false
ISWXWORK = false,
IsIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)
WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.2.0.js'
if (Boolean(ua.match(/MicroMessenger/i)) && Boolean(ua.match(/wxwork/i))) { //是否企微
// WXJDK.src = '//res.wx.qq.com/open/js/jweixin-1.2.0.js'
......@@ -56,6 +57,8 @@ Vue.prototype.ISWXWORK = ISWXWORK
Vue.prototype.ISMOBILE = util.isMobileDevice()
body.appendChild(WXJDK)
if (WWJDK.src) body.appendChild(WWJDK)
window.$IsIOS = IsIOS
Vue.prototype.IsIOS = IsIOS
const isMock = ['prod', 'production'].includes(process.env.NODE_ENV)
fetchConfig(!isMock).then(res => {
// 从配置服务器获取动态配置
......
export function Audio (url, callBack) {
this.IsIOS = window.$IsIOS
this.audioContext = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)()
this.sourceNode = null
this.buffer = null
this.isPlayingBGM = false
if (this.IsIOS) {
let body = document.getElementsByTagName('body')[0]
this.audioContext = document.createElement('audio')
this.audioContext.src = url
this.audioContext.loop = true
body.appendChild(this.audioContext)
this.audioContext.ondurationchange = () => {
console.log('IOS播放——————————————')
this.audioContext.play()
}
}
this.toggleBGM = function (off) {
if (typeof this.sourceNode == 'object') {
if (typeof this.sourceNode == 'object' && !this.IsIOS) {
if (this.isPlayingBGM || off) {
this.sourceNode.stop()
this.isPlayingBGM = false
console.log('暂停——————————————', this.sourceNode)
} else this._playSourceNode()
} else {
if (this.audioContext.paused) this.audioContext.play()
else this.audioContext.pause()
}
}
this.stopVideo = function () {
if (typeof this.sourceNode == 'object') {
if (typeof this.sourceNode == 'object' && !this.IsIOS) {
if (this.isPlayingBGM) {
this.sourceNode.stop()
this.isPlayingBGM = false
console.log('暂停——————————————', this.sourceNode)
}
}
} else this.audioContext.pause()
}
this._playSourceNode = function () {
const audioContext = this.audioContext
......@@ -34,31 +49,36 @@ export function Audio (url, callBack) {
this.isPlayingBGM = true
}
let loadAndAutoPlay = (audioUrl) => {
const audioContext = this.audioContext
const xhr = new XMLHttpRequest()
let _this = this
xhr.open('GET', `${audioUrl}?v=${Date.now()}`, true)
xhr.responseType = 'arraybuffer'
xhr.onreadystatechange = () => {
if (xhr.status < 400 && xhr.status >= 200 && xhr.readyState === 4) {
audioContext.decodeAudioData(xhr.response, buffer => {
this.buffer = buffer
if (buffer) {
if (wx.getNetworkType) wx.getNetworkType({
success: function (res) {
alert(window.$IsIOS)
if (!this.IsIOS) {
const audioContext = this.audioContext
const xhr = new XMLHttpRequest()
let _this = this
xhr.open('GET', `${audioUrl}?v=${Date.now()}`, true)
xhr.responseType = 'arraybuffer'
xhr.onreadystatechange = () => {
if (xhr.status < 400 && xhr.status >= 200 && xhr.readyState === 4) {
audioContext.decodeAudioData(xhr.response, buffer => {
this.buffer = buffer
if (buffer) {
if (wx.getNetworkType) wx.getNetworkType({
success: function (res) {
_this._playSourceNode()
callBack()
}
})
else {
_this._playSourceNode()
callBack()
}
})
else {
_this._playSourceNode()
callBack()
}
}
})
})
}
}
xhr.send()
} else {
callBack()
}
xhr.send()
}
loadAndAutoPlay(url)
loadAndAutoPlay = null
......
......@@ -116,8 +116,8 @@ const setLocalStorage = (key, item) => {
}
const getLocalStorage = key => {
let store = JSON.parse(window.localStorage.getItem(key))
if(key == 'wx_scrm_link_params') {
if(!store || Object.keys(store).length < 0 ){
if (key == 'wx_scrm_link_params') {
if (!store || Object.keys(store).length < 0) {
store = getPageQuery()
}
}
......@@ -245,9 +245,27 @@ const isMobileDevice = () => {//判断当前设备是否为移动端
}
/**页面跳转 */
const jump = name =>{
const jump = name => {
console.log(this)
}
/**秒数转天时分秒*/
const date_format = num => {
const addZero = i => i < 10 ? `0${i}` : `${i}`
//计算剩余的天数
let days = addZero(parseInt(num / 60 / 60 / 24, 10))
//计算剩余的小时
let hours = addZero(parseInt(num / 60 / 60 % 24, 10))
//计算剩余的分钟
let minutes = addZero(parseInt(num / 60 % 60, 10))
//计算剩余的秒数
let second = addZero(parseInt(num % 60, 10))
if (days == 0) {
return `${hours}:${minutes}:${second}`
}
return `${days}天${hours}:${minutes}:${second}`
}
const utils = {
removeLocalStorage,
setClipboardData,
......@@ -269,7 +287,7 @@ const utils = {
getUserInfo,
hideLoading,
refreshPage,
date_format,
touchstart,
showToast,
getParams,
......
......@@ -130,6 +130,7 @@ export default {
if (detail.buyFlag == 2 || detail.activityStatus != 2) return
this.showModal = true
},
/**明天继续这里添加车型 */
checkOut: util.debounce(({ obj, that }) => {
let { detail } = that
let { nickName, logo } = util.getUserInfo()
......
......@@ -62,17 +62,17 @@
:ref="`video-${index}`"
:controls="false"
preload
@loadedmetadata="loadedmetadata($event,index)"
@loadedmetadata="loadedmetadata($event)"
></video>
<div class="mask">
<img src="https://img02.glsx.com.cn/weapp/resource/h5/images/video-poster.png" />
<img :src="i.activityVideoCoverImage" />
<div :class="['sprite-icon xy-center',detail.activityVideos.length == 1 ?'icon-big-play':'icon-play']"></div>
<div class="line-box flex">
<div class="line"></div>
<div
v-if="i.duration"
v-if="i.activityVideoTime"
class="duration"
>{{i.duration}}</div>
>{{date_format(i.activityVideoTime)}}</div>
</div>
</div>
</div>
......@@ -359,23 +359,7 @@ export default {
})
})
},
loadedmetadata ({ srcElement }, index) {
const addZero = i => i < 10 ? `0${i}` : `${i}`
function date_format (num) {
//计算剩余的天数
let days = addZero(parseInt(num / 60 / 60 / 24, 10))
//计算剩余的小时
let hours = addZero(parseInt(num / 60 / 60 % 24, 10))
//计算剩余的分钟
let minutes = addZero(parseInt(num / 60 % 60, 10))
//计算剩余的秒数
let second = addZero(parseInt(num % 60, 10))
if (days == 0) {
return `${hours}:${minutes}:${second}`
}
return `${days}天${hours}:${minutes}:${second}`
}
this.detail.activityVideos[index].duration = date_format(srcElement.duration)
loadedmetadata ({ srcElement }) {
srcElement.controls = false
srcElement.addEventListener('webkitendfullscreen', () => {
let { audioFlag } = this
......
......@@ -41,9 +41,6 @@ export default {
return
}
},
mounted () {
// this.drawOrderImg()
},
methods: {
drawOrderImg (orderInfo) {
this.ctx = document.getElementById('canvas')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!