V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
a570295535
V2EX  ›  问与答

js 大神来看看,明明加了 autostart="false"为什么音乐还是自动播放?

  •  
  •   a570295535 · 2016-06-29 14:22:12 +08:00 · 3117 次点击
    这是一个创建于 2829 天前的主题,其中的信息可能已经有所发展或是发生改变。
    弄了个 js 的音乐播放器,我想让它默认不播放,但是加了 autostart="false"还是不管用,
    应该是 js 的问题,请问哪里的毛病啊?

    demo 播放器:
    http://www.qiufoba.com/music/yy.html
    13 条回复    2016-06-29 17:46:39 +08:00
    ziki
        1
    ziki  
       2016-06-29 14:32:43 +08:00
    确定属性名不是 autoplay?
    a570295535
        2
    a570295535  
    OP
       2016-06-29 14:34:58 +08:00
    @ziki 我去掉 js 代码,实验 autostart="false"是管用的, autoplay="false"是完全不管用。
    learnshare
        3
    learnshare  
       2016-06-29 14:43:21 +08:00
    a570295535
        4
    a570295535  
    OP
       2016-06-29 14:49:06 +08:00
    @learnshare 我是说我 js 有问题,帮忙看看 js 哪里错了,如果不用 js 的话本身就不是问题了
    learnshare
        5
    learnshare  
       2016-06-29 16:22:12 +08:00
    @a570295535 autoplay 最好直接写在 audio 标签中,如果不想让它直接播放,就 **不写 autoplay 属性** ( autoplay="false" 并不能保证,因为 autoplay|autoplay="true"|autoplay="false"|autoplay="abc" 可能是完全一样的)。
    autostart 属性并不存在;问题也不出在 JS 上面。

    不过 JS 本身的确有问题:

    ```js
    this. loadStart=function(){
    $("#sn_status").text("加载中....");
    }
    ```

    this. loadStart 中间的空格是怎么回事?
    a570295535
        6
    a570295535  
    OP
       2016-06-29 16:32:16 +08:00
    @learnshare
    this. loadStart 中间的空格是多余,不过不碍事。
    autostart 属性在啊,但不管用<audio id="musicBox" controls="true" autostart="false"
    不是 js 的问题是什么的问题啊?
    laobaozi
        7
    laobaozi  
       2016-06-29 16:49:40 +08:00
    audio 标签什么时候有 autostart 属性了,你确定这个 autostart 这个属性不是别的 js 进行的封装?
    audio 对象也没有 autostart 属性和方法啊
    a570295535
        8
    a570295535  
    OP
       2016-06-29 16:51:24 +08:00
    @laobaozi
    如果去掉 js 代码,实验 autostart="false"是管用的, autoplay="false"是不管用的。
    但是加上 js 后啥都不管用了
    gongpeione
        9
    gongpeione  
       2016-06-29 17:06:58 +08:00
    autoplay A Boolean attribute; if specified (even if the value is "false"!), the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.

    如果不要自动播放就不要加 autoplay ,以及 autostart 没有这个东西
    learnshare
        10
    learnshare  
       2016-06-29 17:07:57 +08:00
    @a570295535 我解释的不清楚?还是你不仔细看回复
    gongpeione
        11
    gongpeione  
       2016-06-29 17:11:09 +08:00
    以及你现在自动播放是 js 初始化的时候就控制他开始播放了
    ziki
        12
    ziki  
       2016-06-29 17:35:10 +08:00
    @a570295535 我是没有看到有 autostart 这个属性,你说是他起作用的话那你把他设置为 true ,看他能不能自动播放
    吐槽一下,你难道文档都不查的么
    laobaozi
        13
    laobaozi  
       2016-06-29 17:46:39 +08:00
    init()->nextMusic()->play() 所以自动播放了?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1540 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 17:15 · PVG 01:15 · LAX 10:15 · JFK 13:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.