AudioControl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. start : function() {
  6. // var SoundName = this.getAudioSourceByName("StartGun");
  7. // this.playSound(SoundName);
  8. },
  9. getAudioSourceByName:function(SoundName){
  10. if(this.node.getChildByName(SoundName).getComponent(cc.AudioSource) != null){
  11. var AudioSource = this.node.getChildByName(SoundName).getComponent(cc.AudioSource);
  12. return AudioSource;
  13. }
  14. // else{
  15. // cc.log(this.node.getChildByName(SoundName));
  16. // }
  17. },
  18. playSound:function(AudioSource){//播放音频剪辑。
  19. AudioSource.play();
  20. },
  21. stopSound:function(AudioSource){//停止当前音频剪辑。
  22. AudioSource.stop();
  23. },
  24. pauseSound:function(AudioSource){//暂停当前音频剪辑。
  25. AudioSource.pause();
  26. },
  27. resumeSound:function(AudioSource){//恢复播放。
  28. AudioSource.resume();
  29. },
  30. rewindSound:function(AudioSource){//从头开始播放。
  31. AudioSource.rewind();
  32. },
  33. getDurationSound:function(AudioSource){//获取当前音频的长度
  34. AudioSource.getDuration();
  35. }
  36. });