jQuery 我怎样才能让圆形 jPlayer 自动播放?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7808956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:17:15  来源:igfitidea点击:

How can i make circle jPlayer autoplay?

jqueryjplayer

提问by Kochumon Mathew

Can anyone tell me how to make this autoplay?

谁能告诉我如何制作这个自动播放?

$(document).ready(function(){
    var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
    {
        m4a:"x.mp3",
        oga: "x.ogg"
    }, {
        cssSelectorAncestor: "#cp_container_1"
    });
});

回答by Andy Rose

Try this (documentation here) after you have created your player:

创建播放器后,请尝试此操作(此处的文档):

$('#jquery_jplayer_1').jPlayer("play");

Alternatively instantiate the player like this:

或者像这样实例化播放器:

  $(document).ready(function () {
      $("#jquery_jplayer_1").jPlayer({
         ready: function () {
             $(this).jPlayer("setMedia", {
                m4a:"x.mp3",
                oga: "x.ogg"
              }).jPlayer("play");
          },
          swfPath: "/scripts/Jplayer.swf",
          supplied: "m4a, oga"
      });
  });

回答by hansmaiser

maybe not the nicest solution but it works:

也许不是最好的解决方案,但它有效:

[...]
canplay: function() {
    $("#jquery_jplayer_1").jPlayer("play");
}

$(document).ready(function() {                           
    var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
    {
        m4a: "http://www.jplayer.org/audio/m4a/Miaow-07-Bubble.m4a",
        oga: "http://www.jplayer.org/audio/ogg/Miaow-07-Bubble.ogg"
    }, {
        cssSelectorAncestor: "#cp_container_1",
        canplay: function() {
            $("#jquery_jplayer_1").jPlayer("play");
        }
    });
});

回答by 1inMillion

Hope my blog can help you solve your issue http://gmarkmananquil.blogspot.com/2012/01/jplayers-circleplayer-ie-issue.htmland download the script. None of the above work for me so just try my work around a bit.

希望我的博客可以帮助您解决您的问题http://gmarkmananquil.blogspot.com/2012/01/jplayers-circleplayer-ie-issue.html并下载脚本。以上都不适合我,所以请尝试一下我的工作。

Here is the work-around I do in achieving auto play in this plugin, first add autoplay attributes to the defaults object variable in circleplayer script found in line 35.

这是我在此插件中实现自动播放的解决方法,首先将自动播放属性添加到第 35 行找到的 circleplayer 脚本中的默认对象变量。

defaults = {
            // solution: "flash, html", // For testing Flash with CSS3
            supplied: "mp3",
            solution: "flash,html",
            // Android 2.3 corrupts media element if preload:"none" is used.
            // preload: "none", // No point preloading metadata since no times are displayed. It helps keep the buffer state correct too.
            cssSelectorAncestor: "#cp_container_1",
            cssSelector: {
                play: ".cp-play",
                pause: ".cp-pause"
            },
            autoplay: false // add this autoplay default to false
        },

Second, modify the script in line 98 with this code,

其次,使用此代码修改第 98 行中的脚本,

if(self.options.autoplay){
     $(this).jPlayer("setMedia", self.media).jPlayer('play');
   }
else{
    $(this).jPlayer("setMedia", self.media);
   }

The example usage of the script would be like this,

脚本的示例用法如下所示,

var myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",{
        mp3: "music/booty me down.mp3"
    }, {
        cssSelectorAncestor: "#cp_container_1",
        swfPath: "js",
        wmode: "window", size : { width:"40px" },
                autoplay: true
    }
    );