()
| 41 | } |
| 42 | |
| 43 | override async apply(): Promise<void> { |
| 44 | // Check if the audio should have a fade time |
| 45 | const fadePosition = this.props.indexOf('fade'); |
| 46 | |
| 47 | if (Array.isArray(this.player)) { |
| 48 | if (fadePosition > -1) { |
| 49 | const fadeTime = this.props[fadePosition + 1]; |
| 50 | const duration = parseFloat((fadeTime.match(/\d*(\.\d*)?/) as RegExpMatchArray)[0]); |
| 51 | for (const player of this.player) { |
| 52 | // Only AudioPlayer has fadeOut, HTMLAudioElement doesn't |
| 53 | if (player instanceof AudioPlayer) { |
| 54 | await player.fadeOut(duration); |
| 55 | } |
| 56 | this.engine.removeMediaPlayer(this.type, player.dataset.key); |
| 57 | } |
| 58 | } else { |
| 59 | this.engine.removeMediaPlayer(this.type); |
| 60 | } |
| 61 | } else { |
| 62 | if (fadePosition > -1) { |
| 63 | const fadeTime = this.props[fadePosition + 1]; |
| 64 | const duration = parseFloat((fadeTime.match(/\d*(\.\d*)?/) as RegExpMatchArray)[0]); |
| 65 | // Only AudioPlayer has fadeOut, HTMLAudioElement doesn't |
| 66 | if (this.player instanceof AudioPlayer) { |
| 67 | await this.player.fadeOut(duration); |
| 68 | } |
| 69 | this.engine.removeMediaPlayer(this.type, this.media); |
| 70 | } else { |
| 71 | this.engine.removeMediaPlayer(this.type, this.media); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | override async didApply(): Promise<ActionApplyResult> { |
| 77 | const currentState = this.engine.state(this.type); |
no test coverage detected