How to use the flash plug-in to call the PC's camera and embed it into the TML page

How to use the flash plug-in to call the PC's camera and embed it into the TML page
Preface

The reason for writing this article is mainly because the team leader put forward a new requirement - using the browser to call the computer's camera to realize the function of instant photo taking. I checked a lot of information on the Internet, and for various reasons, I finally chose to use the flash plug-in to call the PC's camera. Of course, this requirement is based on the B/S architecture, so I was thinking about how to embed it into the front-end HTML page.

Off topic

Of course, encapsulation has not been considered here. The main purpose is implementation first, and subsequent work will be abstracted according to the business and encapsulated into common components. Okay, enough nonsense, let’s get to the point.

Embed plugin

Using the object and embed tags

Code Showcase

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><div style="margin-top:-30px;margin-left:-120px;">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
width="490" height="390" id="Untitled-1" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="cam.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="cam.swf" quality="high" bgcolor="#ffffff" width="490" height="390" name="cam" align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</div></span>

This method uses the Object and Embed tags. You can see that many parameters of the object and many attributes of the embed are repeated. Browser compatibility: some browsers support object, some support embed, which is why you need to modify both places when modifying Flash parameters. This method is the official method of Macromedia, which guarantees the functionality of Flash to the greatest extent and has no compatibility issues.

But now it seems that there are still big problems.

First, it cannot pass validation because the embed tag embedded for compatibility does not comply with the W3C specification. Of course, if you don’t care about standards or not, that’s another matter.

Secondly, for various reasons, Microsoft restricted the usage mode of IE's ActiveX after SP2, that is, there is a virtual box in the ActiveX on the page, and the user needs to click once to interact normally. Flash is embedded into the web page as an ActiveX, so it will also be implicated. This problem can only be solved by embedding Flash through JS.

Again, there is no Flash version detection. If the browser's flash plug-in version is not enough, your swf file may not be displayed normally, or an ActiveX confirmation installation box may pop up - this box is very scary for many users.

Use only the object tag

Code Showcase

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><div style="margin-top:-30px;margin-left:-120px;">
<object type="application/x-shockwave-flash data="c.swf?path=cam.swf" width="490" height="390">
<param name="cam" value="c.swf?path=cam.swf" />
<img src="defqr.png"
width="550" height="400" alt="" />
</object>
</div></span>

This method only uses the Object tag, which is actually Flash satay. Since there is no embed tag, it can pass the verification. It is a standard method of embedding Flash. The browser compatibility is also good. It looks almost perfect, but there are still problems.

First, you need a holder swf to load your target swf to ensure the stream capability in IE. If you need to pass parameters through flashvars, or interact with the JS of the page, it will be very troublesome.

Secondly, like the first method, an ActiveX prompt box will pop up without version detection.

Again, some lower-version browsers (such as lower-version Safari, etc.) do not recognize this approach and are not compatible with it.

Use only the embed tag

Code Showcase

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><div style="margin-top:0px;margin-left:-70px;">
<embed id="cam" src="cam.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="450" ​​height="350" name="webcam" align="middle" wmode="transparent" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="width=490&height=390&objid=cameradialog">
</div></span>

This method only uses the Embed tag. Compared with the effect, it is still very good. The browser compatibility is also good and can be loaded. Of course, since the embed tag does not comply with W3C specifications, this method is not recommended.

Embed using JavaScript

There are many ways to use JS to load Flash plug-ins on the Internet, and there are also many good JS plug-ins for you to choose from. I will only briefly introduce SWFObject here.

First, you need to download a SWFObject plug-in package, which contains a JS script, which is the script file you need to import. It also includes two HTML examples that you can imitate. Of course, you can also go to SWFObject's website to learn more. Please click here.

Code Showcase

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.registerObject("myId", "9.0.0", "cam.swf");
</script></span>


Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><div style="margin-top:-30px;margin-left:-120px;">
<object id="myId" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="490" height="390">
<param name="movie" value="cam.swf" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="cam.swf" width="490" height="390">
<!--<![endif]-->
<div>
<h1>Alternative content</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div></span>

Rendering

Conclusion <br />Compared with these methods, I recommend using JS embedding to load the Flash plug-in. This method not only ensures the realization of all the functions of Flash, but also performs well in terms of compatibility with various browsers. JS can also provide more extended functions, and more importantly, it can be reused by more people, reducing unnecessary redundant code.

Plug-in download address: SWFObject

<<:  Enterprise-level installation tutorial using LAMP source code

>>:  How to create Baidu dead link file

Recommend

Automatic file synchronization between two Linux servers

When server B (172.17.166.11) is powered on or re...

HTML table markup tutorial (16): title horizontal alignment attribute ALIGN

By default, the table title is horizontally cente...

Implementation of MySQL's MVCC multi-version concurrency control

1 What is MVCC The full name of MVCC is: Multiver...

MySQL Installer Community 5.7.16 installation detailed tutorial

This article records the detailed tutorial of MyS...

Analysis and practice of React server-side rendering principle

Most people have heard of the concept of server-s...

Mac installation mysqlclient process analysis

Try installing via pip in a virtual environment: ...

A simple example of creating a thin line table in html

Regarding how to create this thin-line table, a s...

CSS pseudo-element::marker detailed explanation

This article will introduce an interesting pseudo...

MySQL 5.7.17 latest installation tutorial with pictures and text

mysql-5.7.17-winx64 is the latest version of MySQ...

A brief analysis of the count tracking of a request in nginx

First, let me explain the application method. The...

Using HTML+CSS to track mouse movement

As users become more privacy-conscious and take m...

A brief discussion on Flink's fault-tolerant mechanism: job execution and daemon

Table of contents 1. Job Execution Fault Toleranc...

Detailed installation instructions for the cloud server pagoda panel

Table of contents 0x01. Install the Pagoda Panel ...

Summary of learning HTML tags and basic elements

1. Elements and tags in HTML <br />An eleme...