我有一个带有工厂的AngualrJS应用,负责在某些事件中播放音频。
我在该工厂中创建了3种不同的音频。
我的问题是在IE10中,当我逐步运行并在调试器中运行后,只有从调试器调用的一个音频(已发送消息)正在播放3,而其他2正在正在调试器中(从同一工厂调用)正在播放。第一次播放,然后在没有调试器的情况下可以正常工作。
在Chrome和firefox中效果很好。
var sounds = {
messageSent: new Audio('/assets/audios/message-sent.mp3'),
privateMessageRecived: new Audio('/assets/audios/private_message.mp3'),
notificationRecieved: new Audio('/assets/audios/notification-recived.mp3')
};
然后播放音频:
sounds[soundName].play();
MIME类型是
audio/mpeg
。 function start() {
pusherEvents.onAll(function(channelName, eventName, data) {
if (!isEmbedInactive() || isMuted()) {
return;
}
switch (eventName) {
case 'message':
if (!isMe(data.sender_id)) {
SpotsManager.getSpot({ id: data.spot_id })
.then(function(spot) {
if (spot.type === 'intimate') {
sounds.privateMessageRecived.play();
}
});
}
break;
case 'user_mentioned':
if (!isMe(data.mentioner.id)) {
sounds.notificationRecieved.play();
}
break;
case 'message_liked':
var isMine = isMe(data.sender_id);
if (isMine) {
sounds.notificationRecieved.play();
}
break;
case 'invitation_accepted':
if (!isMe(data.invitee.id)) {
sounds.notificationRecieved.play();
}
break;
case 'intimate_user_invited':
sounds.notificationRecieved.play();
break;
}
});
}
最佳答案
我过去也遇到过类似的问题,这是因为audio
标记是自动关闭的。
尝试<audio></audio>
而不是<audio/>
似乎是IE10错误
更新
在获得一些其他信息之后,建议您检查触发该音频的事件。可能事件无法在IE10中正常运行
关于javascript - IE10中未播放音频对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27401771/