html音频只播放一次,html5,javascript_html5 audio在IOS上播放MP3为何只能播放一次,html5,javascript,前端 - phpStudy...

html5 audio在IOS上播放MP3为何只能播放一次

在一个项目中遇到的问题,HTML5 audio播放MP3文件(只有几秒的提示音),在安卓上能正常播放,但在IOS上就只能播放一次,再点击就不会播放了。经测试可能是 currentTime的问题,

Player = function() {

"use strict";

function e(e, t) {

var n, r, i = !1,

o = "audio-player";

if (n = document.createElement("Audio"), n.className = o, n.style.display = "none", t) for (r in t) t.hasOwnProperty(r) && (n[r] = t[r]);

document.body.appendChild(n),

this.player = n,

this.player.src = e,

this.isplay = i

}

return e.prototype = {

volume: function(e) {

return e ? this.player.volume = e: this.player.volume

},

isPlaying: function() {

return this.isplay

},

play: function() {

this.isplay = !0,

this.player.play()

},

pause: function() {

this.isplay = !1,

this.player.pause()

},

toggle: function() {

this.isplay ? this.pause() : this.play()

},

time: function(e) {

return e ? this.player.currentTime = e: this.player.currentTime

},

setTime: function(){

this.player.currentTime = 0

},

totalTime: function() {

return this.player.duration

},

on: function(e, t) {

var n, r = this,

i = e.split(/\s+/),

o = function(e) {

r.player.ended && "pause" === e.type || t.apply(r, Array.prototype.slice.call(arguments))

};

for (n = 0; n < i.length; ++n) i[n] && this.player.addEventListener(i[n], o, !1)

}

},e

} ();

$(function() {

function e(e, t) {

e.forEach(function(e) {

// e !== t && (e.isPlaying() && e.pause(), e.append_player && e.append_player.isPlaying && e.append_player.pause())

e !== t && (e.isPlaying() && e.pause())

})

}

//if (0 === $(".main.thread").length) return ! 1;

var t = [];

$(".voice").each(function() {

var n, r = $(this),

i = r.data("src"),

// o = r.data("append-src"),

s = new Player(i, {

preload: "none"

});

t.push(s),

// o && (s.append_player = n = new Player(o, {

// n = new Player(o, {

// preload: "none"

// }), n.on("playing",

// function() {

// r.addClass("play")

// }), n.on("pause",

// function() {

// r.removeClass("play")

// }), n.on("ended",

// function() {

// r.removeClass("play"),

// s.in_append = !1

// }),

s.on("playing",

function() {

console.log('playing');

r.addClass("play")

}),

s.on("pause",

function() {

console.log('pause');

r.removeClass("play")

}),

s.on("ended",

function() {

console.log('end');

console.log(s.time());

s.pause();

// s.time(1);

s.setTime();

console.log(s.time());

console.log(s.isPlaying());

// s.append_player ? (s.append_player.play(), s.in_append = !0) : r.removeClass("play")

r.removeClass("play")

}),

r.on("click",

function() {

console.log('click play');

// s.isPlaying() || n && n.isPlaying() ? e(t, null) : (n && s.in_append ? n.play() : s.play(), e(t, s));

s.isPlaying() ? e(t, null) : (s.play(), e(t, s));

});

});

});

这样写在安卓上是可以的,但在IOS上currenttime不会被设置成0. 大家有什么解决方案不。谢谢!

相关阅读:

java EE 与JDK区别

数据库查询,怎样按一定时间间隔跳跃查询数据?

vue.js中,在v-for循环里,使用v-if和v-else,没有实现条件逻辑是怎么回事?

ps cc的复制css功能怎么使用?

支付宝签名问题

FrameLayout的层次问题

C/C++怎样通过一个结构体访问另一个结构体的数据?

有没有拉拽排序listview和gridview的库啊?

关于上传文件的工具

sql查询时如何动态更换连接表

CentOS7 Virtual Box 开机自动挂载共享文件夹

gunicorn+gevent+django+PostgreSQL下的数据库连接情况

php的setcookie突然无法工作?

Java中如何设置代码

登录之后react-router的跳转?

CSS 像素与设备像素的一些疑问

Actionscript项目怎么转成flex项目?

uwsgi --xml命令执行卡住了

Yii视图页面如何获取验证信息

关于登陆模块的设计

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值