API Docs for: 1.2
Show:

Audio Class

控管所有音樂資源的Class

Constructor

Audio

(
  • playlist
)

Parameters:

  • playlist Object

    全部要被播放的音樂和音效清單

Example:

new Framework.Audio({
  horse: {
      mp3: 'horse.mp3',
      ogg: 'horse.ogg',
      wav: 'horse.wav'
  }, song1:{
      mp3: 'song1.mp3',
      ogg: 'song1.ogg',
      wav: 'song1.wav'
  }, song2:{
      mp3: 'song2.mp3',
      ogg: 'song2.ogg',
      wav: 'song2.wav'
  }

});

Methods

mute

(
  • audioName
)

關閉音樂的音效(靜音)

Parameters:

  • audioName String

    歌曲的name

Example:

mute('horse');    

muteAll

()

關閉所有音樂的音效(靜音所有歌曲)

Example:

muteAll();    

openVolume

(
  • audioName
)

開起音樂的音效

Parameters:

  • audioName String

    歌曲的name

Example:

openVolume('horse');    

openVolumeAll

()

開起所有音樂的音效

Example:

openVolumeAll();    

pause

(
  • audioName
)

暫停被播放音樂

Parameters:

  • audioName String

    歌曲的name

Example:

pause('horse');  

pauseAll

()

暫停全部被播放音樂

Example:

pauseAll();  

play

(
  • audioArgs
)

播放音樂

Parameters:

  • audioArgs Object

    audioArgs.name為必要項, 並且需要可以從Constuctor提供的清單上找到, 否則會throw exception audioArgs可以加入任何一個W3C定義的option參數, 詳細請參考W3C網站 http://www.w3schools.com/tags/tag_audio.asp

Example:

 play({name: 'horse'}); 
 play({name: 'horse', loop: true}); 

resume

(
  • audioName
)

恢復播放被暫停的音樂, 若沒有被暫停, 則不會發生任何事情

Parameters:

  • audioName String

    歌曲的name resume('horse');

resumeAll

()

恢復播放被暫停的所有音樂

Example:

resumeAll();  

setErrorEvent

(
  • errorEvent
)

設定當音樂無法播放時, 要執行的callback

Parameters:

  • errorEvent Function

    音樂無法播放時, 要執行的callback

Example:

    setErrorEvent(function() {
        console.log('error');
    }); 

setVolume

(
  • audioName
  • volumeValue
)

設定音樂的音量

Parameters:

  • audioName String

    歌曲的name

  • volumeValue Number

    要設定的音量大小 0-1之間

Example:

setVolume('horse', 0);    //沒聲音 
setVolume('horse', 0.5);  
setVolume('horse', 1);    //最大聲

stop

(
  • audioName
)

停止被播放音樂

Parameters:

  • audioName String

    歌曲的name

Example:

stop('horse');  

stopAll

()

停止所有被播放音樂

Example:

stopAll();