我的问题是,一旦音轨停止播放,你再次点击播放按钮,这首歌就不会播放。通过这个我的意思是我没有听到任何播放,但第一次工作正常。
soundManager.url = '{{ asset('bundles/bm/swf/')}}';
soundManager.onload = (function() {
var preview = soundManager.createSound({
id: 'previewer',
url: '{{ path('play_track', { 'id' : track.id}) }}',
type: 'audio/mp3'
});
preview.options.whileplaying = function() {
var current = new Date (this.position),
minutes = current.getMinutes(),
seconds = current.getSeconds();
var current = minutes + ':' + seconds;
$('.editable').html(current);
}
$('.bigPlay').click(function(e){
if($(this).hasClass('playbtn')) {
e.stopPropagation();
$(this).removeClass('playbtn').addClass('pausebtn');
preview.play({
onfinish: function() {
preview.stop();
$('.bigPlay').removeClass('pausebtn').addClass('playbtn');
}
});
return false;
}
if($(this).hasClass('pausebtn')) {
e.stopPropagation();
$('.bigPlay').removeClass('pausebtn').addClass('playbtn');
preview.stop();
return false;
}
});
});
控制台显示:
-- SoundManager 2: HTML5 support tests (/^(probably|maybe)$/i): mp3: true (preferring flash), mp4: true (preferring flash), ogg: true, wav: true -- soundmanager2.js:1110
-- SoundManager 2 V2.97a.20120527 (AS2/Flash 8) + HTML5 audio, normal polling -- soundmanager2.js:1110
soundManager::createMovie(): Trying to load /bundles/bm/swf/soundmanager2_debug.swf soundmanager2.js:1110
soundManager::initMovie(): Waiting for ExternalInterface call from Flash... soundmanager2.js:1112
soundManager::externalInterfaceOK() (~0 ms) soundmanager2.js:1112
soundManager::init() soundmanager2.js:1112
soundManager: Attempting JS to Flash call... soundmanager2.js:1112
(Flash): SM2 SWF V2.97a.20120527 (AS2/Flash 8) soundmanager2.js:1112
(Flash): JS to/from Flash OK soundmanager2.js:1112
Flash security sandbox type: remote soundmanager2.js:1112
(Flash): Enabling polling, 50 ms interval soundmanager2.js:1112
-- SoundManager 2 loaded (OK) -- soundmanager2.js:1110
soundManager::initComplete(): calling soundManager.onload() soundmanager2.js:1110
soundManager.createSound(): previewer (/app_dev.php/track/play/4.mp3) soundmanager2.js:1110
SMSound() merged options: {
id: previewer,
url: /app_dev.php/track/play/4.mp3,
type: audio/mp3,
autoLoad: false,
autoPlay: false,
loops: 1,
multiShot: true,
multiShotEvents: false,
pan: 0,
stream: true,
usePolicyFile: false,
volume: 100
} soundmanager2.js:1112
Loading sound previewer via HTML5 soundmanager2.js:1112
creating HTML5 Audio() element with URL: /app_dev.php/track/play/4.mp3 soundmanager2.js:1112
HTML5::adding event listeners: previewer soundmanager2.js:1112
SMSound.load(): /app_dev.php/track/play/4.mp3 soundmanager2.js:1110
HTML5::load: previewer soundmanager2.js:1112
0 soulshaka-club-69-underground-mix:529
soundManager.onload() complete soundmanager2.js:1110
HTML5::loadstart: previewer soundmanager2.js:1112
SMSound.play(): "previewer" is loading - attempting to play.. soundmanager2.js:1110
SMSound.play(): "previewer" is starting to play soundmanager2.js:1112
setPosition(0): delaying, sound not ready soundmanager2.js:1112
HTML5::play: previewer, /app_dev.php/track/play/4.mp3 soundmanager2.js:1112
HTML5::waiting: previewer soundmanager2.js:1112
HTML5::loadedmetadata: previewer soundmanager2.js:1112
HTML5::loadeddata: previewer soundmanager2.js:1112
SMSound._onload(): "previewer" loaded. soundmanager2.js:1110
HTML5::canplay: previewer, /app_dev.php/track/play/4.mp3 soundmanager2.js:1112
HTML5::playing: previewer soundmanager2.js:1112
HTML5::suspend: previewer soundmanager2.js:1112
HTML5::suspend: previewer soundmanager2.js:1112
HTML5::suspend: previewer soundmanager2.js:1112
HTML5::suspend: previewer soundmanager2.js:1112
HTML5::ended: previewer soundmanager2.js:1112
SMSound._onfinish(): "previewer" soundmanager2.js:1112
SMSound.play(): "previewer" soundmanager2.js:1112
SMSound.play(): "previewer" is starting to play soundmanager2.js:1112
setPosition(0): setting position soundmanager2.js:1112
HTML5::play: previewer, /app_dev.php/track/play/4.mp3 soundmanager2.js:1112
HTML5::playing: previewer soundmanager2.js:1112
setPosition(0): setting position soundmanager2.js:1112
SMSound.play(): "previewer" soundmanager2.js:1112
SMSound.play(): "previewer" is starting to play soundmanager2.js:1112
setPosition(0): setting position soundmanager2.js:1112
任何帮助都会很棒。
答案 0 :(得分:2)
所以我不是SoundManager2的专家,但我能够修复一个像这样的行为的bug。对我来说这是我的服务器。返回音频数据时需要设置HTTP标头。
技术说明部分列出了您需要提供的一些基本内容: http://www.schillmania.com/projects/soundmanager2/doc/technotes/
获得正确的标题将播放音频。我需要添加几个标题才能让SoundManger2让我播放两次声音。以下是我的浏览器提取和mpeg文件的响应标题。我可能需要也可能不需要“Accept-Ranges”标题:
Accept-Ranges:bytes
Connection:close
Content-Length:30592
Content-Type:audio/mpeg
Server:Jetty(6.1.x)