gpt4 book ai didi

javascript - 如何访问Sound Manager2创建的声音对象?

转载 作者:行者123 更新时间:2023-11-28 20:51:06 24 4
gpt4 key购买 nike

在 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>

最佳答案

用这样的东西设置你的声音管理器

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()

关于javascript - 如何访问Sound Manager2创建的声音对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12416888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com