我有两个Angular组件app-image-input和app-button。我将模板中的app-button用于app-image-input,如下所示。
AppButtonComponent
appButton.html
<button type="button" (click)="buttonClicked.emit()">{{label}}</button>
Run Code Online (Sandbox Code Playgroud)
appButton.ts
@Component({
selector: 'app-button',
templateUrl: './appButton.html'
})
export class AppButtonComponent {
@Input()
label : string
@Input()
enabled : boolean
@Output()
buttonClicked = new EventEmitter()
}
Run Code Online (Sandbox Code Playgroud)
AppImageInputComponent
appImageInput.html
<div class="take-photo">
<span>Photo</span><input type="file" accept="image/*" capture>
</div>
<hr class="hr">
<div class="inner">
<app-button class="submit" label="Submit" (buttonClicked)="submitClk()"></app-button>
<app-button label="Cancel" (buttonClicked)="cancelClk()"></app-button>
</div>
Run Code Online (Sandbox Code Playgroud)
应用模块
app.module.ts
// ..... imports go here.
@NgModule({
declarations: [AppButtonComponent, AppImageInputComponent],
entryComponents: [AppButtonComponent, AppImageInputComponent],
imports: [
FormsModule,
BrowserModule,
],
providers: [],
bootstrap: []
})
export class AppModule { …Run Code Online (Sandbox Code Playgroud) 从音频文件中提取数据字节时,以下两种实现有什么区别?
该文件是一个.wav文件,我想只提取数据,没有标题或任何其他东西.
实施1:
public byte[] extractAudioFromFile(String filePath) {
try {
// Get an input stream on the byte array
// containing the data
File file = new File(filePath);
final AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(file);
byte[] buffer = new byte[4096];
int counter;
while ((counter = audioInputStream.read(buffer, 0, buffer.length)) != -1) {
if (counter > 0) {
byteOut.write(buffer, 0, counter);
}
}
audioInputStream.close();
byteOut.close();
} catch (Exception e) {
System.out.println(e);
System.exit(0);
}// end catch
return ((ByteArrayOutputStream) byteOut).toByteArray();
}
Run Code Online (Sandbox Code Playgroud)
实施2:
public …Run Code Online (Sandbox Code Playgroud)