vue2.0使用html5中的audio标签不能播放音乐

我写了一个M端播放音乐的组件,使用html5的audio标签

clipboard.png

然后我使用watch监测currentSong

clipboard.png

在浏览器中看到audio渲染的如下:

clipboard.png

单独访问渲染出来的audio中url可以播放音乐,为什么调用:this.$refs.audioRef.play()方法不能播放音乐?

阅读 17.1k
8 个回答

ios? 如果是ios的话有限制。媒体的播放操作需要放在交互事件的回调函数里才能生效。

computed 问题 你这照搬的源码 只能告诉你这些了 剩下的自己动手吧

新手上路,请多包涵
    watch:{
        play_mp3_url : function(newUrl){
            let _this = this;
            _this.$nextTick(() => {
                _this.$refs.player.play();
            })
        }
    } 
    用_this变量
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题