Home Web Front-end HTML Tutorial How to call camera on mobile phone in HTML5?

How to call camera on mobile phone in HTML5?

Jun 23, 2020 pm 06:07 PM
html5 Mobile terminal

How to call camera on mobile phone in HTML5?

input calls device recording
HTML5 official document explains: The capture attribute is used to call the device's camera or microphone.
When accept="audio/or video/", capture has only two values, one is user, used to call the camera facing the face (such as the front camera of the mobile phone), and the other is environment, used to call the environment Camera (such as the rear camera of a mobile phone).
When accept="audio", the device microphone is called as long as there is capture, ignoring the user and environment values.
As for the camera and filesystem mentioned online, they were not officially mentioned.
Official document: www.w3.org/TR/2018/REC-html-media-capture-20180201/

iOS complies most with HTML5 specifications, followed by the X5 kernel, and Android webview is basically ignored capture.
Ideally, webview should be developed as follows:

1. When accept="image/", capture="user" calls the front camera, capture="other value" calls the rear camera
2. When accept="video/", capture="user" calls the front video recorder, capture="other value", calls the rear video recorder
3. When accept="image/,video/" , capture="user" calls the front camera, capture="other value" calls the rear camera, default camera, can switch recording
4. When accept="audio/*", capture=”Empty or any value”, call the recorder
5. When the input does not have capture, the folder options and camera or recorder options are given according to the accppt type
6. Access the folder can be checked when the input contains multiple With multiple files, only a single file can be used to call the system camera or recorder
7. When there is no multiple, only a single file can be used

Determine the device type

var ua = navigator.userAgent.toLowerCase();
if(ua.match(/android/i)) == "android") {
 alert("android");
}
if(ua.match(/iPhone/i)) == "iPhone") {
 alert("iPhone");
}
if(ua.match(/iPad/i)) == "iPad") {
 alert("iPad");
}
Copy after login
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="file" accept="image/*" capture="camera">  
    <input type="file" accept="video/*" capture="camcorder">  
    <input type="file" accept="audio/*" capture="microphone">  
</body>
</html>
<script>
    var file = document.querySelector(&#39;input&#39;);
        if (getIos()) {
            file.removeAttribute("capture"); //如果是ios设备就删除"capture"属性
        }
        function getIos() {
            var ua=navigator.userAgent.toLowerCase();
            if (ua.match(/iPhone\sOS/i) == "iphone os") {
                return true;
            } else {
                return false;
            }
        }
</script>
Copy after login

Recommended tutorial: "HTMLTutorial"

The above is the detailed content of How to call camera on mobile phone in HTML5?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles