Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fireballoon
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
fireballoon
Commits
4eb9a32d
Commit
4eb9a32d
authored
Jun 07, 2022
by
yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
410914b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
11 deletions
+52
-11
audio-recorder.component.ts
...src/app/common/audio-recorder/audio-recorder.component.ts
+52
-11
No files found.
form/src/app/common/audio-recorder/audio-recorder.component.ts
View file @
4eb9a32d
import
{
Component
,
EventEmitter
,
Input
,
OnDestroy
,
OnInit
,
Output
,
NgZone
,
OnChanges
}
from
'
@angular/core
'
;
import
{
NzMessageService
,
NzNotificationService
,
UploadFile
}
from
'
ng-zorro-antd
'
;
import
{
HttpClient
,
HttpEvent
,
HttpEventType
,
HttpRequest
}
from
'
@angular/common/http
'
;
import
{
environment
}
from
'
../../../environments/environment
'
;
import
{
Component
,
EventEmitter
,
Input
,
OnDestroy
,
OnInit
,
Output
,
NgZone
,
OnChanges
}
from
'
@angular/core
'
;
import
{
NzMessageService
,
NzNotificationService
,
UploadFile
}
from
'
ng-zorro-antd
'
;
import
{
HttpClient
,
HttpEvent
,
HttpEventType
,
HttpRequest
}
from
'
@angular/common/http
'
;
import
{
environment
}
from
'
../../../environments/environment
'
;
declare
var
Recorder
;
...
...
@@ -35,8 +35,14 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
set
audioUrl
(
url
)
{
this
.
_audioUrl
=
url
;
if
(
url
)
{
this
.
audio
.
src
=
this
.
_audioUrl
;
this
.
audio
.
load
();
this
.
httpHeadCall
(
this
.
_audioUrl
,
flag
=>
{
if
(
flag
)
{
this
.
audio
.
src
=
this
.
_audioUrl
;
}
else
{
this
.
audio
.
src
=
this
.
_audioUrl
.
replace
(
"
_l.
"
,
"
.
"
);
}
this
.
audio
.
load
();
});
}
this
.
init
();
}
...
...
@@ -54,9 +60,9 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
audioBlob
:
any
;
constructor
(
private
nzMessageService
:
NzMessageService
)
{
this
.
uploadUrl
=
(
<
any
>
window
).
courseware
.
uploadUrl
();
this
.
uploadData
=
(
<
any
>
window
).
courseware
.
uploadData
();
constructor
(
private
nzMessageService
:
NzMessageService
)
{
this
.
uploadUrl
=
(
<
any
>
window
).
courseware
.
uploadUrl
();
this
.
uploadData
=
(
<
any
>
window
).
courseware
.
uploadData
();
window
[
'
air
'
].
getUploadCallback
=
(
url
,
data
)
=>
{
this
.
uploadUrl
=
url
;
...
...
@@ -64,6 +70,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
()
{
this
.
playIcon
=
'
play
'
;
this
.
isPlaying
=
false
;
...
...
@@ -187,7 +228,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
this
.
nzMessageService
.
error
(
'
You can only upload Audio file ( mp3 | wav |ogg)
'
);
return
;
}
const
delta
=
25
;
const
delta
=
25
;
const
isOverSize
=
(
file
.
size
/
1024
/
1024
)
<
delta
;
if
(
!
isOverSize
)
{
this
.
nzMessageService
.
error
(
`audio file must smaller than
${
delta
}
MB!`
);
...
...
@@ -226,7 +267,7 @@ export class AudioRecorderComponent implements OnInit, OnChanges, OnDestroy {
p
=
0
;
}
// console.log(Math.floor(p * 100));
this
.
progress
=
Math
.
floor
(
p
*
100
);
this
.
progress
=
Math
.
floor
(
p
*
100
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment