在soundmanger2 http://www.schillmania.com/projects/soundmanager2/
我创建了以下声音对象:
soundManager.setup({
url: '<?php echo $html->url('/') ?>js/swf/',
flashVersion: 9, // optional: shiny features (default = 8)
useFlashBlock: false, // optionally, enable when you're ready to dive in
allowScriptAccess: 'always',
/**
* read up on HTML5 audio support, if you're feeling adventurous.
* iPad/iPhone and devices without flash installed will always attempt to use it.
*/
onready: function() {
//defaultReader = 'Menshawi_16kbps';
soundManager.createSound({
id: defaultReader,
url: '<?php echo $html->url('/').'assets/audio/\'+defaultReader+\''.$mp3; ?>',
autoLoad: false,
autoPlay: true,
onload: function() {
//alert('The sound '+this.id+' loaded!');
},
onplay: function(){
$('#'+defaultReader).removeClass('sm2_link');
$('#'+defaultReader).addClass('sm2_playing');
$.cookie('defaultReader', defaultReader, { expires: 7, path: '/' });
$('#'+defaultReader).click(function(){
//alert('ho')
soundManager.togglePause(defaultReader);
return false;
});
},
onfinish: function(){
$('#'+defaultReader).addClass('sm2_link');
$('#'+defaultReader).removeClass('sm2_playing');
},
volume: 100
});
}
});
我想从另一个脚本标签访问soundManager.createSound创建的对象 例如:
<script>
theSoundObjectCreated.play()
</script>
答案 0 :(得分:3)
使用类似的东西设置你的声音管理器
window.soundManager = new SoundManager();
然后使用soundManager.setup(.....)
您可以使用
加载/创建声音soundManager.createSound({
id: 'some-id-for-your-sound',
url: "url-to-your-sound.mp3",
autoLoad: true,
autoPlay: false,
volume: 40
});
你可以用
播放那个声音 soundManager.getSoundById("some-id-for-your-sound").play()