1
|
cordova plugin add cordova-plugin-media-capture
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<!DOCTYPE html>
<html>
<head>
<title>Capture Audio</title>
<meta http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
>
<script type=
"text/javascript"
charset=
"utf-8"
src=
"cordova.js"
></script>
<script type=
"text/javascript"
charset=
"utf-8"
>
function
audioCapture() {
//開始錄音(最長錄製時間:15秒)
navigator.device.capture.captureAudio(onSuccess, onError, {duration: 15});
//錄製成功
function
onSuccess(mediaFiles) {
var
i, path, len;
//遍歷獲取錄製的文件(iOS只支持一次錄製一個視頻或音頻)
for
(i = 0, len = mediaFiles.length; i < len; i += 1) {
console.log(mediaFiles);
path = mediaFiles[i].fullPath;
alert(
"錄製成功!\n\n"
+
"文件名:"
+ mediaFiles[i].name +
"\n"
+
"大小:"
+ mediaFiles[i].size +
"\n\n"
+
"localURL地址:"
+ mediaFiles[i].localURL +
"\n\n"
+
"fullPath地址:"
+ path);
}
}
//錄製失敗
function
onError(error) {
alert(
'錄製失敗!錯誤碼:'
+ error.code);
}
}
</script>
</head>
<body style=
"padding-top:50px"
>
<button style=
"font-size:23px;"
onclick=
"audioCapture();"
>開始錄音</button>
</body>
</html>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<!DOCTYPE html>
<html>
<head>
<title>Capture Video</title>
<meta http-equiv=
"Content-type"
content=
"text/html; charset=utf-8"
>
<script type=
"text/javascript"
charset=
"utf-8"
src=
"cordova.js"
></script>
<script type=
"text/javascript"
charset=
"utf-8"
>
function
videoCapture() {
//開始錄像(最長錄製時間:15秒)
navigator.device.capture.captureVideo(onSuccess, onError, {duration: 15});
//錄製成功
function
onSuccess(mediaFiles) {
var
i, path, len;
//遍歷獲取錄製的文件(iOS只支持一次錄製一個視頻或音頻)
for
(i = 0, len = mediaFiles.length; i < len; i += 1) {
console.log(mediaFiles);
path = mediaFiles[i].fullPath;
alert(
"錄製成功!\n\n"
+
"文件名:"
+ mediaFiles[i].name +
"\n"
+
"大小:"
+ mediaFiles[i].size +
"\n\n"
+
"localURL地址:"
+ mediaFiles[i].localURL +
"\n\n"
+
"fullPath地址:"
+ path);
}
}
//錄製失敗
function
onError(error) {
alert(
'錄製失敗!錯誤碼:'
+ error.code);
}
}
</script>
</head>
<body style=
"padding-top:50px"
>
<button style=
"font-size:23px;"
onclick=
"videoCapture();"
>開始錄像</button>
</body>
</html>
|