This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`<button (click)='onClick()' [disabled]='loadingSample'>play</button>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
playSample() { | |
let bufferSource = this.audioContext.createBufferSource(); | |
bufferSource.buffer = this.audioBuffer; | |
bufferSource.connect(this.audioContext.destination); | |
bufferSource.start(0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppComponent implements OnInit { | |
private audioContext: AudioContext; | |
private loadingSample: boolean = false; | |
private audioBuffer: AudioBuffer; | |
ngOnInit() { | |
this.audioContext = new AudioContext(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`<button [disabled]='loadingSample'>play</button>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngOnInit() { | |
this.audioContext = new AudioContext(); | |
this.loadingSample = true; | |
this.fetchSample() | |
.then((audioBuffer) => { | |
this.loadingSample = false; | |
this.audioBuffer = audioBuffer; | |
}) | |
.catch((error) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchSample(): Promise<AudioBuffer> { | |
return fetch(‘samples/snare.wav’) | |
.then((response) => response.arrayBuffer()) | |
.then((buffer) => { | |
return new Promise((resolve, reject) => { | |
this.audioContext.decodeAudioData(buffer, resolve, reject); | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from ‘angular2/core’; | |
@Component({ | |
selector: 'my-app', | |
template: `<h1>My First Angular2 App</h1>` | |
}) | |
export class AppComponent implements OnInit { | |
private audioContext: AudioContext; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from ‘angular2/core’; | |
@Component({ | |
selector: ‘my-app’, | |
template: `<h1>My First Angular 2 App</h1>` | |
}) | |
export class AppComponent { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_five(n): | |
return n+5 | |
def add_seven(n): | |
return n+7 | |
def add_nine(n): | |
return n+9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fail(): | |
return 'this will break |