JW Player for Flash and HTML5
Release 5.3
Embedding Guide
September 29, 2010
CONTENTS
1 Embedding the player 1
1.1 Upload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 SWFObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Embed tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 JW Embedder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Player API 11
2.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Selecting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.5 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.6 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
i
ii
CHAPTER
ONE
EMBEDDING THE PLAYER
Like every other Flash object, the JW Player has to be embedded into the HTML of a webpage using specific embed
codes. Overall, there are three methods for embedding the JW Player:
• Using a generic JavaScript embedder (like SWFObject).
• Using a HTML tag (like <object> or <embed>).
• Using the JW Player’s own JavaScript embedder (jwplayer.js).
We recommend using the included JW Player Embedder. It can detect if a browser supports Flash, it ensures that the
player’s Player API works and it avoids browser compatibility issues. Also, as of version 5.3, the JW Player Embedder
allows you to use the player’s HTML5 feautures. Detailed instructions can be found below.
1.1 Upload
First, a primer on uploading. This may sound obvious, but for the JW Player to work on your website, you must upload
the player.swf file from the download to your webserver. If you want to play Youtube videos, you must also upload the
yt.swf file - this is the bridge between the player and Youtube. Finally, to use the JW Player Embedder and HTML5
player, upload jwplayer.js.
Your media files and playlists can be hosted at any domain. Do note that Crossdomain Security Restrictions apply
when loading these files from a different domain. In short, playing media files works, but loading playlists across
domains will not work by default. Resolve this issue by hosting a crossdomain.xml file.
Note: We recommend putting everything in a folder called “jwplayer” at the root of your site. This enables the Quick
Embed method of setting up the player.
1.2 SWFObject
There’s a wide array of good, open source libraries available for embedding Flash. SWFObject is the most widely
used one. It has excellent documentation.
Before embedding any players on the page, make sure to include the swfobject.js script in the <head> of your HTML.
You can download the script and host it yourself, or leverage the copy provided by Google:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js">
</script>
With the library set up, you can start embedding players. Here’s an example:
1
- 1
- 2
前往页