【问题标题】:Audio object is not playing in IE10音频对象未在 IE10 中播放
【发布时间】:2015-02-08 16:37:20
【问题描述】:

我有一个带有工厂的 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;
            }
        });
    }

【问题讨论】:

    标签: javascript angularjs audio internet-explorer-10


    【解决方案1】:

    我过去也遇到过类似的问题,是因为audio标签是自闭的。

    试试<audio></audio> 而不是<audio/>

    好像是IE10的bug

    更新

    在获得其他一些信息后,我建议您检查触发此音频的事件。也许这些事件在 IE10 中无法正常工作

    【讨论】:

    • 只有当我调试它时在 IE10 中触发的事件才会播放声音
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    相关资源
    最近更新 更多