jQuery multimedia plug in jQuery Media Plugin using details
- 2020-05-07 19:15:06
- OfStack
jQuery Media Plugin is a web media player plug-in based on jQuery. It supports most web media players and media formats, such as Flash, Windows Media Player, Real Player, Quicktime, MP3,Silverlight, PDF. It automatically replaces the a tag with div based on the current script configuration and generates object, embed, and even iframe code. As for object or embed, jQuery Media automatically checks according to the current platform. The following code is the result of jQuery Media generation:
<div class="media">
<object width="450" height="250" attr1="attrValue1" attr2="attrValue2"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B">
<param name="src" value="myBetterMovie.mov">
<param name="autoplay" value="true">
<param name="param1" value="paramValue1">
<param name="param2" value="paramValue2">
<embed width="450" height="250" src="myBetterMovie.mov" autoplay="true"
attr1="attrValue1" attr2="attrValue2" param1="paramValue1" param2="paramValue2"
pluginspage="http://www.apple.com/quicktime/download/" > </embed>
</object>
</div>
specific use method
html markup code
<a class="media" href="sample.mov">My Quicktime Movie</a>
<a class="media" href="sample.swf">My Flash Movie</a>
<a class="media" href="sample.wma">My Audio File</a>
Initialization script:
$('.media').media();
options
Parameters can be configured either by a script object or by jQuery Metadata Plugin.
Global default value:
$.fn.media.defaults = {
preferMeta: 1, // If it is true, The token of meta Values take precedence over script objects
autoplay: 0, // Standardized across player Settings
bgColor: '#ffffff', // The background color
params: {}, // As a param Element to add to object The tag; Add to as a property embed The tag
attrs: {}, // Add to as a property object As well as embed In the
flashvars: {}, // As a flashvars Parameter or property added to flash In the
flashVersion: '7', // Minimum required flash version
// The default flash Video and mp3 player // @see: http://jeroenwijering.com/?item=Flash_Media_Player
flvPlayer: 'mediaplayer.swf',
mp3Player: 'mediaplayer.swf',
// Silverlight options // @see http://msdn2.microsoft.com/en-us/library/bb412401.aspx
silverlight: {
inplaceInstallPrompt: 'true', // Displays the installation prompt in the appropriate location
isWindowless: 'true', // Windowless mode
framerate: '24', // Maximum frame rate
version: '0.9', // Silverlight version onError: null, // onError The callback function
onLoad: null, // onLoad The callback function
initParams: null, // Object initialization parameters
userContext: null // to load Arguments to the callback function
}
};
We can also pass in some option parameters when executing the initialization script, as follows:
$('.media').media( { width: 400, height: 300, autoplay: true } );
Another example is the code:
$('.media').media({
width: 450,
height: 250,
autoplay: true,
src: 'myBetterMovie.mov',
attrs: { attr1: 'attrValue1', attr2: 'attrValue2' }, // object/embed attrs
params: { param1: 'paramValue1', param2: 'paramValue2' }, // object params/embed attrs
caption: false // supress caption text
});
'src' option
The src option specifies the address of the media file. It has no global default. If the value of the specified src option is not displayed, jQuery Media Plugin will use the value of href or src attribute instead.
player and format
jQuery Media Plugin is the default player and format as shown in the following table:
播放器 |
文件格式 |
Quicktime |
aif,aiff,aac,au,bmp,gsm,mov,mid, midi,mpg,mpeg,mp4,m4a,psd,qt,qtif, qif,qti,snd,tif,tiff,wav,3g2,3pg |
Flash |
flv, mp3, swf |
Windows Media Player |
asx, asf, avi, wma, wmv |
Real Player |
ra, ram, rm, rpm, rv, smi, smil |
Silverlight |
xaml |
iframe |
html, pdf |
As the table above shows, the mp3 format is automatically mapped to the flash player. Global configuration of $. fn. media. defaults. mp3Player MP3 media specified by mediaplayer. swf file. The swf file is a small mp3 and flash video player, can be downloaded from here: http: / / www longtailvideo. com players/jw - flv - player /
SWFObject
This script is very common and is used to embed Flash content into a web page. You don't have to worry about how Flash is embedded on different platforms. But this file is not required. If it is loaded, jQuery Media Plugin will use it, whereas jQuery Media Plugin will generate the object/embed tag in its default mode. More information is available: http: / / code google. com/p swfobject /
iframe Player
By default, the PDF and HTML formats are mapped to iframe. They will appear in iframe instead of object/embed tags.
Add or modify the format association
This action can be implemented by the plug-in's mapFormat method, for example
$.fn.media.mapFormat('mp3','quicktime');
Available players are uicktime, flash, realplayer, winmedia, silverlight, and iframe, ensuring that the player can play the file format associated with it.
Download
Download the jquery.media.js file directly, or download the history version on Github
Note:
This plugin will take < a > into < div > Thereby nesting multimedia content. This plugin is as easy to use as the other Jquery plugin 1.