2015-02-10 101 views
4

** ** EDITED自动播放音频播放列表SoundManager2栏的UI

见乔恩·布莱克的回答下面为正确的解决方案......

我想在网站上使用SoundManager2 HTML5音频播放器为客户端但是客户坚持认为.mp3播放列表自动播放从曲目1开始并循环播放其余曲目。

原始脚本(网站上的soundmanager2.js)有一个autoPlay:false选项,但将其更改为true将不起作用。

这里是一个演示网站,我已经创建了利用SoundManager2的酒吧的UI(这是客户想要使用的样式)和脚本自动播放背景的MP3播放曲目的链接:website with working demo

正如你所看到的(听到的),背景音频自动播放很好,但不是像预期的那样通过音轨。如果您点击播放或点击轨道菜单中的播放列表项目,新点击的音频只播放背景音频,这是不希望的。我需要播放列表中的奥迪自动播放功能,以播放,暂停和通过声音栏自身选择不同的曲目。

Here is the link to original SoundManager2 project website for further info

我希望有人能告诉我如何创建一个函数或提供一个脚本,允许播放列表在播放页面时自动播放音频播放器UI。

我已经完成了一个TON搜索,并尝试编写和拼接脚本,但似乎无法得到这个工作!所以,我转向SO上的GENIUSES。

非常感谢您的帮助!

+0

尝试在bar-ui.js的第794行添加'autoPlay:true'。 – jmiraglia 2015-02-11 01:31:24

+0

@PatrickGunderson - 道歉,但整个代码是问题...我似乎无法得到autoPlay:真正发挥很好,工作。我试着设置文档中提供的函数,并在许多地方添加autoPlay:true,但无济于事。 – 2015-02-12 03:04:44

+0

@jmiraglia尝试在bar-ui.js的第794行添加'autoPlay:true',但仍然没有...感谢您的建议。我真的很感谢帮助人员 – 2015-02-12 03:05:26

回答

1

我已经想出了一个快速简单的方法来照顾你的困境。您只需在init()之后或bar-ui.jsline 1378之后添加此简单代码即可。

soundObject = makeSound(playlistController.getURL()); 
    soundObject.togglePause(); 

init()设置播放器,你只需要排队播放列表中的第一个音(与makeSound(playlistController.getURL()),然后播放(带togglePause())。

+0

我不能upvote(太新的网站,显然,但这工作完美,并已被标记为正确的解决方案!谢谢你这么多的时间和专业知识乔恩黑色和每个人谁共享答案 – 2015-02-12 19:00:27

0

要清楚地了解乔恩的解决方案: 添加两行,他提到了吧,ui.js并插入您的soundManager.setup

onready: function() { 
makeSound(playlistController.getURL()); 
togglePause(); 
} 

希望这有助于。

+1

你好John V,我不知道你说的是要添加你提供的代码,但我只是做了Jon Black建议的,并且它完美地工作。 – 2015-03-02 13:40:54

2

上述解决方案不适合我。 它改变按钮状态,但文件不播放。我在镀铬控制台中得到这个下划线错误

sound0: play(): Loading - attempting to play... 
bar-ui.js:125 Uncaught TypeError: Cannot read property 'on' of undefined 

并且在此显示autoPlay为true。

Object {url: "http://freshly-ground.com/data/audio/sm2/SonReal%20-%20LA%20%28Prod%20Chin%20Injetti%29.mp3", volume: 100, autoLoad: false, autoPlay: true, from: null…} 
+0

那么什么是解决方案? – 2016-10-06 08:04:58

0

我有Oj的奥巴西的同样的错误,当我试图乔恩·布莱克的解决方案,因此,而不是初始化后,立即将这两行()调用我加入他们的出口报关后,效果不错。 这里是我做编辑:

init(); // the init call 
 

 
    exports = { 
 
     // Per-instance events: window.sm2BarPlayers[0].on = { ... } etc. See global players.on example above for reference. 
 
     on: null, 
 
     actions: actions, 
 
     dom: dom, 
 
     playlistController: playlistController 
 
    }; 
 
    soundObject = makeSound(playlistController.getURL()); // these two lines make it autoplays the playlist from beginning 
 
    soundObject.togglePause(); // these two lines make it autoplays the playlist from beginning 
 
    return exports;

+0

如果包含部分代码在你的文章,这使得它独立于其他答案 - [来自评论](http://stackoverflow.com/review/late-answers/11995708) – Raju 2016-04-13 00:47:11

+0

完成。希望这会有所帮助。 – Mis94 2016-04-13 14:30:36

0

要使用SM2播放器自动播放单个文件,(而不是播放列表)包括在页面加载如下:

sm2BarPlayers[0].actions.play();