Commit c5834d39 authored by liujiangnan's avatar liujiangnan

feat: 上传音频问题

parent d4a11193
...@@ -38,8 +38,14 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -38,8 +38,14 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
set audioUrl(url) { set audioUrl(url) {
this._audioUrl = url; this._audioUrl = url;
if (url) { if (url) {
this.httpHeadCall(this._audioUrl, flag => {
if (flag) {
this.audio.src = this._audioUrl; this.audio.src = this._audioUrl;
} else {
this.audio.src = this._audioUrl.replace("_l.", ".");
}
this.audio.load(); this.audio.load();
});
} }
this.init(); this.init();
} }
...@@ -68,6 +74,41 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy { ...@@ -68,6 +74,41 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
}; };
} }
httpHeadCall(requsetUrl: string, callback) {
let xhr = new XMLHttpRequest();
console.log("Status: Send Post Request to " + requsetUrl);
try {
xhr.onreadystatechange = () => {
try {
console.log('xhr.readyState: ', xhr.readyState);
if (xhr.readyState == 4) {
if ((xhr.status >= 200 && xhr.status < 400)) {
callback(true);
} else {
callback(false);
}
}
} catch (e) {
console.log(e)
}
};
xhr.open("HEAD", requsetUrl, true);
xhr.send();
xhr.timeout = 15000;
xhr.onerror = (e) => {
console.log("汪汪汪 posterror", e);
callback(false);
};
xhr.ontimeout = (e) => {
console.log("汪汪汪 ontimeout", e);
callback(false);
};
} catch (e) {
console.log("Send Get Request error: ", e)
}
}
init() { init() {
this.playIcon = 'play'; this.playIcon = 'play';
this.isPlaying = false; this.isPlaying = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment