MCPcopy Create free account
hub / github.com/codecombat/codecombat / playAmbientSound

Method playAmbientSound

app/views/play/CampaignView.js:2081–2099  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2079 }
2080
2081 playAmbientSound () {
2082 if (!me.get('volume')) { return }
2083 if (this.ambientSound) { return }
2084 const file = this.campaign?.get('ambientSound')?.[AudioPlayer.ext.substr(1)]
2085 if (!file) { return }
2086 const src = `/file/${file}`
2087 if (!AudioPlayer.getStatus(src)?.loaded) {
2088 AudioPlayer.preloadSound(src)
2089 Backbone.Mediator.subscribeOnce('audio-player:loaded', this.playAmbientSound, this)
2090 return
2091 }
2092 if (this.isMusicPlaybackBlockedByAutoplay()) {
2093 this.pendingAmbientSound = true
2094 this.ensureMusicGestureListeners()
2095 return
2096 }
2097 this.ambientSound = createjs.Sound.play(src, { loop: -1, volume: 0.1 })
2098 createjs.Tween.get(this.ambientSound).to({ volume: 0.5 }, 1000)
2099 }
2100
2101 playMusic () {
2102 const musicFile = '/music/music-menu'

Callers 3

applyCampaignStylesMethod · 0.95
updateVolumeMethod · 0.95

Calls 3

getMethod · 0.45

Tested by

no test coverage detected