Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sn03_playVideo
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
sn03_playVideo
Commits
bd2ddb2a
Commit
bd2ddb2a
authored
Aug 25, 2026
by
Jeff nan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat
parent
d8a8d701
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
137 deletions
+43
-137
upload-video.component.html
form/src/app/common/upload-video/upload-video.component.html
+5
-4
upload-video.component.ts
form/src/app/common/upload-video/upload-video.component.ts
+38
-133
No files found.
form/src/app/common/upload-video/upload-video.component.html
View file @
bd2ddb2a
<div
class=
"p-video-box"
>
<div
class=
"p-video-box"
>
<div
class=
"up-video"
style=
"display: flex;"
>
<div
class=
"up-video"
style=
"display: flex;"
>
<nz-upload
class=
"p-image-uploader"
[
nzDisabled
]="
uploading
"
[
nzShowUploadList
]="
false
"
nzAccept=
".mp4"
<nz-upload
class=
"p-image-uploader"
[
nzDisabled
]="
uploading
"
[
nzShowUploadList
]="
false
"
nzAccept=
".mp4"
(
nzChange
)="
handleChange
($
event
)"
[
nzCustomRequest
]="
customReq
"
[
nzAction
]="
uploadUrl
"
[
nzData
]="
uploadData
"
(
nzChange
)="
handleChange
($
event
)"
style=
"margin-right: 1rem"
>
style=
"margin-right: 1rem"
>
<button
type=
"button"
nz-button
nzType=
"default"
*
ngIf=
"showUploadBtn"
[
disabled
]="
uploading
"
<button
type=
"button"
nz-button
nzType=
"default"
*
ngIf=
"showUploadBtn"
[
disabled
]="
uploading
"
[
nzLoading
]="
uploading
"
>
[
nzLoading
]="
uploading
"
>
...
@@ -40,9 +41,9 @@
...
@@ -40,9 +41,9 @@
<i
nz-icon
nzType=
"loading"
nzTheme=
"outline"
></i>
Checking...
<i
nz-icon
nzType=
"loading"
nzTheme=
"outline"
></i>
Checking...
</div>
</div>
</div>
</div>
<div
class=
"p-preview"
*
ngIf=
"!uploading
&&playVedioUrl
"
>
<div
class=
"p-preview"
*
ngIf=
"!uploading
&& videoUrl
"
>
<video
crossorigin=
"anonymous"
[
src
]="
playVedioUrl
"
controls
#
videoNode
></video>
<video
crossorigin=
"anonymous"
[
src
]="
safeVideoUrl
(
videoUrl
)
"
controls
#
videoNode
></video>
<!-- <video crossorigin="anonymous" [src]="
safeVideoUrl()
" controls #videoNode></video> -->
<!-- <video crossorigin="anonymous" [src]="
videoUrl
" controls #videoNode></video> -->
</div>
</div>
</div>
</div>
<div
[
style
.
display
]="!
checkVideoExists
?'
none
'
:
''"
>
<div
[
style
.
display
]="!
checkVideoExists
?'
none
'
:
''"
>
...
...
form/src/app/common/upload-video/upload-video.component.ts
View file @
bd2ddb2a
...
@@ -5,38 +5,7 @@ import {HttpClient, HttpHeaders, HttpRequest, HttpEvent, HttpEventType, HttpResp
...
@@ -5,38 +5,7 @@ import {HttpClient, HttpHeaders, HttpRequest, HttpEvent, HttpEventType, HttpResp
import
{
NzMessageService
,
UploadChangeParam
,
UploadFile
,
UploadFileStatus
,
UploadXHRArgs
}
from
'
ng-zorro-antd
'
;
import
{
NzMessageService
,
UploadChangeParam
,
UploadFile
,
UploadFileStatus
,
UploadXHRArgs
}
from
'
ng-zorro-antd
'
;
import
{
DomSanitizer
,
SafeResourceUrl
}
from
'
@angular/platform-browser
'
;
import
{
DomSanitizer
,
SafeResourceUrl
}
from
'
@angular/platform-browser
'
;
import
cryptoJs
from
'
crypto-js
'
;
import
{
v4
}
from
'
uuid
'
;
function
httpHeadCall
(
requsetUrl
,
callback
)
{
let
xhr
=
new
XMLHttpRequest
();
try
{
xhr
.
onreadystatechange
=
()
=>
{
try
{
if
(
xhr
.
readyState
==
4
)
{
if
((
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callback
(
true
);
}
else
{
callback
(
false
);
}
}
}
catch
(
e
)
{
callback
(
false
);
}
};
xhr
.
open
(
"
HEAD
"
,
requsetUrl
,
true
);
xhr
.
send
();
xhr
.
timeout
=
15000
;
xhr
.
onerror
=
(
e
)
=>
{
callback
(
false
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
callback
(
false
);
};
}
catch
(
e
)
{
callback
(
false
);
}
}
@
Component
({
@
Component
({
...
@@ -102,24 +71,13 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
...
@@ -102,24 +71,13 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
this
.
uploadUrl
=
(
<
any
>
window
).
courseware
.
uploadVideoUrl
();
this
.
uploadUrl
=
(
<
any
>
window
).
courseware
.
uploadVideoUrl
();
this
.
uploadData
=
(
<
any
>
window
).
courseware
.
uploadData
();
this
.
uploadData
=
(
<
any
>
window
).
courseware
.
uploadData
();
window
[
'
air
'
].
getUploadVideoCallback
=
(
url
,
data
)
=>
{
window
[
'
air
'
].
getUploadVideoCallback
=
(
url
,
data
)
=>
{
this
.
uploadUrl
=
url
;
this
.
uploadUrl
=
url
;
this
.
uploadData
=
data
;
this
.
uploadData
=
data
;
};
};
}
}
ngOnInit
()
{
ngOnInit
()
{
this
.
playVedioUrl
=
this
.
videoUrl
.
replace
(
`_h.mp4`
,
`_l.mp4`
);;
}
md5Short
(
str
,
_salt
)
{
return
cryptoJs
.
MD5
(
str
+
_salt
).
toString
();
}
}
ngOnChanges
()
{
ngOnChanges
()
{
// if (!this.videoFile || this.showUploadBtn) {
// if (!this.videoFile || this.showUploadBtn) {
...
@@ -132,94 +90,13 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
...
@@ -132,94 +90,13 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
URL
.
revokeObjectURL
(
this
.
videoUrl
);
URL
.
revokeObjectURL
(
this
.
videoUrl
);
}
}
playVedioUrl
=
''
;
safeVideoUrl
(
url
)
{
safeVideoUrl
()
{
return
this
.
sanitization
.
bypassSecurityTrustResourceUrl
(
url
);
// `${url}`;
const
url
=
this
.
videoUrl
.
replace
(
`_h.mp4`
,
`.mp4`
).
replace
(
`.mp4`
,
`_l.mp4`
);
console
.
log
(
`=============safeVideoUrl==============`
,
url
);
httpHeadCall
(
url
,
(
flag
)
=>
{
if
(
flag
)
{
this
.
playVedioUrl
=
url
;
}
else
{
setTimeout
(()
=>
{
this
.
safeVideoUrl
();
},
500
);
}
});
return
this
.
playVedioUrl
;
}
}
videoLoadedMetaData
()
{
videoLoadedMetaData
()
{
}
}
// fileToBlob(file) {
// let reader = new FileReader();
// reader.addEventListener('load', (e) => {
// let base64 = e.target.result;
// let blob = new Blob([base64], { type: file.type });
// console.log("Blob对象", blob);
// })
// reader.readAsDataURL(file)
// }
customReq
(
item
:
UploadXHRArgs
)
{
// md5值计算
const
protocolStr
=
document
.
location
.
protocol
;
const
baseCDN
=
`
${
protocolStr
}
//teach.cdn.ireadabc.com`
;
const
baseAPI
=
`
${
protocolStr
}
//openapi.iteachabc.com`
;
const
fileName
=
v4
().
replace
(
/-/g
,
""
);
httpHeadCall
(
`
${
baseCDN
}
/
${
fileName
}
_h.mp4`
,
(
flag
)
=>
{
if
(
flag
)
{
item
.
onSuccess
!
({
url
:
`
${
baseCDN
}
/
${
fileName
}
.mp4`
},
item
.
file
!
,
event
);
}
else
{
this
.
http
.
get
(
`
${
baseAPI
}
/oss/timestamp`
,
{}).
subscribe
((
tmps
:
string
)
=>
{
const
sign
=
cryptoJs
.
MD5
(
tmps
+
"
iplayABC2019
"
).
toString
();
const
params
=
new
HttpParams
().
set
(
'
sign
'
,
sign
).
set
(
'
stmp
'
,
tmps
);
this
.
http
.
get
(
`
${
baseAPI
}
/oss/signature`
,
{
params
}).
subscribe
((
res
)
=>
{
const
serve
=
res
[
'
data
'
];
const
formData
=
new
FormData
();
formData
.
append
(
'
key
'
,
fileName
+
`.mp4`
);
formData
.
append
(
'
bucket
'
,
`iplayabc-worker-queue-videolmh`
);
formData
.
append
(
'
OSSAccessKeyId
'
,
serve
.
OSSAccessKeyId
);
formData
.
append
(
'
policy
'
,
serve
.
policy
);
formData
.
append
(
'
Signature
'
,
serve
.
signature
);
formData
.
append
(
'
success_action_status
'
,
'
200
'
);
formData
.
append
(
'
file
'
,
item
.
file
as
any
);
//设置cors跨域请求
const
headerstemp
=
new
HttpHeaders
({
'
Access-Control-Allow-Origin
'
:
'
*
'
});
item
.
action
=
`
${
protocolStr
}
//iplayabc-worker-queue-videolmh.oss-cn-beijing.aliyuncs.com`
;
const
req
=
new
HttpRequest
(
'
POST
'
,
item
.
action
!
,
formData
,
{
headers
:
headerstemp
,
reportProgress
:
true
,
//进度条
// withCredentials: true
});
// Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
return
this
.
http
.
request
(
req
).
subscribe
(
(
event
:
HttpEvent
<
{}
>
)
=>
{
if
(
event
.
type
===
HttpEventType
.
UploadProgress
)
{
if
(
event
.
total
!
>
0
)
{
// tslint:disable-next-line:no-any
(
event
as
any
).
percent
=
(
event
.
loaded
/
event
.
total
!
)
*
100
;
}
item
.
onProgress
!
(
event
,
item
.
file
!
);
}
else
if
(
event
instanceof
HttpResponse
)
{
item
.
onSuccess
!
({
url
:
`
${
baseCDN
}
/
${
fileName
}
.mp4`
},
item
.
file
!
,
event
);
}
},
err
=>
{
console
.
log
(
err
);
item
.
onError
!
(
err
,
item
.
file
!
);
}
);
});
});
}
});
};
handleChange
(
info
:
UploadChangeParam
/* { type: string, file: UploadFile, event: any }*/
):
void
{
handleChange
(
info
:
UploadChangeParam
/* { type: string, file: UploadFile, event: any }*/
):
void
{
console
.
log
(
info
);
console
.
log
(
info
);
...
@@ -235,8 +112,7 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
...
@@ -235,8 +112,7 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
this
.
uploadSuccess
(
info
.
file
);
this
.
uploadSuccess
(
info
.
file
);
break
;
break
;
case
'
progress
'
:
case
'
progress
'
:
this
.
progress
=
info
.
event
.
percent
;
this
.
doProgress
(
info
.
event
.
percent
);
// this.doProgress(this.progress);
break
;
break
;
}
}
}
}
...
@@ -277,10 +153,38 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
...
@@ -277,10 +153,38 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
this
.
videoFile
=
null
;
this
.
videoFile
=
null
;
// this.updateSource(url);
// this.updateSource(url);
this
.
videoUrl
=
file
.
response
.
url
;
this
.
videoUrl
=
file
.
response
.
url
;
this
.
videoUploaded
.
emit
(
file
.
response
);
// console.log(this.picUrl)
setTimeout
(()
=>
{
// this.uploadFinished(url);
this
.
safeVideoUrl
();
// if (!inOSS) {
},
2000
);
const
vid
=
document
.
createElement
(
'
video
'
);
vid
.
addEventListener
(
'
loadedmetadata
'
,
()
=>
{
const
height
=
vid
.
videoHeight
;
const
width
=
vid
.
videoWidth
;
let
duration
=
vid
.
duration
;
if
(
duration
)
{
duration
=
duration
*
1000
;
}
file
.
height
=
height
;
file
.
width
=
width
;
file
.
duration
=
duration
;
vid
.
preload
=
'
none
'
;
vid
.
src
=
''
;
vid
.
remove
();
this
.
videoUploaded
.
emit
(
file
.
response
);
// this.resService.updateVideo(id, {width, height, duration}).then( () => {
// this.videoUploaded.emit({res_id: id, id, name, hash, url});
// });
});
vid
.
src
=
file
.
response
.
url
;
// } else {
// this.videoUploaded.emit(file.response);
// }
}
}
...
@@ -297,7 +201,8 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
...
@@ -297,7 +201,8 @@ export class UploadVideoComponent implements OnChanges, OnDestroy, OnInit {
doProgress
=
(
p
)
=>
{
doProgress
=
(
p
)
=>
{
if
(
p
>
1
)
{
if
(
p
>
1
)
{
p
=
1
;
this
.
progress
=
p
;
return
;
}
}
if
(
p
<
0
)
{
if
(
p
<
0
)
{
p
=
0
;
p
=
0
;
...
...
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