2012-09-14 48 views
0

在soundmanger2 http://www.schillmania.com/projects/soundmanager2/如何訪問Sound Manager2創建的聲音對象?

我創建了下面的聲音對象:

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> 

回答

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