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

How to install ionCube extension using pagoda

1. First install the pagoda Installation requirem...

Reasons and solutions for slow MySQL query stuck in sending data

Because I wrote a Python program and intensively ...

About the IE label LI text wrapping problem

I struggled with this for a long time, and after s...

Detailed Introduction to MySQL Innodb Index Mechanism

1. What is an index? An index is a data structure...

MySQL stored functions detailed introduction

Table of contents 1. Create a stored function 2. ...

WeChat applet calculator example

WeChat applet calculator example, for your refere...

Detailed steps to install CentOS7 system on VMWare virtual machine

Pre-installation work: Make sure vmware workstati...

MySQL big data query optimization experience sharing (recommended)

Serious MySQL optimization! If the amount of MySQ...

CocosCreator Typescript makes Tetris game

Table of contents 1. Introduction 2. Several key ...

Advanced techniques for using CSS (used in actual combat)

1. The ul tag has a padding value by default in Mo...

Detailed steps for installing and configuring MySQL 8.0 on CentOS

Preface Here are the steps to install and configu...

Win10 + Ubuntu20.04 LTS dual system boot interface beautification

Effect display The built-in boot interface is too...