0
我把HTML5和javascript應用放在一起,但由於某種原因,我得到一個來自chrome的異常錯誤,我不知道爲什麼。從鉻從chrome未捕獲的異常錯誤:無法設置null屬性'onclick'爲空
未捕獲的異常錯誤:不能設置爲空的特性 '的onclick'
這裏是我的html
<section class="experiment">
<div class="inner" style="height: 5em;">
<audio id="audio" autoplay controls></audio>
<button class="recorder-btn" id="record-audio">Record</button>
<button class="recorder-btn" id="stop-recording-audio" disabled>Stop</button>
<h2 id="audio-url-preview"></h2>
</div>
</section>
這裏是我JS
function getByID(id) {
return document.getElementById(id);
}
var recordAudio = getByID('record-audio'),
stopRecordingAudio = getByID('stop-recording-audio');
var audio = getByID('audio');
var audioConstraints = {
audio: true,
video: false
};
var audioStream;
var recorder;
recordAudio.onclick = function() {
if (!audioStream)
navigator.getUserMedia(audioConstraints, function(stream) {
if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
audioStream = stream;
audio.src = URL.createObjectURL(audioStream);
audio.muted = true;
audio.play();
// "audio" is a default type
recorder = window.RecordRTC(stream, {
type: 'audio'
});
recorder.startRecording();
}, function() {
});
else {
audio.src = URL.createObjectURL(audioStream);
audio.muted = true;
audio.play();
if (recorder) recorder.startRecording();
}
window.isAudio = true;
this.disabled = true;
stopRecordingAudio.disabled = false;
};