mirror of
https://github.com/videojs/video.js.git
synced 2024-11-24 08:42:25 +02:00
Merge branch 'feature/component-docs'
Conflicts: src/player.js
This commit is contained in:
commit
6623919429
5
.gitignore
vendored
5
.gitignore
vendored
@ -3,6 +3,9 @@ dist/*
|
||||
dev.html
|
||||
projects
|
||||
.zenflow-log
|
||||
test/*.map
|
||||
|
||||
node_modules
|
||||
npm-debug.log
|
||||
npm-debug.log
|
||||
sandbox/*
|
||||
!sandbox/*.example
|
||||
|
12
.jshintrc
12
.jshintrc
@ -1,16 +1,20 @@
|
||||
{
|
||||
"evil" : true,
|
||||
"validthis": true,
|
||||
"browser" : true,
|
||||
"debug" : true,
|
||||
"boss" : true,
|
||||
"expr" : true,
|
||||
"eqnull" : true,
|
||||
"quotmark" : "double",
|
||||
"quotmark" : "single",
|
||||
"sub" : true,
|
||||
"trailing" : true,
|
||||
"undef" : true,
|
||||
"predef" : [ // Extra globals.
|
||||
"laxbreak" : true,
|
||||
"predef" : [
|
||||
"_V_",
|
||||
"VideoJS"
|
||||
"videojs",
|
||||
"vjs",
|
||||
"goog"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
159
CONTRIBUTING.md
Normal file
159
CONTRIBUTING.md
Normal file
@ -0,0 +1,159 @@
|
||||
So you're telling me you want to spend some of your precious time giving back to this humble project? You're crazy. But since you're here...there are some ways you can help make Video.js a faster, easier, more compatible, and more fully-featured video player.
|
||||
|
||||
* Bug reports and fixes
|
||||
* Features and changes (pull requests)
|
||||
* [Answer questions](http://stackoverflow.com/questions/tagged/video.js) on Stack Overflow
|
||||
* Other Video.js projects
|
||||
|
||||
Don't miss the [code style guide](#code-style).
|
||||
|
||||
# Getting started
|
||||
|
||||
1. [Download and install Node.js](http://nodejs.org/download/). Video.js uses Node for build and test automation.
|
||||
|
||||
2. [Fork](http://help.github.com/fork-a-repo/) and clone the video.js git repository.
|
||||
|
||||
```bash
|
||||
# Clones your fork of the repo into the current directory in terminal
|
||||
git clone https://github.com/<your-username>/video-js.git
|
||||
# Navigate to the newly cloned directory
|
||||
cd video-js
|
||||
# Assigns the original repo to a remote called "upstream"
|
||||
git remote add upstream https://github.com/zencoder/video-js.git
|
||||
```
|
||||
|
||||
In the future, if you want to pull in updates to video.js that happened after you cloned the main repo, you can run:
|
||||
|
||||
```bash
|
||||
git checkout master
|
||||
git pull upstream master
|
||||
```
|
||||
|
||||
3. Install required node.js modules using node package manager.
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
4. Build a local copy. Video.js uses [grunt](http://gruntjs.com), a node-based task automation tool for building and tesing. The following will compile a local copy in the dist/ directory and run tests. It will also create a sourcelist.js file that can be used to load the video.js source scripts in a page.
|
||||
|
||||
```bash
|
||||
grunt
|
||||
```
|
||||
|
||||
5. When you're ready to add a feature, make a change, or fix a bug, first create a new branch for it. Prefix the branch with the correspoding [issue number](https://github.com/zencoder/video-js/issues). If there isn't one, submit a new issue. Anything more complicated than simple docs changes should have an issue.
|
||||
|
||||
```bash
|
||||
git checkout -b <####-branch-name>
|
||||
```
|
||||
|
||||
# Bugs
|
||||
|
||||
A bug is a _demonstrable problem_ that is caused by the code in the
|
||||
repository. Good bug reports are extremely helpful - thank you!
|
||||
|
||||
Guidelines for bug reports:
|
||||
|
||||
1. **Use the [GitHub issue search](https://github.com/zencoder/video-js/issues)** — check if the issue has already been reported.
|
||||
|
||||
2. **Check if the issue has been fixed** — try to reproduce it using the latest `master` branch in the repository.
|
||||
|
||||
3. **Isolate the problem** — ideally create a [reduced test
|
||||
case](http://css-tricks.com/6263-reduced-test-cases/) and a live example.
|
||||
|
||||
A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. What is your environment? What steps will reproduce the issue? What browser(s), OS, and devices experience the problem? What would you expect to be the outcome? All these
|
||||
details will help people to fix any potential bugs.
|
||||
|
||||
Example:
|
||||
|
||||
> Short and descriptive example bug report title
|
||||
>
|
||||
> A summary of the issue and the browser/OS environment in which it occurs. If
|
||||
> suitable, include the steps required to reproduce the bug.
|
||||
>
|
||||
> 1. This is the first step
|
||||
> 2. This is the second step
|
||||
> 3. Further steps, etc.
|
||||
>
|
||||
> `<url>` (a link to the reduced test case)
|
||||
>
|
||||
> Any other information you want to share that is relevant to the issue being
|
||||
> reported. This might include the lines of code that you have identified as
|
||||
> causing the bug, and potential solutions (and your opinions on their
|
||||
> merits).
|
||||
|
||||
**[File a bug report](https://github.com/h5bp/html5-boilerplate/issues/)**
|
||||
|
||||
## Pull requests
|
||||
|
||||
Good pull requests - patches, improvements, new features - are a fantastic help. They should remain focused in scope and avoid containing unrelated commits. If your contribution involves a significant amount of work or substantial changes to any part of the project, please open an issue to discuss it first.
|
||||
|
||||
Make sure to adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.). Please update any documentation that is relevant to the change you're making.
|
||||
|
||||
Please follow this process; it's the best way to get your work included in the project:
|
||||
|
||||
1. [Fork](http://help.github.com/fork-a-repo/) the project, clone your fork, and configure the remotes:
|
||||
|
||||
```bash
|
||||
# Clones your fork of the repo into the current directory in terminal
|
||||
git clone https://github.com/<your-username>/html5-boilerplate.git
|
||||
# Navigate to the newly cloned directory
|
||||
cd html5-boilerplate
|
||||
# Assigns the original repo to a remote called "upstream"
|
||||
git remote add upstream https://github.com/h5bp/html5-boilerplate.git
|
||||
```
|
||||
|
||||
2. If you cloned a while ago, get the latest changes from upstream:
|
||||
|
||||
```bash
|
||||
git checkout master
|
||||
git pull upstream master
|
||||
```
|
||||
|
||||
3. Create a new topic branch to contain your feature, change, or fix:
|
||||
|
||||
```bash
|
||||
git checkout -b <topic-branch-name>
|
||||
```
|
||||
|
||||
4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your pull request is unlikely be merged into the main project. Use git's [interactive rebase](https://help.github.com/articles/interactive-rebase) feature to tidy up your commits before making them public.
|
||||
|
||||
5. Locally merge (or rebase) the upstream development branch into your topic branch:
|
||||
|
||||
```bash
|
||||
git pull [--rebase] upstream master
|
||||
```
|
||||
|
||||
6. Push your topic branch up to your fork:
|
||||
|
||||
```bash
|
||||
git push origin <topic-branch-name>
|
||||
```
|
||||
|
||||
10. [Open a Pull Request](http://help.github.com/send-pull-requests/) with a clear title and description.
|
||||
|
||||
# Code Style
|
||||
Please follow [Google's JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) to the letter. If your editor supports [.editorconfig](http://editorconfig.org/#download) it will make it easier to manage differences from your own coding style.
|
||||
|
||||
### Style examples include:
|
||||
* Two space indents.
|
||||
* Delimit strings with single-quotes `'`, not double-quotes `"`.
|
||||
* No trailing whitespace, except in markdown files where a linebreak must be forced.
|
||||
* No more than [one assignment](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) per `var` statement.
|
||||
* Prefer `if` and `else` to ["clever"](http://programmers.stackexchange.com/a/25281) uses of `? :` conditional or `||`, `&&` logical operators.
|
||||
* **When in doubt, follow the conventions you see used in the source already.**
|
||||
|
||||
If you happen to find something in the codebase that does not follow the style guide, that's a good opportunity to make your first contribution!
|
||||
|
||||
# Other Video.js Pojects
|
||||
* [Video.js SWF](https://github.com/zencoder/video-js-swf) - The light-weight flash video player that makes flash work like HTML5 video. This allows player skins, plugins, and other features to work with both HTML5 and Flash.
|
||||
|
||||
* [Videojs.com](http://videojs.com) - The public site with helpful tools and information about Video.js.
|
||||
|
||||
---
|
||||
### Doc Credit
|
||||
This doc was inspired by some great contribution guide examples including [contribute.md template](https://github.com/contribute-md/contribute-md-template),
|
||||
[grunt](https://github.com/gruntjs/grunt/wiki/Contributing),
|
||||
[html5 boilerplate](https://github.com/h5bp/html5-boilerplate/blob/master/CONTRIBUTING.md),
|
||||
[jquery](https://github.com/jquery/jquery/blob/master/CONTRIBUTING.md),
|
||||
and [node.js](https://github.com/joyent/node/wiki/Contributing).
|
138
Gruntfile.js
Normal file
138
Gruntfile.js
Normal file
@ -0,0 +1,138 @@
|
||||
module.exports = function(grunt) {
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
build: {
|
||||
dist:{}
|
||||
},
|
||||
// Current forEach issue: https://github.com/gruntjs/grunt/issues/610
|
||||
// npm install https://github.com/gruntjs/grunt-contrib-jshint/archive/7fd70e86c5a8d489095fa81589d95dccb8eb3a46.tar.gz
|
||||
jshint: {
|
||||
src: {
|
||||
src: ["src/js/*.js"],
|
||||
options: {
|
||||
jshintrc: ".jshintrc"
|
||||
}
|
||||
}
|
||||
},
|
||||
compile: {
|
||||
dist:{
|
||||
sourcelist: 'dist/sourcelist.txt',
|
||||
externs: ['src/js/media.flash.externs.js'],
|
||||
dest: 'dist/video.js'
|
||||
},
|
||||
test: {
|
||||
sourcelist: 'dist/sourcelist.txt',
|
||||
src: ['test/unit/*.js'],
|
||||
externs: ['src/js/media.flash.externs.js', 'test/qunit/qunit-externs.js'],
|
||||
dest: 'test/video.test.js'
|
||||
}
|
||||
},
|
||||
dist: {
|
||||
latest:{}
|
||||
},
|
||||
qunit: {
|
||||
all: ['test/index.html'],
|
||||
},
|
||||
watch: {
|
||||
files: [ "src/**/*.js" ],
|
||||
tasks: "dev"
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks("grunt-contrib-jshint");
|
||||
grunt.loadNpmTasks("grunt-contrib-qunit");
|
||||
grunt.loadNpmTasks("grunt-contrib-watch");
|
||||
|
||||
// Default task.
|
||||
grunt.registerTask('default', ['build', 'jshint', 'compile', 'dist']);
|
||||
// Development watch task
|
||||
grunt.registerTask('dev', ['jshint','build']);
|
||||
|
||||
grunt.registerTask('test', ['jshint','build','qunit']);
|
||||
|
||||
var fs = require('fs'),
|
||||
gzip = require('zlib').gzip;
|
||||
|
||||
grunt.registerMultiTask('build', 'Building Source', function(){
|
||||
var calcdeps = require('calcdeps').calcdeps;
|
||||
// caclcdeps is async
|
||||
var done = this.async();
|
||||
|
||||
// In current version of calcdeps, not supplying certain
|
||||
// options that should have defaults causes errors
|
||||
// so we have all options listed here with their defaults.
|
||||
calcdeps({
|
||||
input: ['src/js/exports.js'],
|
||||
path:['src/js/'],
|
||||
dep:[],
|
||||
exclude:[],
|
||||
output_mode:'list',
|
||||
}, function(err,results){
|
||||
if (err) {
|
||||
grunt.warn({ message: err })
|
||||
grunt.log.writeln(err);
|
||||
done(false);
|
||||
}
|
||||
|
||||
if (results) {
|
||||
grunt.file.write('dist/sourcelist.txt', results.join(','));
|
||||
grunt.file.write('dist/sourcelist.js', 'var sourcelist = ["' + results.join('","') + '"]');
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
grunt.registerMultiTask('compile', 'Minify JS files using Closure Compiler.', function() {
|
||||
var done = this.async();
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var externs = this.file.externs || [];
|
||||
var dest = this.file.dest;
|
||||
var files = [];
|
||||
if (this.data.sourcelist) {
|
||||
files = files.concat(grunt.file.read(this.data.sourcelist).split(','))
|
||||
}
|
||||
if (this.file.src) {
|
||||
files = files.concat(this.file.src);
|
||||
}
|
||||
|
||||
var command = 'java -jar build/compiler/compiler.jar'
|
||||
+ ' --compilation_level ADVANCED_OPTIMIZATIONS'
|
||||
// + ' --formatting=pretty_print'
|
||||
+ ' --js_output_file=' + dest
|
||||
+ ' --create_source_map ' + dest + '.map --source_map_format=V3'
|
||||
+ ' --output_wrapper "(function() {%output%})();//@ sourceMappingURL=video.js.map"';
|
||||
|
||||
files.forEach(function(file){
|
||||
command += ' --js='+file;
|
||||
});
|
||||
|
||||
externs.forEach(function(extern){
|
||||
command += ' --externs='+extern;
|
||||
});
|
||||
|
||||
// grunt.log.writeln(command)
|
||||
|
||||
exec(command, { maxBuffer: 500*1024 }, function(err, stdout, stderr){
|
||||
|
||||
if (err) {
|
||||
grunt.warn(err);
|
||||
done(false);
|
||||
}
|
||||
|
||||
if (stdout) {
|
||||
grunt.log.writeln(stdout);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
grunt.registerMultiTask('dist', 'Creating distribution', function(){
|
||||
|
||||
});
|
||||
};
|
10
Makefile
10
Makefile
@ -1,10 +0,0 @@
|
||||
# Using makefile temporarily to run tests on Travis CI
|
||||
|
||||
test:
|
||||
# jshint src/*.js --config .jshintrc
|
||||
node test/server.js &
|
||||
phantomjs test/phantom.js "http://localhost:3000/test/unit.html"
|
||||
kill -9 `cat test/pid.txt`
|
||||
rm test/pid.txt
|
||||
|
||||
.PHONY: test
|
19
README.md
19
README.md
@ -1,8 +1,16 @@
|
||||
[Video.js - HTML5 Video Player](http://videojs.com) [![Build Status](https://travis-ci.org/zencoder/video-js.png?branch=master)](https://travis-ci.org/zencoder/video-js)
|
||||
[Video.js - HTML5 and Flash Video Player](http://videojs.com) [![Build Status](https://travis-ci.org/zencoder/video-js.png?branch=master)](https://travis-ci.org/zencoder/video-js)
|
||||
==================================================
|
||||
|
||||
Visit the main site at [videojs.com](http://videojs.com) for download options and instructions.
|
||||
|
||||
Video.js was built to provide a fast and easy way to embed and work with video in a web page. It was built from the ground up with the assumption that HTML5 is the future of web video, however it supports Flash equally well for older browsers and for advanced features not yet supported in HTML5.
|
||||
|
||||
Some of the focuses of Video.js are:
|
||||
- Universal browser and device support
|
||||
- Easily skinned (themed/chromed) using just CSS
|
||||
- A JavaScript API for controlling the video that works consistently across video platforms (HTML5, Flash, and others) as well as devices
|
||||
- A common skin and API between HTML5, Flash, and potentially other players like YouTube
|
||||
|
||||
To build video-js from the latest version of the source, clone the source repository and run:
|
||||
sh build.sh
|
||||
in the video-js directory using the commnand-line/terminal of a unix-based system.
|
||||
@ -17,7 +25,7 @@ cp dev.html.example dev.html
|
||||
You can use dev.html to test new code. It's simple HTML doc that includes all the source files. Send a pull request for any updates.
|
||||
|
||||
---
|
||||
BETA NOTES
|
||||
BETA NOTES
|
||||
Version 3 is almost a complete rewrite of the previous versions of VideoJS. New features includes:
|
||||
|
||||
- HTML/CSS Controls and API now work for both the HTML5 and Flash versions.
|
||||
@ -27,3 +35,10 @@ Version 3 is almost a complete rewrite of the previous versions of VideoJS. New
|
||||
- No more embedding of Flash fallback within the video tag HTML.
|
||||
|
||||
---
|
||||
|
||||
TESTING FLASH LOCALLY IN CHROME
|
||||
-------------------------------
|
||||
Chrome 21+ (as of 2013/01/01) doens't run Flash files that are local and loaded into a locally accessed page (file:///). To get around this you need to [disable the version of Flash](http://helpx.adobe.com/flash-player/kb/flash-player-google-chrome.html#How_can_I_run_debugger_or_alternate_versions_of_Flash_Player_in_Google_Chrome) included with Chrome and enable a system-wide version of Flash.
|
||||
|
||||
|
||||
|
||||
|
206
Rakefile
206
Rakefile
@ -1,206 +0,0 @@
|
||||
require 'rubygems'
|
||||
require 'yaml'
|
||||
require 'httparty'
|
||||
|
||||
namespace :build do
|
||||
|
||||
desc "Build version for current '/c/' CDN copy and locked in version"
|
||||
task :current do
|
||||
Rake::Task["build:source"].execute
|
||||
|
||||
cdn_version_num = "#{version['major']}.#{version['minor']}"
|
||||
|
||||
['c', cdn_version_num].each do |vsn|
|
||||
Rake::Shell["mkdir dist/#{vsn}"]
|
||||
|
||||
File.open("dist/#{vsn}/video.js", "w+") do |file|
|
||||
file.puts File.read("dist/video.min.js").sub('GENERATED_CDN_VSN', vsn)
|
||||
end
|
||||
|
||||
Rake::Shell["cp dist/video-js.min.css dist/#{vsn}/video-js.css"]
|
||||
Rake::Shell["cp dist/video-js.swf dist/#{vsn}/video-js.swf"]
|
||||
Rake::Shell["cp dist/video-js.png dist/#{vsn}/video-js.png"]
|
||||
Rake::Shell["cp dist/demo.html dist/#{vsn}/demo.html"]
|
||||
Rake::Shell["cp dist/captions.vtt dist/#{vsn}/captions.vtt"]
|
||||
end
|
||||
|
||||
Rake::Shell["mkdir dist/video-js"]
|
||||
|
||||
File.open("dist/video-js/video.min.js", "w+") do |file|
|
||||
file.puts File.read("dist/video.min.js").sub('GENERATED_CDN_VSN', cdn_version_num)
|
||||
end
|
||||
|
||||
File.open("dist/video-js/video.js", "w+") do |file|
|
||||
file.puts File.read("dist/video.js").sub('GENERATED_CDN_VSN', cdn_version_num)
|
||||
end
|
||||
|
||||
Rake::Shell["cp dist/video-js.min.css dist/video-js/video-js.min.css"]
|
||||
Rake::Shell["cp dist/video-js.css dist/video-js/video-js.css"]
|
||||
Rake::Shell["cp dist/video-js.swf dist/video-js/video-js.swf"]
|
||||
Rake::Shell["cp dist/video-js.png dist/video-js/video-js.png"]
|
||||
Rake::Shell["cp dist/demo.html dist/video-js/demo.html"]
|
||||
Rake::Shell["cp dist/captions.vtt dist/video-js/captions.vtt"]
|
||||
|
||||
Rake::Shell["cd dist && zip -r video-js-#{version_number}.zip video-js && cd .."]
|
||||
|
||||
if `git name-rev --name-only HEAD`.strip != 'stable'
|
||||
Rake::Log["*** WARNING: NOT ON STABLE BRANCH!!! ***"]
|
||||
end
|
||||
end
|
||||
|
||||
desc "Build source files for packaging"
|
||||
task :source do
|
||||
Rake::Log["Building Version: " << version_number]
|
||||
|
||||
if File.exist?("dist")
|
||||
Rake::Shell["rm -r dist"]
|
||||
end
|
||||
|
||||
# Make distribution folder
|
||||
Rake::Shell["mkdir dist"]
|
||||
|
||||
Rake::Log["Combining source files"]
|
||||
combined = ""
|
||||
|
||||
first_files = [ '_begin.js', 'core.js', 'lib.js' ]
|
||||
|
||||
first_files.each do |item|
|
||||
Rake::Log[item]
|
||||
combined << File.read("src/#{item}")
|
||||
end
|
||||
|
||||
Dir.foreach('src') do |item|
|
||||
next if (['.', '..', '.DS_Store', 'setup.js', '_end.js'] + first_files).include? item
|
||||
combined << File.read("src/#{item}")
|
||||
end
|
||||
|
||||
combined << "\n" << File.read("tech/html5/html5.js")
|
||||
combined << "\n" << File.read("tech/flash/flash.js")
|
||||
|
||||
# combined << File.read("flash/swfobject.js")
|
||||
combined << File.read("src/setup.js")
|
||||
combined << File.read("src/_end.js")
|
||||
|
||||
Rake::Log["Adding version number"]
|
||||
combined = combined.gsub('GENERATED_AT_BUILD', version_number)
|
||||
|
||||
File.open('dist/video.js', "w+") do |file|
|
||||
file.puts "" << combined
|
||||
end
|
||||
|
||||
Rake::Log["Copying CSS and updated version"]
|
||||
File.open('dist/video-js.css', "w+") do |file|
|
||||
file.puts File.read("design/video-js.css").gsub('GENERATED_AT_BUILD', version_number)
|
||||
end
|
||||
|
||||
Rake::Log["Copying suppporting files"]
|
||||
Rake::Shell["cp design/video-js.png dist/video-js.png"]
|
||||
Rake::Shell["cp tech/flash/video-js.swf dist/video-js.swf"]
|
||||
|
||||
Rake::Shell["cp build/release-files/README.md dist/README.md"]
|
||||
Rake::Shell["cp build/release-files/demo.html dist/demo.html"]
|
||||
Rake::Shell["cp build/release-files/captions.vtt dist/captions.vtt"]
|
||||
Rake::Shell["cp LGPLv3-LICENSE.txt dist/LGPLv3-LICENSE.txt"]
|
||||
|
||||
Rake::Log["Minimizing JavaScript"]
|
||||
Rake::Shell["java -jar build/lib/yuicompressor-2.4.7.jar dist/video.js -o dist/video.min.js"]
|
||||
|
||||
Rake::Log["Minimizing CSS"]
|
||||
Rake::Shell["java -jar build/lib/yuicompressor-2.4.7.jar dist/video-js.css -o dist/video-js.min.css"]
|
||||
|
||||
Rake::Log[version_number << " Built"]
|
||||
end
|
||||
|
||||
desc "Build list of source files for easy inclusion in projects"
|
||||
task :js_source do
|
||||
|
||||
File.open("dev/source-list.js", "w+") do |file|
|
||||
file.puts "var vjsSourceList = [];"
|
||||
|
||||
src_array = ["src/core", "src/lib"]
|
||||
last = ["src/setup"] # "flash/swfobject",
|
||||
exclude = [".", "..", ".DS_Store", "_end.js", "_begin.js"]
|
||||
|
||||
Dir.foreach('src') do |item|
|
||||
next if exclude.include? item
|
||||
|
||||
item_name = "src/" << item.sub(".js", "")
|
||||
|
||||
next if (src_array + last).include? item_name
|
||||
|
||||
src_array << item_name
|
||||
end
|
||||
|
||||
src_array = src_array + last
|
||||
|
||||
src_array.each do |item|
|
||||
file.puts "vjsSourceList.push('#{item}')"
|
||||
end
|
||||
# file.puts "vjsSourceList.push('src/#{item.sub(".js", "")}')"
|
||||
# file.puts "vjsSourceList.push('flash/swfobject.js')"
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
desc "Build list of source files for easy inclusion in projects"
|
||||
task :source_html do
|
||||
|
||||
File.open("dev/source-list.html", "w+") do |file|
|
||||
file.puts "<!-- Video.js Source Files -->"
|
||||
|
||||
src_array = ["src/core", "src/lib"]
|
||||
last = ["src/setup"] # "flash/swfobject",
|
||||
exclude = [".", "..", ".DS_Store", "_end.js", "_begin.js"]
|
||||
|
||||
Dir.foreach('src') do |item|
|
||||
next if exclude.include? item
|
||||
|
||||
item_name = "src/" << item.sub(".js", "")
|
||||
|
||||
next if (src_array + last).include? item_name
|
||||
|
||||
src_array << item_name
|
||||
end
|
||||
|
||||
src_array = src_array + last
|
||||
|
||||
src_array.each do |item|
|
||||
file.puts "<script src='#{item}.js'></script>"
|
||||
end
|
||||
# file.puts "vjsSourceList.push('src/#{item.sub(".js", "")}')"
|
||||
# file.puts "vjsSourceList.push('flash/swfobject.js')"
|
||||
|
||||
file.puts "<!-- END Video.js Source Files -->"
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def version
|
||||
YAML.load(File.read("VERSION.yml"))
|
||||
end
|
||||
|
||||
def version_number
|
||||
"#{version['major']}.#{version['minor']}.#{version['patch']}"
|
||||
end
|
||||
|
||||
module Rake
|
||||
class Shell
|
||||
def self.[](command)
|
||||
output = %x[#{command}]
|
||||
if $?.to_i > 0
|
||||
puts "-----> Process aborted"
|
||||
puts " Exit status: #{$?}"
|
||||
exit($?.to_i)
|
||||
end
|
||||
puts output
|
||||
end
|
||||
end
|
||||
|
||||
class Log
|
||||
def self.[](message)
|
||||
puts "-----> #{message.split("\n").join("\n ")}"
|
||||
end
|
||||
end
|
||||
end
|
202
build/compiler/COPYING
Normal file
202
build/compiler/COPYING
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
292
build/compiler/README
Normal file
292
build/compiler/README
Normal file
@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright 2009 The Closure Compiler Authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// Contents
|
||||
//
|
||||
|
||||
The Closure Compiler performs checking, instrumentation, and
|
||||
optimizations on JavaScript code. The purpose of this README is to
|
||||
explain how to build and run the Closure Compiler.
|
||||
|
||||
The Closure Compiler requires Java 6 or higher.
|
||||
http://www.java.com/
|
||||
|
||||
|
||||
//
|
||||
// Building The Closure Compiler
|
||||
//
|
||||
|
||||
There are three ways to get a Closure Compiler executable.
|
||||
|
||||
1) Use one we built for you.
|
||||
|
||||
Pre-built Closure binaries can be found at
|
||||
http://code.google.com/p/closure-compiler/downloads/list
|
||||
|
||||
|
||||
2) Check out the source and build it with Apache Ant.
|
||||
|
||||
First, check out the full source tree of the Closure Compiler. There
|
||||
are instructions on how to do this at the project site.
|
||||
http://code.google.com/p/closure-compiler/source/checkout
|
||||
|
||||
Apache Ant is a cross-platform build tool.
|
||||
http://ant.apache.org/
|
||||
|
||||
At the root of the source tree, there is an Ant file named
|
||||
build.xml. To use it, navigate to the same directory and type the
|
||||
command
|
||||
|
||||
ant jar
|
||||
|
||||
This will produce a jar file called "build/compiler.jar".
|
||||
|
||||
|
||||
3) Check out the source and build it with Eclipse.
|
||||
|
||||
Eclipse is a cross-platform IDE.
|
||||
http://www.eclipse.org/
|
||||
|
||||
Under Eclipse's File menu, click "New > Project ..." and create a
|
||||
"Java Project." You will see an options screen. Give the project a
|
||||
name, select "Create project from existing source," and choose the
|
||||
root of the checked-out source tree as the existing directory. Verify
|
||||
that you are using JRE version 6 or higher.
|
||||
|
||||
Eclipse can use the build.xml file to discover rules. When you
|
||||
navigate to the build.xml file, you will see all the build rules in
|
||||
the "Outline" pane. Run the "jar" rule to build the compiler in
|
||||
build/compiler.jar.
|
||||
|
||||
|
||||
//
|
||||
// Running The Closure Compiler
|
||||
//
|
||||
|
||||
Once you have the jar binary, running the Closure Compiler is straightforward.
|
||||
|
||||
On the command line, type
|
||||
|
||||
java -jar compiler.jar
|
||||
|
||||
This starts the compiler in interactive mode. Type
|
||||
|
||||
var x = 17 + 25;
|
||||
|
||||
then hit "Enter", then hit "Ctrl-Z" (on Windows) or "Ctrl-D" (on Mac or Linux)
|
||||
and "Enter" again. The Compiler will respond:
|
||||
|
||||
var x=42;
|
||||
|
||||
The Closure Compiler has many options for reading input from a file,
|
||||
writing output to a file, checking your code, and running
|
||||
optimizations. To learn more, type
|
||||
|
||||
java -jar compiler.jar --help
|
||||
|
||||
You can read more detailed documentation about the many flags at
|
||||
http://code.google.com/closure/compiler/docs/gettingstarted_app.html
|
||||
|
||||
|
||||
//
|
||||
// Compiling Multiple Scripts
|
||||
//
|
||||
|
||||
If you have multiple scripts, you should compile them all together with
|
||||
one compile command.
|
||||
|
||||
java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
|
||||
|
||||
The Closure Compiler will concatenate the files in the order they're
|
||||
passed at the command line.
|
||||
|
||||
If you need to compile many, many scripts together, you may start to
|
||||
run into problems with managing dependencies between scripts. You
|
||||
should check out the Closure Library. It contains functions for
|
||||
enforcing dependencies between scripts, and a tool called calcdeps.py
|
||||
that knows how to give scripts to the Closure Compiler in the right
|
||||
order.
|
||||
|
||||
http://code.google.com/p/closure-library/
|
||||
|
||||
//
|
||||
// Licensing
|
||||
//
|
||||
|
||||
Unless otherwise stated, all source files are licensed under
|
||||
the Apache License, Version 2.0.
|
||||
|
||||
|
||||
-----
|
||||
Code under:
|
||||
src/com/google/javascript/rhino
|
||||
test/com/google/javascript/rhino
|
||||
|
||||
URL: http://www.mozilla.org/rhino
|
||||
Version: 1.5R3, with heavy modifications
|
||||
License: Netscape Public License and MPL / GPL dual license
|
||||
|
||||
Description: A partial copy of Mozilla Rhino. Mozilla Rhino is an
|
||||
implementation of JavaScript for the JVM. The JavaScript parser and
|
||||
the parse tree data structures were extracted and modified
|
||||
significantly for use by Google's JavaScript compiler.
|
||||
|
||||
Local Modifications: The packages have been renamespaced. All code not
|
||||
relevant to parsing has been removed. A JsDoc parser and static typing
|
||||
system have been added.
|
||||
|
||||
|
||||
-----
|
||||
Code in:
|
||||
lib/rhino
|
||||
|
||||
Rhino
|
||||
URL: http://www.mozilla.org/rhino
|
||||
Version: Trunk
|
||||
License: Netscape Public License and MPL / GPL dual license
|
||||
|
||||
Description: Mozilla Rhino is an implementation of JavaScript for the JVM.
|
||||
|
||||
Local Modifications: Minor changes to parsing JSDoc that usually get pushed
|
||||
up-stream to Rhino trunk.
|
||||
|
||||
|
||||
-----
|
||||
Code in:
|
||||
lib/args4j.jar
|
||||
|
||||
Args4j
|
||||
URL: https://args4j.dev.java.net/
|
||||
Version: 2.0.16
|
||||
License: MIT
|
||||
|
||||
Description:
|
||||
args4j is a small Java class library that makes it easy to parse command line
|
||||
options/arguments in your CUI application.
|
||||
|
||||
Local Modifications: None.
|
||||
|
||||
|
||||
-----
|
||||
Code in:
|
||||
lib/guava.jar
|
||||
|
||||
Guava Libraries
|
||||
URL: http://code.google.com/p/guava-libraries/
|
||||
Version: 13.0.1
|
||||
License: Apache License 2.0
|
||||
|
||||
Description: Google's core Java libraries.
|
||||
|
||||
Local Modifications: None.
|
||||
|
||||
|
||||
-----
|
||||
Code in:
|
||||
lib/jsr305.jar
|
||||
|
||||
Annotations for software defect detection
|
||||
URL: http://code.google.com/p/jsr-305/
|
||||
Version: svn revision 47
|
||||
License: BSD License
|
||||
|
||||
Description: Annotations for software defect detection.
|
||||
|
||||
Local Modifications: None.
|
||||
|
||||
|
||||
-----
|
||||
Code in:
|
||||
lib/jarjar.jar
|
||||
|
||||
Jar Jar Links
|
||||
URL: http://jarjar.googlecode.com/
|
||||
Version: 1.1
|
||||
License: Apache License 2.0
|
||||
|
||||
Description:
|
||||
A utility for repackaging Java libraries.
|
||||
|
||||
Local Modifications: None.
|
||||
|
||||
|
||||
----
|
||||
Code in:
|
||||
lib/junit.jar
|
||||
|
||||
JUnit
|
||||
URL: http://sourceforge.net/projects/junit/
|
||||
Version: 4.10
|
||||
License: Common Public License 1.0
|
||||
|
||||
Description: A framework for writing and running automated tests in Java.
|
||||
|
||||
Local Modifications: None.
|
||||
|
||||
|
||||
---
|
||||
Code in:
|
||||
lib/protobuf-java.jar
|
||||
|
||||
Protocol Buffers
|
||||
URL: http://code.google.com/p/protobuf/
|
||||
Version: 2.4.1
|
||||
License: New BSD License
|
||||
|
||||
Description: Supporting libraries for protocol buffers,
|
||||
an encoding of structured data.
|
||||
|
||||
Local Modifications: None
|
||||
|
||||
|
||||
---
|
||||
Code in:
|
||||
lib/ant.jar
|
||||
lib/ant-launcher.jar
|
||||
|
||||
URL: http://ant.apache.org/bindownload.cgi
|
||||
Version: 1.8.1
|
||||
License: Apache License 2.0
|
||||
Description:
|
||||
Ant is a Java based build tool. In theory it is kind of like "make"
|
||||
without make's wrinkles and with the full portability of pure java code.
|
||||
|
||||
Local Modifications: None
|
||||
|
||||
|
||||
---
|
||||
Code in:
|
||||
lib/json.jar
|
||||
URL: http://json.org/java/index.html
|
||||
Version: JSON version 20090211
|
||||
License: MIT license
|
||||
Description:
|
||||
JSON is a set of java files for use in transmitting data in JSON format.
|
||||
|
||||
Local Modifications: None
|
||||
|
||||
---
|
||||
Code in:
|
||||
tools/maven-ant-tasks-2.1.3.jar
|
||||
URL: http://maven.apache.org
|
||||
Version 2.1.3
|
||||
License: Apache License 2.0
|
||||
Description:
|
||||
Maven Ant tasks are used to manage dependencies and to install/deploy to
|
||||
maven repositories.
|
||||
|
||||
Local Modifications: None
|
BIN
build/compiler/compiler.jar
Normal file
BIN
build/compiler/compiler.jar
Normal file
Binary file not shown.
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video.js | HTML5 Video Player | YouTube Demo</title>
|
||||
|
||||
<!-- Change URLs to wherever Video.js files will be hosted -->
|
||||
<link href="video-js.css" rel="stylesheet" type="text/css">
|
||||
<!-- video.js must be in the <head> for older IEs to work. -->
|
||||
<script src="video.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="360"
|
||||
data-setup='{"techOrder":["youtube","html5"],"ytcontrols":false}'>
|
||||
<source src="http://www.youtube.com/watch?v=qWjzVHG9T1I" type='video/youtube' />
|
||||
</video>
|
||||
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Before Width: | Height: | Size: 85 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.5 KiB |
@ -1,190 +0,0 @@
|
||||
/* DEFAULT SKIN (override in another file)
|
||||
================================================================================
|
||||
Using all CSS to draw the controls. Images could be used if desired.
|
||||
Instead of editing this file, I recommend creating your own skin CSS file to be included after this file,
|
||||
so you can upgrade to newer versions easier. */
|
||||
|
||||
.vjs-original-skin .vjs-controls {
|
||||
position: absolute; margin: 0; opacity: 0.85; color: #fff;
|
||||
display: block; /* Start hidden */
|
||||
left: 0; right: 0; /* 100% width of video-js-box */
|
||||
width: 100%;
|
||||
bottom: 0px; /* Distance from the bottom of the box/video. Keep 0. Use height to add more bottom margin. */
|
||||
height: 35px; /* Including any margin you want above or below control items */
|
||||
padding: 0; /* Controls are absolutely position, so no padding necessary */
|
||||
-webkit-transition: opacity 0.5s linear;
|
||||
-moz-transition: opacity 0.5s linear;
|
||||
-o-transition: opacity 0.5s linear;
|
||||
-ms-transition: opacity 0.5s linear;
|
||||
transition: opacity 0.5s linear;
|
||||
}
|
||||
|
||||
.vjs-original-skin .vjs-control {
|
||||
position: absolute; /* Use top, bottom, left, and right to specifically position the control. */
|
||||
text-align: center; margin: 0; padding: 0;
|
||||
height: 25px; /* Default height of individual controls */
|
||||
top: 5px; /* Top margin to put space between video and controls when controls are below */
|
||||
|
||||
/* CSS Background Gradients
|
||||
Using to give the aqua-ish look. */
|
||||
/* Default */ background-color: #0B151A;
|
||||
/* Webkit */ background: #1F3744 -webkit-gradient(linear, left top, left bottom, from(#0B151A), to(#1F3744)) left 12px;
|
||||
/* Firefox */ background: #1F3744 -moz-linear-gradient(top, #0B151A, #1F3744) left 12px;
|
||||
|
||||
/* CSS Curved Corners */
|
||||
-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
|
||||
|
||||
/* CSS Shadows */
|
||||
-webkit-box-shadow: 1px 1px 2px #000; -moz-box-shadow: 1px 1px 2px #000; box-shadow: 1px 1px 2px #000;
|
||||
}
|
||||
|
||||
/* Placement of Control Items
|
||||
- Left side of pogress bar, use left & width
|
||||
- Rigth side of progress bar, use right & width
|
||||
- Expand with the video (like progress bar) use left & right
|
||||
(using div.x to make more specific than vjs-control style)
|
||||
*/
|
||||
.vjs-original-skin div.vjs-play-control { left: 5px; width: 25px; }
|
||||
.vjs-original-skin div.vjs-progress-control { left: 35px; right: 165px; } /* Using left & right so it expands with the width of the video */
|
||||
.vjs-original-skin div.vjs-time-control { width: 75px; right: 90px; } /* Time control and progress bar are combined to look like one */
|
||||
.vjs-original-skin div.vjs-volume-control { width: 50px; right: 35px; }
|
||||
.vjs-original-skin div.vjs-fullscreen-control { width: 25px; right: 5px; }
|
||||
|
||||
/* Removing curved corners on progress control and time control to join them. */
|
||||
.vjs-original-skin div.vjs-progress-control {
|
||||
-webkit-border-top-right-radius: 0; -moz-border-radius-topright: 0; border-top-right-radius: 0;
|
||||
-webkit-border-bottom-right-radius: 0; -moz-border-radius-bottomright: 0; border-bottom-right-radius: 0;
|
||||
}
|
||||
.vjs-original-skin div.vjs-time-control {
|
||||
-webkit-border-top-left-radius: 0; -moz-border-radius-topleft: 0; border-top-left-radius: 0;
|
||||
-webkit-border-bottom-left-radius: 0; -moz-border-radius-bottomleft: 0; border-bottom-left-radius: 0;
|
||||
}
|
||||
|
||||
/* Play/Pause
|
||||
-------------------------------------------------------------------------------- */
|
||||
.vjs-original-skin .vjs-play-control { cursor: pointer !important; }
|
||||
/* Play Icon */
|
||||
.vjs-original-skin .vjs-play-control span { display: block; font-size: 0; line-height: 0; }
|
||||
.vjs-original-skin.vjs-paused .vjs-play-control span {
|
||||
width: 0; height: 0; margin: 8px 0 0 8px;
|
||||
/* Drawing the play triangle with borders - http://www.infimum.dk/HTML/slantinfo.html */
|
||||
border-left: 10px solid #fff; /* Width & Color of play icon */
|
||||
/* Height of play icon is total top & bottom border widths. Color is transparent. */
|
||||
border-top: 5px solid rgba(0,0,0,0); border-bottom: 5px solid rgba(0,0,0,0);
|
||||
}
|
||||
.vjs-original-skin.vjs-playing .vjs-play-control span {
|
||||
width: 3px; height: 10px; margin: 8px auto 0;
|
||||
/* Drawing the pause bars with borders */
|
||||
border-top: 0px; border-left: 3px solid #fff; border-bottom: 0px; border-right: 3px solid #fff;
|
||||
}
|
||||
|
||||
/* Progress
|
||||
-------------------------------------------------------------------------------- */
|
||||
.vjs-original-skin .vjs-progress-holder { /* Box containing play and load progresses */
|
||||
position: relative; padding: 0; overflow:hidden; cursor: pointer !important;
|
||||
height: 9px; border: 1px solid #777;
|
||||
margin: 7px 1px 0 5px; /* Placement within the progress control item */
|
||||
-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
|
||||
}
|
||||
.vjs-original-skin .vjs-progress-holder div { /* Progress Bars */
|
||||
position: absolute; display: block; width: 0; height: 9px; margin: 0; padding: 0;
|
||||
left: 0; top: 0; /*Needed for IE6*/
|
||||
-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
|
||||
}
|
||||
.vjs-original-skin .vjs-play-progress {
|
||||
/* CSS Gradient */
|
||||
/* Default */ background: #fff;
|
||||
/* Webkit */ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#777));
|
||||
/* Firefox */ background: -moz-linear-gradient(top, #fff, #777);
|
||||
}
|
||||
.vjs-original-skin .vjs-load-progress {
|
||||
opacity: 0.8;
|
||||
/* CSS Gradient */
|
||||
/* Default */ background-color: #555;
|
||||
/* Webkit */ background: -webkit-gradient(linear, left top, left bottom, from(#555), to(#aaa));
|
||||
/* Firefox */ background: -moz-linear-gradient(top, #555, #aaa);
|
||||
}
|
||||
|
||||
/* Time Display
|
||||
-------------------------------------------------------------------------------- */
|
||||
.vjs-original-skin .vjs-time-control { font-size: 10px; line-height: 1; font-weight: normal; font-family: Helvetica, Arial, sans-serif; }
|
||||
.vjs-original-skin .vjs-time-control span { line-height: 25px; /* Centering vertically */ }
|
||||
|
||||
/* Volume
|
||||
-------------------------------------------------------------------------------- */
|
||||
.vjs-original-skin .vjs-volume-control { cursor: pointer !important; }
|
||||
.vjs-original-skin .vjs-volume-control div { display: block; margin: 0 5px 0 5px; padding: 4px 0 0 0; }
|
||||
/* Drawing the volume icon using 6 span elements */
|
||||
.vjs-original-skin .vjs-volume-control div span { /* Individual volume bars */
|
||||
float: left; padding: 0; font-size: 0; line-height: 0;
|
||||
margin: 0 2px 0 0; /* Space between */
|
||||
width: 5px; height: 0px; /* Total height is height + bottom border */
|
||||
border-bottom: 18px solid #555; /* Default (off) color and height of visible portion */
|
||||
}
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-volume-level-on { border-color: #fff; /* Volume on bar color */ }
|
||||
/* Creating differnt bar heights through height (transparent) and bottom border (visible). */
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-1 { border-bottom-width: 2px; height: 16px; }
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-2 { border-bottom-width: 4px; height: 14px; }
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-3 { border-bottom-width: 7px; height: 11px; }
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-4 { border-bottom-width: 10px; height: 8px; }
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-5 { border-bottom-width: 14px; height: 4px; }
|
||||
.vjs-original-skin .vjs-volume-control div span.vjs-vc-6 { margin-right: 0; }
|
||||
|
||||
/* Fullscreen
|
||||
-------------------------------------------------------------------------------- */
|
||||
.vjs-original-skin .vjs-fullscreen-control { cursor: pointer !important; }
|
||||
.vjs-original-skin .vjs-fullscreen-control div {
|
||||
padding: 0; text-align: left; vertical-align: top; cursor: pointer !important;
|
||||
margin: 5px 0 0 5px; /* Placement within the fullscreen control item */
|
||||
width: 20px; height: 20px;
|
||||
}
|
||||
/* Drawing the fullscreen icon using 4 span elements */
|
||||
.vjs-original-skin .vjs-fullscreen-control div span { float: left; margin: 0; padding: 0; font-size: 0; line-height: 0; width: 0; text-align: left; vertical-align: top; }
|
||||
.vjs-original-skin .vjs-fullscreen-control div span.vjs-fc-1 { /* Top-left triangle */
|
||||
margin-right: 3px; /* Space between top-left and top-right */
|
||||
margin-bottom: 3px; /* Space between top-left and bottom-left */
|
||||
border-top: 6px solid #fff; /* Height and color */
|
||||
border-right: 6px solid rgba(0,0,0,0); /* Width */
|
||||
}
|
||||
.vjs-original-skin .vjs-fullscreen-control div span.vjs-fc-2 { border-top: 6px solid #fff; border-left: 6px solid rgba(0,0,0,0); }
|
||||
.vjs-original-skin .vjs-fullscreen-control div span.vjs-fc-3 { clear: both; margin: 0 3px 0 0; border-bottom: 6px solid #fff; border-right: 6px solid rgba(0,0,0,0); }
|
||||
.vjs-original-skin .vjs-fullscreen-control div span.vjs-fc-4 { border-bottom: 6px solid #fff; border-left: 6px solid rgba(0,0,0,0); }
|
||||
/* Icon when video is in fullscreen mode */
|
||||
.vjs-original-skin.vjs-fullscreen .vjs-fullscreen-control div span.vjs-fc-1 { border: none; border-bottom: 6px solid #fff; border-left: 6px solid rgba(0,0,0,0); }
|
||||
.vjs-original-skin.vjs-fullscreen .vjs-fullscreen-control div span.vjs-fc-2 { border: none; border-bottom: 6px solid #fff; border-right: 6px solid rgba(0,0,0,0); }
|
||||
.vjs-original-skin.vjs-fullscreen .vjs-fullscreen-control div span.vjs-fc-3 { border: none; border-top: 6px solid #fff; border-left: 6px solid rgba(0,0,0,0); }
|
||||
.vjs-original-skin.vjs-fullscreen .vjs-fullscreen-control div span.vjs-fc-4 { border: none; border-top: 6px solid #fff; border-right: 6px solid rgba(0,0,0,0); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* Big Play Button (at start)
|
||||
---------------------------------------------------------*/
|
||||
.vjs-original-skin .vjs-big-play-button {
|
||||
display: block; /* Start hidden */ z-index: 2;
|
||||
position: absolute; top: 50%; left: 50%; width: 80px; height: 80px; margin: -43px 0 0 -43px; text-align: center; vertical-align: center; cursor: pointer !important;
|
||||
border: 3px solid #fff; opacity: 0.9;
|
||||
-webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;
|
||||
|
||||
/* CSS Background Gradients */
|
||||
/* Default */ background-color: #0B151A;
|
||||
/* Webkit */ background: #1F3744 -webkit-gradient(linear, left top, left bottom, from(#0B151A), to(#1F3744)) left 40px;
|
||||
/* Firefox */ background: #1F3744 -moz-linear-gradient(top, #0B151A, #1F3744) left 40px;
|
||||
|
||||
/* CSS Shadows */
|
||||
-webkit-box-shadow: 4px 4px 8px #000; -moz-box-shadow: 4px 4px 8px #000; box-shadow: 4px 4px 8px #000;
|
||||
}
|
||||
|
||||
.vjs-original-skin div.vjs-big-play-button:hover {
|
||||
-webkit-box-shadow: 0px 0px 80px #fff; -moz-box-shadow: 0px 0px 80px #fff; box-shadow: 0px 0px 80px #fff;
|
||||
}
|
||||
|
||||
.vjs-original-skin div.vjs-big-play-button span {
|
||||
display: block; font-size: 0; line-height: 0;
|
||||
width: 0; height: 0; margin: 20px 0 0 23px;
|
||||
/* Drawing the play triangle with borders - http://www.infimum.dk/HTML/slantinfo.html */
|
||||
border-left: 40px solid #fff; /* Width & Color of play icon */
|
||||
/* Height of play icon is total top & bottom border widths. Color is transparent. */
|
||||
border-top: 20px solid rgba(0,0,0,0); border-bottom: 20px solid rgba(0,0,0,0);
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>HTML5 Video Player</title>
|
||||
|
||||
<link href="design/video-js.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!--[if IE]>
|
||||
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
|
||||
<!--<![endif]-->
|
||||
|
||||
<script src="src/core.js"></script>
|
||||
<script src="src/lib.js"></script>
|
||||
<script src="src/json.js"></script>
|
||||
|
||||
<script src="src/component.js"></script>
|
||||
<script src="src/player.js"></script>
|
||||
<script src="src/tech.js"></script>
|
||||
<script src="src/controls.js"></script>
|
||||
<script src="src/events.js"></script>
|
||||
<script src="src/tracks.js"></script>
|
||||
|
||||
<script src="tech/html5/html5.js"></script>
|
||||
<script src="tech/flash/flash.js"></script>
|
||||
|
||||
<script src="src/setup.js"></script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Easy access to test Flash over HTML5. Add ?flash to URL
|
||||
if (window.location.href.indexOf("?flash") !== -1) {
|
||||
_V_.options.techOrder = ["flash"];
|
||||
_V_.options.flash.swf = "tech/flash/video-js.swf";
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
|
||||
poster="http://video-js.zencoder.com/oceans-clip.png"
|
||||
data-setup='{}'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg'>
|
||||
<p>Video Playback Not Supported</p>
|
||||
</video>
|
||||
|
||||
<script>
|
||||
vid = document.getElementById("vid1");
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,17 +0,0 @@
|
||||
#! /usr/bin/env ruby
|
||||
# Create javascript file with list of source files for easy inclusion in other development files.
|
||||
|
||||
# puts ARGV[0]
|
||||
|
||||
File.open("source-list.js", "w+") do |file|
|
||||
file.puts "var vjsSourceList = [];"
|
||||
|
||||
|
||||
Dir.foreach('../src') do |item|
|
||||
next if item == '.' or item == '..' or item == '.DS_Store'
|
||||
|
||||
file.puts "vjsSourceList.push('src/#{item}')"
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -1,31 +0,0 @@
|
||||
// Attempting to create a portable script that loads source files in order. So we can change which files are included and have it change multiple places.
|
||||
var vjsSourceList = ["require",
|
||||
'order!../../src/core.js',
|
||||
'order!../../src/lib.js',
|
||||
'order!../../src/component.js',
|
||||
'order!../../src/controls.js',
|
||||
'order!../../src/ecma.js',
|
||||
'order!../../src/events.js',
|
||||
'order!../../src/json.js',
|
||||
'order!../../src/player.js',
|
||||
'order!../../src/tech.js',
|
||||
'order!../../src/tracks.js',
|
||||
'order!../../flash/swfobject.js',
|
||||
'order!../../src/setup.js'
|
||||
];
|
||||
|
||||
// Not going to be used in production, so eval ok.
|
||||
require([vjsSourceList])
|
||||
|
||||
// var requireEval = '';
|
||||
// for (var i=0; i < vjsSourceList.length; i++) {
|
||||
// requireEval += 'require(["order!'+vjsSourceList[i]+'"], function() { ';
|
||||
// }
|
||||
//
|
||||
// requireEval += 'var libsLoaded = true;'
|
||||
//
|
||||
// for (var i=0; i < vjsSourceList.length; i++) {
|
||||
// requireEval += ' }); ';
|
||||
// }
|
||||
//
|
||||
// eval(requireEval);
|
2144
dev/require.js
2144
dev/require.js
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
<!-- Video.js Source Files -->
|
||||
<script src='src/core.js'></script>
|
||||
<script src='src/lib.js'></script>
|
||||
<script src='src/component.js'></script>
|
||||
<script src='src/controls.js'></script>
|
||||
<script src='src/ecma.js'></script>
|
||||
<script src='src/events.js'></script>
|
||||
<script src='src/json.js'></script>
|
||||
<script src='src/player.js'></script>
|
||||
<script src='src/tech.js'></script>
|
||||
<script src='src/tracks.js'></script>
|
||||
<script src='src/setup.js'></script>
|
||||
<!-- END Video.js Source Files -->
|
@ -1,13 +0,0 @@
|
||||
var vjsSourceList = [];
|
||||
vjsSourceList.push('src/core')
|
||||
vjsSourceList.push('src/lib')
|
||||
vjsSourceList.push('src/component')
|
||||
vjsSourceList.push('src/controls')
|
||||
vjsSourceList.push('src/ecma')
|
||||
vjsSourceList.push('src/events')
|
||||
vjsSourceList.push('src/json')
|
||||
vjsSourceList.push('src/player')
|
||||
vjsSourceList.push('src/tech')
|
||||
vjsSourceList.push('src/tracks')
|
||||
vjsSourceList.push('flash/swfobject')
|
||||
vjsSourceList.push('src/setup')
|
27
docs/api.md
27
docs/api.md
@ -5,19 +5,15 @@ The Video.js API allows you to interact with the video through Javascript, wheth
|
||||
Referencing the Player
|
||||
----------------------
|
||||
To use the API functions, you need access to the player object. Luckily this is easy to get. You just need to make sure your video tag has an ID. The example embed code has an ID of "example\_video_1". If you have multiple videos on one page, make sure every video tag has a unique ID.
|
||||
|
||||
```js
|
||||
var myPlayer = _V_("example_video_1");
|
||||
```
|
||||
|
||||
(If the player hasn't been initialized yet via the data-setup attribute or another method, this will also initialize the player.)
|
||||
|
||||
The player may also be referenced using a DOM element as an argument, so `_V_(document.getElementById('my-video'))` and `_V_('my-video')` are equivalent.
|
||||
|
||||
Wait Until the Player is Ready
|
||||
------------------------------
|
||||
The time it takes Video.js to set up the video and API will vary depending on the playback technology being used (HTML5 will often be much faster to load than Flash). For that reason we want to use the player's 'ready' function to trigger any code that requires the player's API.
|
||||
|
||||
```javascript
|
||||
_V_("example_video_1").ready(function(){
|
||||
|
||||
@ -35,7 +31,6 @@ Now that you have access to a ready player, you can control the video, get value
|
||||
|
||||
### play() ###
|
||||
Start video playback. Returns the player object.
|
||||
|
||||
```js
|
||||
myPlayer.play();
|
||||
```
|
||||
@ -43,7 +38,6 @@ myPlayer.play();
|
||||
|
||||
### pause() ###
|
||||
Pause the video playback. Returns the player object
|
||||
|
||||
```js
|
||||
myPlayer.pause();
|
||||
```
|
||||
@ -51,7 +45,6 @@ myPlayer.pause();
|
||||
|
||||
### paused() ###
|
||||
Returns false if the video is currently playing, or true otherwise. ()
|
||||
|
||||
```js
|
||||
var isPaused = myPlayer.paused();
|
||||
var isPlaying = !myPlayer.paused();
|
||||
@ -62,19 +55,16 @@ var isPlaying = !myPlayer.paused();
|
||||
The source function updates the video source. There are three types of variables you can pass as the argument.
|
||||
|
||||
**URL String**: A URL to the the video file. Use this method if you're sure the current playback technology (HTML5/Flash) can support the source you provide. Currently only MP4 files can be used in both HTML5 and Flash.
|
||||
|
||||
```js
|
||||
myPlayer.src("http://www.example.com/path/to/video.mp4");
|
||||
```
|
||||
|
||||
**Source Object (or element):** A javascript object containing information about the source file. Use this method if you want the player to determine if it can support the file using the type information.
|
||||
|
||||
```js
|
||||
myPlayer.src({ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" });
|
||||
```
|
||||
|
||||
**Array of Source Objects:** To provide multiple versions of the source so that it can be played using HTML5 across browsers you can use an array of source objects. Video.js will detect which version is supported and load that file.
|
||||
|
||||
```js
|
||||
myPlayer.src([
|
||||
{ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" },
|
||||
@ -88,7 +78,6 @@ Returns the player object.
|
||||
|
||||
### currentTime() ###
|
||||
Returns the current time of the video in seconds.
|
||||
|
||||
```js
|
||||
var whereYouAt = myPlayer.currentTime();
|
||||
```
|
||||
@ -96,7 +85,6 @@ var whereYouAt = myPlayer.currentTime();
|
||||
|
||||
### currentTime(seconds) // Type: Integer or Float ###
|
||||
Seek to the supplied time (seconds). Returns the player object.
|
||||
|
||||
```js
|
||||
myPlayer.currentTime(120); // 2 minutes into the video
|
||||
```
|
||||
@ -104,7 +92,6 @@ myPlayer.currentTime(120); // 2 minutes into the video
|
||||
|
||||
### duration() ###
|
||||
Returns the length in time of the video in seconds. NOTE: The video must have started loading before the duration can be known, and in the case of Flash, may not be known until the video starts playing.
|
||||
|
||||
```js
|
||||
var howLongIsThis = myPlayer.duration();
|
||||
```
|
||||
@ -112,7 +99,6 @@ var howLongIsThis = myPlayer.duration();
|
||||
|
||||
### buffered() ###
|
||||
Returns a [TimeRange](glossary.md#timerange) object with sections of the video that have been downloaded. If you just want the percent of the video that's been downloaded, use bufferedPercent.
|
||||
|
||||
```js
|
||||
var bufferedTimeRange = myPlayer.buffered(),
|
||||
|
||||
@ -132,7 +118,6 @@ firstRangeLength = firstRangeEnd - firstRangeStart;
|
||||
|
||||
### bufferedPercent() ###
|
||||
Returns the percent (as a decimal) of the video that's been downloaded. 0 means none, 1 means all.
|
||||
|
||||
```js
|
||||
var howMuchIsDownloaded = myPlayer.bufferedPercent();
|
||||
```
|
||||
@ -140,7 +125,6 @@ var howMuchIsDownloaded = myPlayer.bufferedPercent();
|
||||
|
||||
### volume() ###
|
||||
Returns the current volume of the video as a percent in decimal form. 0 is off (muted), 1.0 is all the way up, 0.5 is half way.
|
||||
|
||||
```js
|
||||
var howLoudIsIt = myPlayer.volume();
|
||||
```
|
||||
@ -148,7 +132,6 @@ var howLoudIsIt = myPlayer.volume();
|
||||
|
||||
### volume(percentAsDecimal) ###
|
||||
Set the volume to the supplied percent (as a decimal between 0 and 1).
|
||||
|
||||
```js
|
||||
myPlayer.volume(0.5); // Set volume to half
|
||||
```
|
||||
@ -156,7 +139,6 @@ myPlayer.volume(0.5); // Set volume to half
|
||||
|
||||
### width() ###
|
||||
Returns the current width of the video in pixels.
|
||||
|
||||
```js
|
||||
var howWideIsIt = myPlayer.width();
|
||||
```
|
||||
@ -164,7 +146,6 @@ var howWideIsIt = myPlayer.width();
|
||||
|
||||
### width(pixels) ###
|
||||
Change the width of the video to the supplied width in pixels. Returns the player object
|
||||
|
||||
```js
|
||||
myPlayer.width(640);
|
||||
```
|
||||
@ -172,7 +153,6 @@ myPlayer.width(640);
|
||||
|
||||
### height() ###
|
||||
Returns the current height of the video in pixels.
|
||||
|
||||
```js
|
||||
var howTallIsIt = myPlayer.height();
|
||||
```
|
||||
@ -180,7 +160,6 @@ var howTallIsIt = myPlayer.height();
|
||||
|
||||
### height(pixels) ###
|
||||
Change the height of the video to the supplied height in pixels. Returns the player object
|
||||
|
||||
```js
|
||||
myPlayer.height(480);
|
||||
```
|
||||
@ -188,7 +167,6 @@ myPlayer.height(480);
|
||||
|
||||
### size(width, height) ###
|
||||
Changes the width and height of the video to the supplied width and height. This is more efficient if you're changing both width and height (only triggers the player's resize event once). Returns the player object.
|
||||
|
||||
```js
|
||||
myPlayer.size(640,480);
|
||||
```
|
||||
@ -196,7 +174,6 @@ myPlayer.size(640,480);
|
||||
|
||||
### requestFullScreen() ###
|
||||
Increase the size of the video to full screen. In some browsers, full screen is not supported natively, so it enters full window mode, where the video fills the browser window. In browsers and devices that support native full screen, sometimes the browser's default controls will be shown, and not the Video.js custom skin. This includes most mobile devices (iOS, Android) and older versions of Safari. Returns the player object.
|
||||
|
||||
```js
|
||||
myPlayer.requestFullScreen();
|
||||
```
|
||||
@ -204,7 +181,6 @@ myPlayer.requestFullScreen();
|
||||
|
||||
### cancelFullScreen() ###
|
||||
Return the video to its normal size after having been in full screen mode. Returns the player object.
|
||||
|
||||
```js
|
||||
myPlayer.cancelFullScreen();
|
||||
```
|
||||
@ -223,7 +199,6 @@ myPlayer.addEvent("eventName", myFunc);
|
||||
```
|
||||
|
||||
You can also remove the listeners later.
|
||||
|
||||
```js
|
||||
myPlayer.removeEvent("eventName", myFunc);
|
||||
```
|
||||
@ -248,4 +223,4 @@ List of player events you can add listeners for.
|
||||
<tr><td>volumechange</td><td>Fired when the volume changes.</td></tr>
|
||||
<tr><td>error</td><td>Fired when there is an error in playback.</td></tr>
|
||||
<tr><td>fullscreenchange</td><td>Fired when the player switches in or out of fullscreen mode.</td></tr>
|
||||
</table>
|
||||
</table>
|
||||
|
@ -1,6 +1,6 @@
|
||||
Components
|
||||
===
|
||||
The Video.js player is built on top of a simple custom UI components architecture. The player class and all control classes extend the Component class, or a subclass of Component.
|
||||
The Video.js player is built on top of a simple, custom UI components architecture. The player class and all control classes inherit from the Component class, or a subclass of Component.
|
||||
|
||||
```js
|
||||
_V_.Control = _V_.Component.extend({});
|
||||
@ -8,4 +8,84 @@ _V_.Button = _V_.Control.extend({});
|
||||
_V_.PlayToggle = _V_.Button.extend({});
|
||||
```
|
||||
|
||||
(The Class interface itself is provided using John Resig's [simple class inheritance](http://ejohn.org/blog/simple-javascript-inheritance/) also found in [JSNinja](http://jsninja.com).
|
||||
(The Class interface itself is provided using John Resig's [simple class inheritance](http://ejohn.org/blog/simple-javascript-inheritance/) also found in [JSNinja](http://jsninja.com).
|
||||
|
||||
The UI component architecture makes it easier to add child components to a parent component and build up an entire user interface, like the controls for the Video.js player.
|
||||
|
||||
```js
|
||||
// Adding a new control to the player
|
||||
myPlayer.addChild('BigPlayButton');
|
||||
```
|
||||
|
||||
Every component has an associated DOM element, and when you add a child component, it inserts the element of that child into the element of the parent.
|
||||
|
||||
```js
|
||||
myPlayer.addChild('BigPlayButton');
|
||||
```
|
||||
|
||||
Results in:
|
||||
|
||||
```html
|
||||
<!-- Player Element -->
|
||||
<div class="video-js">
|
||||
<!-- BigPlayButton Element -->
|
||||
<div class="vjs-big-play-button"></div>
|
||||
</div>
|
||||
```
|
||||
|
||||
The actual default component structure of the Video.js player looks something like this:
|
||||
|
||||
```
|
||||
Player
|
||||
PosterImage
|
||||
TextTrackDisplay
|
||||
LoadingSpinner
|
||||
BigPlayButton
|
||||
ControlBar
|
||||
PlayToggle
|
||||
FullscreenToggle
|
||||
CurrentTimeDisplay
|
||||
TimeDivider
|
||||
DurationDisplay
|
||||
RemainingTimeDisplay
|
||||
ProgressControl
|
||||
SeekBar
|
||||
LoadProgressBar
|
||||
PlayProgressBar
|
||||
SeekHandle
|
||||
VolumeControl
|
||||
VolumeBar
|
||||
VolumeLevel
|
||||
VolumeHandle
|
||||
MuteToggle
|
||||
```
|
||||
|
||||
Component Methods
|
||||
-----------------
|
||||
|
||||
### addChild() ###
|
||||
Add a child component to myComponent. This will also insert the child component's DOM element into myComponent's element.
|
||||
|
||||
|
||||
|
||||
```js
|
||||
myComponent.addChild('');
|
||||
```
|
||||
|
||||
|
||||
myPlayer.addChild('BigPlayButton');
|
||||
myPlayer.removeChild('BigPlayButton');
|
||||
myPlayer.getChild('BiPlayButton');
|
||||
myPlayer.children();
|
||||
|
||||
|
||||
myPlayer.getChildById('biPlayButton');
|
||||
myPlayer.removeChildById('my-player-big-play-button');
|
||||
|
||||
el();
|
||||
getContentEl();
|
||||
getChildren();
|
||||
|
||||
getParent();
|
||||
|
||||
#home_player_big-play-button
|
||||
|
@ -6,7 +6,7 @@ Video.js is pretty easy to set up. It can take a matter of seconds to get the pl
|
||||
Step 1: Include the Video.js Javascript and CSS files in the head of your page.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
You can download the Video.js source and host it on your own servers, or use the free CDN hosted version. It's often recommended now to put JavaScript before the end body tag (</body>) instead of the head (<head>), but Video.js includes an 'HTML5 Shiv', which needs to be in the head for older IE versions to respect the video tag as a valid element.
|
||||
You can download the Video.js source and host it on your own servers, or use the free CDN hosted version. It's often recommended now to put JavaScript before the end body tag (</body>) instead of the head (<head>), but Video.js includes an 'HTML5 Shiv', which needs to be in the head for older IE versions to respect the video tag as a valid element.
|
||||
|
||||
> NOTE: If you're already using an HTML5 shiv like [Modernizr](http://modernizr.com/) you can include the Video.js JavaScript anywhere, however make sure your version of Modernizr includes the shiv for video.
|
||||
|
||||
@ -42,13 +42,13 @@ With Video.js you just use an HTML5 video tag to embed a video. Video.js will th
|
||||
Otherwise include/exclude attributes, settings, sources, and tracks exactly as you would for HTML5 video.
|
||||
|
||||
```html
|
||||
<video id="example_video_1" class="video-js vjs-default-skin"
|
||||
controls preload="auto" width="640" height="264"
|
||||
poster="http://video-js.zencoder.com/oceans-clip.png"
|
||||
data-setup='{"example_option":true}'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
|
||||
<video id="example_video_1" class="video-js vjs-default-skin"
|
||||
controls preload="auto" width="640" height="264"
|
||||
poster="http://video-js.zencoder.com/oceans-clip.png"
|
||||
data-setup='{"example_option":true}'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4' />
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm' />
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg' />
|
||||
</video>
|
||||
```
|
||||
|
||||
@ -62,9 +62,9 @@ _V_("example_video_1", {}, function(){
|
||||
});
|
||||
```
|
||||
|
||||
The first argument in the \_V_ function is the ID of your video tag. Replace it with your own.
|
||||
The first argument in the \_V_ function is the ID of your video tag. Replace it with your own.
|
||||
|
||||
The second argument is an options object. It allows you to set additional options like you can with the data-setup attribute.
|
||||
The second argument is an options object. It allows you to set additional options like you can with the data-setup attribute.
|
||||
|
||||
The third argument is a 'ready' callback. Once Video.js has initialized it will call this function.
|
||||
|
||||
|
45
package.json
45
package.json
@ -1,16 +1,29 @@
|
||||
{ "name": "Video.js"
|
||||
, "description": "An HTML5 and Flash video player with a common API and skin for both."
|
||||
, "version": "3.2.3"
|
||||
, "keywords": ["html5", "flash", "video", "player"]
|
||||
, "homepage": "http://videojs.com"
|
||||
, "author": "Steve Heffernan"
|
||||
, "scripts": { "test": "make test" }
|
||||
, "repository":
|
||||
{ "type": "git"
|
||||
, "url": "https://github.com/zencoder/video-js.git"
|
||||
}
|
||||
, "devDependencies":
|
||||
{ "jshint": "0.6.1"
|
||||
, "connect": "2.1.3"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "video.js",
|
||||
"description": "An HTML5 and Flash video player with a common API and skin for both.",
|
||||
"version": "3.2.3",
|
||||
"keywords": [
|
||||
"html5",
|
||||
"flash",
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"homepage": "http://videojs.com",
|
||||
"author": "Steve Heffernan",
|
||||
"scripts": {
|
||||
"test": "grunt test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zencoder/video-js.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt-cli": "~0.1.0",
|
||||
"grunt": "0.4.0rc4",
|
||||
"grunt-contrib-jshint": "https://github.com/gruntjs/grunt-contrib-jshint/archive/7fd70e86c5a8d489095fa81589d95dccb8eb3a46.tar.gz",
|
||||
"grunt-contrib-watch": "~0.1.4",
|
||||
"grunt-contrib-qunit": "~0.1.0",
|
||||
"calcdeps": "~0.1.7",
|
||||
"phantomjs": "~1.8.0-1"
|
||||
}
|
||||
}
|
||||
|
53
sandbox/index.html.example
Normal file
53
sandbox/index.html.example
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Video.js Sandbox</title>
|
||||
|
||||
<link href="../src/css/video-js.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!--[if IE]>
|
||||
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
|
||||
<!--<![endif]-->
|
||||
|
||||
<script src='../src/js/goog.base.js'></script>
|
||||
<script src='../src/js/core.js'></script>
|
||||
<script src='../src/js/lib.js'></script>
|
||||
<script src='../src/js/events.js'></script>
|
||||
<script src='../src/js/component.js'></script>
|
||||
<script src='../src/js/player.js'></script>
|
||||
<script src='../src/js/media.js'></script>
|
||||
<script src='../src/js/media.html5.js'></script>
|
||||
<script src='../src/js/media.flash.js'></script>
|
||||
<script src='../src/js/controls.js'></script>
|
||||
<script src='../src/js/tracks.js'></script>
|
||||
<script src='../src/js/setup.js'></script>
|
||||
<script src='../src/js/json.js'></script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// Easy access to test Flash over HTML5. Add ?flash to URL
|
||||
if (window.location.href.indexOf("?flash") !== -1) {
|
||||
videojs.options.techOrder = ["Flash"];
|
||||
videojs.options.flash.swf = "../src/swf/video-js.swf";
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo, except files that end in .example, so please don't edit or add those files. To get started make a copy of index.html.example and rename it to index.html.</p>
|
||||
|
||||
<video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
|
||||
poster="http://video-js.zencoder.com/oceans-clip.png"
|
||||
data-setup='{}'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
|
||||
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg'>
|
||||
<p>Video Playback Not Supported</p>
|
||||
</video>
|
||||
|
||||
<script>
|
||||
vid = document.getElementById("vid1");
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,24 +0,0 @@
|
||||
/*!
|
||||
Video.js - HTML5 Video Player
|
||||
Version GENERATED_AT_BUILD
|
||||
|
||||
LGPL v3 LICENSE INFO
|
||||
This file is part of Video.js. Copyright 2011 Zencoder, Inc.
|
||||
|
||||
Video.js is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Video.js is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with Video.js. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Self-executing function to prevent global vars and help with minification
|
||||
;(function(window, undefined){
|
||||
var document = window.document;
|
@ -1,6 +0,0 @@
|
||||
|
||||
// Expose to global
|
||||
window.VideoJS = window._V_ = VideoJS;
|
||||
|
||||
// End self-executing function
|
||||
})(window);
|
247
src/component.js
247
src/component.js
@ -1,247 +0,0 @@
|
||||
// Using John Resig's Class implementation http://ejohn.org/blog/simple-javascript-inheritance/
|
||||
// (function(){var initializing=false, fnTest=/xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; _V_.Class = function(){}; _V_.Class.extend = function(prop) { var _super = this.prototype; initializing = true; var prototype = new this(); initializing = false; for (var name in prop) { prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn){ return function() { var tmp = this._super; this._super = _super[name]; var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } function Class() { if ( !initializing && this.init ) this.init.apply(this, arguments); } Class.prototype = prototype; Class.constructor = Class; Class.extend = arguments.callee; return Class;};})();
|
||||
(function(){
|
||||
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
_V_.Class = function(){};
|
||||
_V_.Class.extend = function(prop) {
|
||||
var _super = this.prototype;
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
for (var name in prop) {
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function(name, fn){
|
||||
return function() {
|
||||
var tmp = this._super;
|
||||
this._super = _super[name];
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
function Class() {
|
||||
if ( !initializing && this.init ) {
|
||||
return this.init.apply(this, arguments);
|
||||
|
||||
// Attempting to recreate accessing function form of class.
|
||||
} else if (!initializing) {
|
||||
return arguments.callee.prototype.init()
|
||||
}
|
||||
}
|
||||
Class.prototype = prototype;
|
||||
Class.constructor = Class;
|
||||
Class.extend = arguments.callee;
|
||||
return Class;
|
||||
};
|
||||
})();
|
||||
|
||||
/* Player Component- Base class for all UI objects
|
||||
================================================================================ */
|
||||
_V_.Component = _V_.Class.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this.player = player;
|
||||
|
||||
// Allow for overridding default component options
|
||||
options = this.options = _V_.merge(this.options || {}, options);
|
||||
|
||||
// Create element if one wasn't provided in options
|
||||
if (options.el) {
|
||||
this.el = options.el;
|
||||
} else {
|
||||
this.el = this.createElement();
|
||||
}
|
||||
|
||||
// Add any components in options
|
||||
this.initComponents();
|
||||
},
|
||||
|
||||
destroy: function(){},
|
||||
|
||||
createElement: function(type, attrs){
|
||||
return _V_.createElement(type || "div", attrs);
|
||||
},
|
||||
|
||||
buildCSSClass: function(){
|
||||
// Child classes can include a function that does:
|
||||
// return "CLASS NAME" + this._super();
|
||||
return "";
|
||||
},
|
||||
|
||||
initComponents: function(){
|
||||
var options = this.options;
|
||||
if (options && options.components) {
|
||||
// Loop through components and add them to the player
|
||||
this.eachProp(options.components, function(name, opts){
|
||||
|
||||
// Allow for disabling default components
|
||||
// e.g. _V_.options.components.posterImage = false
|
||||
if (opts === false) return;
|
||||
|
||||
// Allow waiting to add components until a specific event is called
|
||||
var tempAdd = this.proxy(function(){
|
||||
// Set property name on player. Could cause conflicts with other prop names, but it's worth making refs easy.
|
||||
this[name] = this.addComponent(name, opts);
|
||||
});
|
||||
|
||||
if (opts.loadEvent) {
|
||||
this.one(opts.loadEvent, tempAdd)
|
||||
} else {
|
||||
tempAdd();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// Add child components to this component.
|
||||
// Will generate a new child component and then append child component's element to this component's element.
|
||||
// Takes either the name of the UI component class, or an object that contains a name, UI Class, and options.
|
||||
addComponent: function(name, options){
|
||||
var component, componentClass;
|
||||
|
||||
// If string, create new component with options
|
||||
if (typeof name == "string") {
|
||||
|
||||
// Make sure options is at least an empty object to protect against errors
|
||||
options = options || {};
|
||||
|
||||
// Assume name of set is a lowercased name of the UI Class (PlayButton, etc.)
|
||||
componentClass = options.componentClass || _V_.uc(name);
|
||||
|
||||
// Create a new object & element for this controls set
|
||||
// If there's no .player, this is a player
|
||||
component = new _V_[componentClass](this.player || this, options);
|
||||
|
||||
} else {
|
||||
component = name;
|
||||
}
|
||||
|
||||
// Add the UI object's element to the container div (box)
|
||||
this.el.appendChild(component.el);
|
||||
|
||||
// Return so it can stored on parent object if desired.
|
||||
return component;
|
||||
},
|
||||
|
||||
removeComponent: function(component){
|
||||
this.el.removeChild(component.el);
|
||||
},
|
||||
|
||||
/* Display
|
||||
================================================================================ */
|
||||
show: function(){
|
||||
this.el.style.display = "block";
|
||||
},
|
||||
|
||||
hide: function(){
|
||||
this.el.style.display = "none";
|
||||
},
|
||||
|
||||
fadeIn: function(){
|
||||
this.removeClass("vjs-fade-out");
|
||||
this.addClass("vjs-fade-in");
|
||||
},
|
||||
|
||||
fadeOut: function(){
|
||||
this.removeClass("vjs-fade-in");
|
||||
this.addClass("vjs-fade-out");
|
||||
},
|
||||
|
||||
lockShowing: function(){
|
||||
var style = this.el.style;
|
||||
style.display = "block";
|
||||
style.opacity = 1;
|
||||
style.visiblity = "visible";
|
||||
},
|
||||
|
||||
unlockShowing: function(){
|
||||
var style = this.el.style;
|
||||
style.display = "";
|
||||
style.opacity = "";
|
||||
style.visiblity = "";
|
||||
},
|
||||
|
||||
addClass: function(classToAdd){
|
||||
_V_.addClass(this.el, classToAdd);
|
||||
},
|
||||
|
||||
removeClass: function(classToRemove){
|
||||
_V_.removeClass(this.el, classToRemove);
|
||||
},
|
||||
|
||||
/* Events
|
||||
================================================================================ */
|
||||
on: function(type, fn, uid){
|
||||
_V_.on(this.el, type, _V_.proxy(this, fn));
|
||||
return this;
|
||||
},
|
||||
// Deprecated name for 'on' function
|
||||
addEvent: function(){ return this.on.apply(this, arguments); },
|
||||
|
||||
off: function(type, fn){
|
||||
_V_.off(this.el, type, fn);
|
||||
return this;
|
||||
},
|
||||
// Deprecated name for 'off' function
|
||||
removeEvent: function(){ return this.off.apply(this, arguments); },
|
||||
|
||||
trigger: function(type, e){
|
||||
_V_.trigger(this.el, type, e);
|
||||
return this;
|
||||
},
|
||||
// Deprecated name for 'off' function
|
||||
triggerEvent: function(){ return this.trigger.apply(this, arguments); },
|
||||
|
||||
one: function(type, fn) {
|
||||
_V_.one(this.el, type, _V_.proxy(this, fn));
|
||||
return this;
|
||||
},
|
||||
|
||||
/* Ready - Trigger functions when component is ready
|
||||
================================================================================ */
|
||||
ready: function(fn){
|
||||
if (!fn) return this;
|
||||
|
||||
if (this.isReady) {
|
||||
fn.call(this);
|
||||
} else {
|
||||
if (this.readyQueue === undefined) {
|
||||
this.readyQueue = [];
|
||||
}
|
||||
this.readyQueue.push(fn);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
triggerReady: function(){
|
||||
this.isReady = true;
|
||||
if (this.readyQueue && this.readyQueue.length > 0) {
|
||||
// Call all functions in ready queue
|
||||
this.each(this.readyQueue, function(fn){
|
||||
fn.call(this);
|
||||
});
|
||||
|
||||
// Reset Ready Queue
|
||||
this.readyQueue = [];
|
||||
|
||||
// Allow for using event listeners also, in case you want to do something everytime a source is ready.
|
||||
this.trigger("ready");
|
||||
}
|
||||
},
|
||||
|
||||
/* Utility
|
||||
================================================================================ */
|
||||
each: function(arr, fn){ _V_.each.call(this, arr, fn); },
|
||||
|
||||
eachProp: function(obj, fn){ _V_.eachProp.call(this, obj, fn); },
|
||||
|
||||
extend: function(obj){ _V_.merge(this, obj) },
|
||||
|
||||
// More easily attach 'this' to functions
|
||||
proxy: function(fn, uid){ return _V_.proxy(this, fn, uid); }
|
||||
|
||||
});
|
853
src/controls.js
vendored
853
src/controls.js
vendored
@ -1,853 +0,0 @@
|
||||
/* Control - Base class for all control elements
|
||||
================================================================================ */
|
||||
_V_.Control = _V_.Component.extend({
|
||||
|
||||
buildCSSClass: function(){
|
||||
return "vjs-control " + this._super();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Control Bar
|
||||
================================================================================ */
|
||||
_V_.ControlBar = _V_.Component.extend({
|
||||
|
||||
options: {
|
||||
loadEvent: "play",
|
||||
components: {
|
||||
"playToggle": {},
|
||||
"fullscreenToggle": {},
|
||||
"currentTimeDisplay": {},
|
||||
"timeDivider": {},
|
||||
"durationDisplay": {},
|
||||
"remainingTimeDisplay": {},
|
||||
"progressControl": {},
|
||||
"volumeControl": {},
|
||||
"muteToggle": {}
|
||||
}
|
||||
},
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.one("play", this.proxy(function(){
|
||||
this.fadeIn();
|
||||
this.player.on("mouseover", this.proxy(this.fadeIn));
|
||||
this.player.on("mouseout", this.proxy(this.fadeOut));
|
||||
}));
|
||||
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return _V_.createElement("div", {
|
||||
className: "vjs-controls"
|
||||
});
|
||||
},
|
||||
|
||||
fadeIn: function(){
|
||||
this._super();
|
||||
this.player.trigger("controlsvisible");
|
||||
},
|
||||
|
||||
fadeOut: function(){
|
||||
this._super();
|
||||
this.player.trigger("controlshidden");
|
||||
},
|
||||
|
||||
lockShowing: function(){
|
||||
this.el.style.opacity = "1";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Button - Base class for all buttons
|
||||
================================================================================ */
|
||||
_V_.Button = _V_.Control.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
this.on("click", this.onClick);
|
||||
this.on("focus", this.onFocus);
|
||||
this.on("blur", this.onBlur);
|
||||
},
|
||||
|
||||
createElement: function(type, attrs){
|
||||
// Add standard Aria and Tabindex info
|
||||
attrs = _V_.merge({
|
||||
className: this.buildCSSClass(),
|
||||
innerHTML: '<div><span class="vjs-control-text">' + (this.buttonText || "Need Text") + '</span></div>',
|
||||
role: "button",
|
||||
tabIndex: 0
|
||||
}, attrs);
|
||||
|
||||
return this._super(type, attrs);
|
||||
},
|
||||
|
||||
// Click - Override with specific functionality for button
|
||||
onClick: function(){},
|
||||
|
||||
// Focus - Add keyboard functionality to element
|
||||
onFocus: function(){
|
||||
_V_.on(document, "keyup", _V_.proxy(this, this.onKeyPress));
|
||||
},
|
||||
|
||||
// KeyPress (document level) - Trigger click when keys are pressed
|
||||
onKeyPress: function(event){
|
||||
// Check for space bar (32) or enter (13) keys
|
||||
if (event.which == 32 || event.which == 13) {
|
||||
event.preventDefault();
|
||||
this.onClick();
|
||||
}
|
||||
},
|
||||
|
||||
// Blur - Remove keyboard triggers
|
||||
onBlur: function(){
|
||||
_V_.off(document, "keyup", _V_.proxy(this, this.onKeyPress));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Play Button
|
||||
================================================================================ */
|
||||
_V_.PlayButton = _V_.Button.extend({
|
||||
|
||||
buttonText: "Play",
|
||||
|
||||
buildCSSClass: function(){
|
||||
return "vjs-play-button " + this._super();
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this.player.play();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Pause Button
|
||||
================================================================================ */
|
||||
_V_.PauseButton = _V_.Button.extend({
|
||||
|
||||
buttonText: "Pause",
|
||||
|
||||
buildCSSClass: function(){
|
||||
return "vjs-pause-button " + this._super();
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this.player.pause();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Play Toggle - Play or Pause Media
|
||||
================================================================================ */
|
||||
_V_.PlayToggle = _V_.Button.extend({
|
||||
|
||||
buttonText: "Play",
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("play", _V_.proxy(this, this.onPlay));
|
||||
player.on("pause", _V_.proxy(this, this.onPause));
|
||||
},
|
||||
|
||||
buildCSSClass: function(){
|
||||
return "vjs-play-control " + this._super();
|
||||
},
|
||||
|
||||
// OnClick - Toggle between play and pause
|
||||
onClick: function(){
|
||||
if (this.player.paused()) {
|
||||
this.player.play();
|
||||
} else {
|
||||
this.player.pause();
|
||||
}
|
||||
},
|
||||
|
||||
// OnPlay - Add the vjs-playing class to the element so it can change appearance
|
||||
onPlay: function(){
|
||||
_V_.removeClass(this.el, "vjs-paused");
|
||||
_V_.addClass(this.el, "vjs-playing");
|
||||
},
|
||||
|
||||
// OnPause - Add the vjs-paused class to the element so it can change appearance
|
||||
onPause: function(){
|
||||
_V_.removeClass(this.el, "vjs-playing");
|
||||
_V_.addClass(this.el, "vjs-paused");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Fullscreen Toggle Behaviors
|
||||
================================================================================ */
|
||||
_V_.FullscreenToggle = _V_.Button.extend({
|
||||
|
||||
buttonText: "Fullscreen",
|
||||
|
||||
buildCSSClass: function(){
|
||||
return "vjs-fullscreen-control " + this._super();
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
if (!this.player.isFullScreen) {
|
||||
this.player.requestFullScreen();
|
||||
} else {
|
||||
this.player.cancelFullScreen();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Big Play Button
|
||||
================================================================================ */
|
||||
_V_.BigPlayButton = _V_.Button.extend({
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("play", _V_.proxy(this, this.hide));
|
||||
player.on("ended", _V_.proxy(this, this.show));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-big-play-button",
|
||||
innerHTML: "<span></span>"
|
||||
});
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
// Go back to the beginning if big play button is showing at the end.
|
||||
// Have to check for current time otherwise it might throw a 'not ready' error.
|
||||
if(this.player.currentTime()) {
|
||||
this.player.currentTime(0);
|
||||
}
|
||||
this.player.play();
|
||||
}
|
||||
});
|
||||
|
||||
/* Loading Spinner
|
||||
================================================================================ */
|
||||
_V_.LoadingSpinner = _V_.Component.extend({
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("canplay", _V_.proxy(this, this.hide));
|
||||
player.on("canplaythrough", _V_.proxy(this, this.hide));
|
||||
player.on("playing", _V_.proxy(this, this.hide));
|
||||
player.on("seeked", _V_.proxy(this, this.hide));
|
||||
|
||||
player.addEvent("seeking", _V_.proxy(this, this.show));
|
||||
|
||||
// in some browsers seeking does not trigger the 'playing' event,
|
||||
// so we also need to trap 'seeked' if we are going to set a
|
||||
// 'seeking' event
|
||||
player.addEvent("seeked", _V_.proxy(this, this.hide));
|
||||
|
||||
player.addEvent("error", _V_.proxy(this, this.show));
|
||||
|
||||
// Not showing spinner on stalled any more. Browsers may stall and then not trigger any events that would remove the spinner.
|
||||
// Checked in Chrome 16 and Safari 5.1.2. http://help.videojs.com/discussions/problems/883-why-is-the-download-progress-showing
|
||||
// player.on("stalled", _V_.proxy(this, this.show));
|
||||
|
||||
player.on("waiting", _V_.proxy(this, this.show));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
|
||||
var classNameSpinner, innerHtmlSpinner;
|
||||
|
||||
if ( typeof this.player.el.style.WebkitBorderRadius == "string"
|
||||
|| typeof this.player.el.style.MozBorderRadius == "string"
|
||||
|| typeof this.player.el.style.KhtmlBorderRadius == "string"
|
||||
|| typeof this.player.el.style.borderRadius == "string")
|
||||
{
|
||||
classNameSpinner = "vjs-loading-spinner";
|
||||
innerHtmlSpinner = "<div class='ball1'></div><div class='ball2'></div><div class='ball3'></div><div class='ball4'></div><div class='ball5'></div><div class='ball6'></div><div class='ball7'></div><div class='ball8'></div>";
|
||||
} else {
|
||||
classNameSpinner = "vjs-loading-spinner-fallback";
|
||||
innerHtmlSpinner = "";
|
||||
}
|
||||
|
||||
return this._super("div", {
|
||||
className: classNameSpinner,
|
||||
innerHTML: innerHtmlSpinner
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* Time
|
||||
================================================================================ */
|
||||
_V_.CurrentTimeDisplay = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("timeupdate", _V_.proxy(this, this.updateContent));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
var el = this._super("div", {
|
||||
className: "vjs-current-time vjs-time-controls vjs-control"
|
||||
});
|
||||
|
||||
this.content = _V_.createElement("div", {
|
||||
className: "vjs-current-time-display",
|
||||
innerHTML: '0:00'
|
||||
});
|
||||
|
||||
el.appendChild(_V_.createElement("div").appendChild(this.content));
|
||||
return el;
|
||||
},
|
||||
|
||||
updateContent: function(){
|
||||
// Allows for smooth scrubbing, when player can't keep up.
|
||||
var time = (this.player.scrubbing) ? this.player.values.currentTime : this.player.currentTime();
|
||||
this.content.innerHTML = _V_.formatTime(time, this.player.duration());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.DurationDisplay = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("timeupdate", _V_.proxy(this, this.updateContent));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
var el = this._super("div", {
|
||||
className: "vjs-duration vjs-time-controls vjs-control"
|
||||
});
|
||||
|
||||
this.content = _V_.createElement("div", {
|
||||
className: "vjs-duration-display",
|
||||
innerHTML: '0:00'
|
||||
});
|
||||
|
||||
el.appendChild(_V_.createElement("div").appendChild(this.content));
|
||||
return el;
|
||||
},
|
||||
|
||||
updateContent: function(){
|
||||
if (this.player.duration()) { this.content.innerHTML = _V_.formatTime(this.player.duration()); }
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Time Separator (Not used in main skin, but still available, and could be used as a 'spare element')
|
||||
_V_.TimeDivider = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-time-divider",
|
||||
innerHTML: '<div><span>/</span></div>'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.RemainingTimeDisplay = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("timeupdate", _V_.proxy(this, this.updateContent));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
var el = this._super("div", {
|
||||
className: "vjs-remaining-time vjs-time-controls vjs-control"
|
||||
});
|
||||
|
||||
this.content = _V_.createElement("div", {
|
||||
className: "vjs-remaining-time-display",
|
||||
innerHTML: '-0:00'
|
||||
});
|
||||
|
||||
el.appendChild(_V_.createElement("div").appendChild(this.content));
|
||||
return el;
|
||||
},
|
||||
|
||||
updateContent: function(){
|
||||
if (this.player.duration()) { this.content.innerHTML = "-"+_V_.formatTime(this.player.remainingTime()); }
|
||||
|
||||
// Allows for smooth scrubbing, when player can't keep up.
|
||||
// var time = (this.player.scrubbing) ? this.player.values.currentTime : this.player.currentTime();
|
||||
// this.content.innerHTML = _V_.formatTime(time, this.player.duration());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Slider - Parent for seek bar and volume slider
|
||||
================================================================================ */
|
||||
_V_.Slider = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on(this.playerEvent, _V_.proxy(this, this.update));
|
||||
|
||||
this.on("mousedown", this.onMouseDown);
|
||||
this.on("focus", this.onFocus);
|
||||
this.on("blur", this.onBlur);
|
||||
|
||||
this.player.on("controlsvisible", this.proxy(this.update));
|
||||
|
||||
// This is actually to fix the volume handle position. http://twitter.com/#!/gerritvanaaken/status/159046254519787520
|
||||
// this.player.one("timeupdate", this.proxy(this.update));
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
createElement: function(type, attrs) {
|
||||
attrs = _V_.merge({
|
||||
role: "slider",
|
||||
"aria-valuenow": 0,
|
||||
"aria-valuemin": 0,
|
||||
"aria-valuemax": 100,
|
||||
tabIndex: 0
|
||||
}, attrs);
|
||||
|
||||
return this._super(type, attrs);
|
||||
},
|
||||
|
||||
onMouseDown: function(event){
|
||||
event.preventDefault();
|
||||
_V_.blockTextSelection();
|
||||
|
||||
_V_.on(document, "mousemove", _V_.proxy(this, this.onMouseMove));
|
||||
_V_.on(document, "mouseup", _V_.proxy(this, this.onMouseUp));
|
||||
|
||||
this.onMouseMove(event);
|
||||
},
|
||||
|
||||
onMouseUp: function(event) {
|
||||
_V_.unblockTextSelection();
|
||||
_V_.off(document, "mousemove", this.onMouseMove, false);
|
||||
_V_.off(document, "mouseup", this.onMouseUp, false);
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
update: function(){
|
||||
// If scrubbing, we could use a cached value to make the handle keep up with the user's mouse.
|
||||
// On HTML5 browsers scrubbing is really smooth, but some flash players are slow, so we might want to utilize this later.
|
||||
// var progress = (this.player.scrubbing) ? this.player.values.currentTime / this.player.duration() : this.player.currentTime() / this.player.duration();
|
||||
|
||||
var barProgress,
|
||||
progress = this.getPercent();
|
||||
handle = this.handle,
|
||||
bar = this.bar;
|
||||
|
||||
// Protect against no duration and other division issues
|
||||
if (isNaN(progress)) { progress = 0; }
|
||||
|
||||
barProgress = progress;
|
||||
|
||||
// If there is a handle, we need to account for the handle in our calculation for progress bar
|
||||
// so that it doesn't fall short of or extend past the handle.
|
||||
if (handle) {
|
||||
|
||||
var box = this.el,
|
||||
boxWidth = box.offsetWidth,
|
||||
|
||||
handleWidth = handle.el.offsetWidth,
|
||||
|
||||
// The width of the handle in percent of the containing box
|
||||
// In IE, widths may not be ready yet causing NaN
|
||||
handlePercent = (handleWidth) ? handleWidth / boxWidth : 0,
|
||||
|
||||
// Get the adjusted size of the box, considering that the handle's center never touches the left or right side.
|
||||
// There is a margin of half the handle's width on both sides.
|
||||
boxAdjustedPercent = 1 - handlePercent;
|
||||
|
||||
// Adjust the progress that we'll use to set widths to the new adjusted box width
|
||||
adjustedProgress = progress * boxAdjustedPercent,
|
||||
|
||||
// The bar does reach the left side, so we need to account for this in the bar's width
|
||||
barProgress = adjustedProgress + (handlePercent / 2);
|
||||
|
||||
// Move the handle from the left based on the adjected progress
|
||||
handle.el.style.left = _V_.round(adjustedProgress * 100, 2) + "%";
|
||||
}
|
||||
|
||||
// Set the new bar width
|
||||
bar.el.style.width = _V_.round(barProgress * 100, 2) + "%";
|
||||
},
|
||||
|
||||
calculateDistance: function(event){
|
||||
var box = this.el,
|
||||
boxX = _V_.findPosX(box),
|
||||
boxW = box.offsetWidth,
|
||||
handle = this.handle;
|
||||
|
||||
if (handle) {
|
||||
var handleW = handle.el.offsetWidth;
|
||||
|
||||
// Adjusted X and Width, so handle doesn't go outside the bar
|
||||
boxX = boxX + (handleW / 2);
|
||||
boxW = boxW - handleW;
|
||||
}
|
||||
|
||||
// Percent that the click is through the adjusted area
|
||||
return Math.max(0, Math.min(1, (event.pageX - boxX) / boxW));
|
||||
},
|
||||
|
||||
onFocus: function(event){
|
||||
_V_.on(document, "keyup", _V_.proxy(this, this.onKeyPress));
|
||||
},
|
||||
|
||||
onKeyPress: function(event){
|
||||
if (event.which == 37) { // Left Arrow
|
||||
event.preventDefault();
|
||||
this.stepBack();
|
||||
} else if (event.which == 39) { // Right Arrow
|
||||
event.preventDefault();
|
||||
this.stepForward();
|
||||
}
|
||||
},
|
||||
|
||||
onBlur: function(event){
|
||||
_V_.off(document, "keyup", _V_.proxy(this, this.onKeyPress));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/* Progress
|
||||
================================================================================ */
|
||||
|
||||
// Progress Control: Seek, Load Progress, and Play Progress
|
||||
_V_.ProgressControl = _V_.Component.extend({
|
||||
|
||||
options: {
|
||||
components: {
|
||||
"seekBar": {}
|
||||
}
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-progress-control vjs-control"
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Seek Bar and holder for the progress bars
|
||||
_V_.SeekBar = _V_.Slider.extend({
|
||||
|
||||
options: {
|
||||
components: {
|
||||
"loadProgressBar": {},
|
||||
|
||||
// Set property names to bar and handle to match with the parent Slider class is looking for
|
||||
"bar": { componentClass: "PlayProgressBar" },
|
||||
"handle": { componentClass: "SeekHandle" }
|
||||
}
|
||||
},
|
||||
|
||||
playerEvent: "timeupdate",
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-progress-holder"
|
||||
});
|
||||
},
|
||||
|
||||
getPercent: function(){
|
||||
return this.player.currentTime() / this.player.duration();
|
||||
},
|
||||
|
||||
onMouseDown: function(event){
|
||||
this._super(event);
|
||||
|
||||
this.player.scrubbing = true;
|
||||
|
||||
this.videoWasPlaying = !this.player.paused();
|
||||
this.player.pause();
|
||||
},
|
||||
|
||||
onMouseMove: function(event){
|
||||
var newTime = this.calculateDistance(event) * this.player.duration();
|
||||
|
||||
// Don't let video end while scrubbing.
|
||||
if (newTime == this.player.duration()) { newTime = newTime - 0.1; }
|
||||
|
||||
// Set new time (tell player to seek to new time)
|
||||
this.player.currentTime(newTime);
|
||||
},
|
||||
|
||||
onMouseUp: function(event){
|
||||
this._super(event);
|
||||
|
||||
this.player.scrubbing = false;
|
||||
if (this.videoWasPlaying) {
|
||||
this.player.play();
|
||||
}
|
||||
},
|
||||
|
||||
stepForward: function(){
|
||||
this.player.currentTime(this.player.currentTime() + 1);
|
||||
},
|
||||
|
||||
stepBack: function(){
|
||||
this.player.currentTime(this.player.currentTime() - 1);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Load Progress Bar
|
||||
_V_.LoadProgressBar = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
player.on("progress", _V_.proxy(this, this.update));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-load-progress",
|
||||
innerHTML: '<span class="vjs-control-text">Loaded: 0%</span>'
|
||||
});
|
||||
},
|
||||
|
||||
update: function(){
|
||||
if (this.el.style) { this.el.style.width = _V_.round(this.player.bufferedPercent() * 100, 2) + "%"; }
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Play Progress Bar
|
||||
_V_.PlayProgressBar = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-play-progress",
|
||||
innerHTML: '<span class="vjs-control-text">Progress: 0%</span>'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Seek Handle
|
||||
// SeekBar Behavior includes play progress bar, and seek handle
|
||||
// Needed so it can determine seek position based on handle position/size
|
||||
_V_.SeekHandle = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-seek-handle",
|
||||
innerHTML: '<span class="vjs-control-text">00:00</span>'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Volume Scrubber
|
||||
================================================================================ */
|
||||
// Progress Control: Seek, Load Progress, and Play Progress
|
||||
_V_.VolumeControl = _V_.Component.extend({
|
||||
|
||||
options: {
|
||||
components: {
|
||||
"volumeBar": {}
|
||||
}
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-volume-control vjs-control"
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.VolumeBar = _V_.Slider.extend({
|
||||
|
||||
options: {
|
||||
components: {
|
||||
"bar": { componentClass: "VolumeLevel" },
|
||||
"handle": { componentClass: "VolumeHandle" }
|
||||
}
|
||||
},
|
||||
|
||||
playerEvent: "volumechange",
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-volume-bar"
|
||||
});
|
||||
},
|
||||
|
||||
onMouseMove: function(event) {
|
||||
this.player.volume(this.calculateDistance(event));
|
||||
},
|
||||
|
||||
getPercent: function(){
|
||||
return this.player.volume();
|
||||
},
|
||||
|
||||
stepForward: function(){
|
||||
this.player.volume(this.player.volume() + 0.1);
|
||||
},
|
||||
|
||||
stepBack: function(){
|
||||
this.player.volume(this.player.volume() - 0.1);
|
||||
}
|
||||
});
|
||||
|
||||
_V_.VolumeLevel = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-volume-level",
|
||||
innerHTML: '<span class="vjs-control-text"></span>'
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.VolumeHandle = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-volume-handle",
|
||||
innerHTML: '<span class="vjs-control-text"></span>'
|
||||
// tabindex: 0,
|
||||
// role: "slider", "aria-valuenow": 0, "aria-valuemin": 0, "aria-valuemax": 100
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.MuteToggle = _V_.Button.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
player.on("volumechange", _V_.proxy(this, this.update));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-mute-control vjs-control",
|
||||
innerHTML: '<div><span class="vjs-control-text">Mute</span></div>'
|
||||
});
|
||||
},
|
||||
|
||||
onClick: function(event){
|
||||
this.player.muted( this.player.muted() ? false : true );
|
||||
},
|
||||
|
||||
update: function(event){
|
||||
var vol = this.player.volume(),
|
||||
level = 3;
|
||||
|
||||
if (vol == 0 || this.player.muted()) {
|
||||
level = 0;
|
||||
} else if (vol < 0.33) {
|
||||
level = 1;
|
||||
} else if (vol < 0.67) {
|
||||
level = 2;
|
||||
}
|
||||
|
||||
/* TODO improve muted icon classes */
|
||||
_V_.each.call(this, [0,1,2,3], function(i){
|
||||
_V_.removeClass(this.el, "vjs-vol-"+i);
|
||||
});
|
||||
_V_.addClass(this.el, "vjs-vol-"+level);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Poster Image
|
||||
================================================================================ */
|
||||
_V_.PosterImage = _V_.Button.extend({
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
if (!this.player.options.poster) {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
player.on("play", _V_.proxy(this, this.hide));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return _V_.createElement("img", {
|
||||
className: "vjs-poster",
|
||||
src: this.player.options.poster,
|
||||
|
||||
// Don't want poster to be tabbable.
|
||||
tabIndex: -1
|
||||
});
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this.player.play();
|
||||
}
|
||||
});
|
||||
|
||||
/* Menu
|
||||
================================================================================ */
|
||||
// The base for text track and settings menu buttons.
|
||||
_V_.Menu = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
},
|
||||
|
||||
addItem: function(component){
|
||||
this.addComponent(component);
|
||||
component.on("click", this.proxy(function(){
|
||||
this.unlockShowing();
|
||||
}));
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
return this._super("ul", {
|
||||
className: "vjs-menu"
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.MenuItem = _V_.Button.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
if (options.selected) {
|
||||
this.addClass("vjs-selected");
|
||||
}
|
||||
},
|
||||
|
||||
createElement: function(type, attrs){
|
||||
return this._super("li", _V_.merge({
|
||||
className: "vjs-menu-item",
|
||||
innerHTML: this.options.label
|
||||
}, attrs));
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this.selected(true);
|
||||
},
|
||||
|
||||
selected: function(selected){
|
||||
if (selected) {
|
||||
this.addClass("vjs-selected");
|
||||
} else {
|
||||
this.removeClass("vjs-selected")
|
||||
}
|
||||
}
|
||||
|
||||
});
|
116
src/core.js
116
src/core.js
@ -1,116 +0,0 @@
|
||||
// HTML5 Shiv. Must be in <head> to support older browsers.
|
||||
document.createElement("video");document.createElement("audio");
|
||||
|
||||
var VideoJS = function(id, addOptions, ready){
|
||||
var tag; // Element of ID
|
||||
|
||||
// Allow for element or ID to be passed in
|
||||
// String ID
|
||||
if (typeof id == "string") {
|
||||
|
||||
// Adjust for jQuery ID syntax
|
||||
if (id.indexOf("#") === 0) {
|
||||
id = id.slice(1);
|
||||
}
|
||||
|
||||
// If a player instance has already been created for this ID return it.
|
||||
if (_V_.players[id]) {
|
||||
return _V_.players[id];
|
||||
|
||||
// Otherwise get element for ID
|
||||
} else {
|
||||
tag = _V_.el(id)
|
||||
}
|
||||
|
||||
// ID is a media element
|
||||
} else {
|
||||
tag = id;
|
||||
}
|
||||
|
||||
// Check for a useable element
|
||||
if (!tag || !tag.nodeName) { // re: nodeName, could be a box div also
|
||||
throw new TypeError("The element or ID supplied is not valid. (VideoJS)"); // Returns
|
||||
}
|
||||
|
||||
// Element may have a player attr referring to an already created player instance.
|
||||
// If not, set up a new player and return the instance.
|
||||
return tag.player || new _V_.Player(tag, addOptions, ready);
|
||||
},
|
||||
|
||||
// Shortcut
|
||||
_V_ = VideoJS,
|
||||
|
||||
// CDN Version. Used to target right flash swf.
|
||||
CDN_VERSION = "GENERATED_CDN_VSN";
|
||||
|
||||
VideoJS.players = {};
|
||||
|
||||
VideoJS.options = {
|
||||
|
||||
// Default order of fallback technology
|
||||
techOrder: ["html5","flash"],
|
||||
// techOrder: ["flash","html5"],
|
||||
|
||||
html5: {},
|
||||
flash: { swf: "http://vjs.zencdn.net/c/video-js.swf" },
|
||||
|
||||
// Default of web browser is 300x150. Should rely on source width/height.
|
||||
width: 300,
|
||||
height: 150,
|
||||
|
||||
// defaultVolume: 0.85,
|
||||
defaultVolume: 0.00, // The freakin seaguls are driving me crazy!
|
||||
|
||||
// Included control sets
|
||||
components: {
|
||||
"posterImage": {},
|
||||
"textTrackDisplay": {},
|
||||
"loadingSpinner": {},
|
||||
"bigPlayButton": {},
|
||||
"controlBar": {}
|
||||
}
|
||||
|
||||
// components: [
|
||||
// "poster",
|
||||
// "loadingSpinner",
|
||||
// "bigPlayButton",
|
||||
// { name: "controlBar", options: {
|
||||
// components: [
|
||||
// "playToggle",
|
||||
// "fullscreenToggle",
|
||||
// "currentTimeDisplay",
|
||||
// "timeDivider",
|
||||
// "durationDisplay",
|
||||
// "remainingTimeDisplay",
|
||||
// { name: "progressControl", options: {
|
||||
// components: [
|
||||
// { name: "seekBar", options: {
|
||||
// components: [
|
||||
// "loadProgressBar",
|
||||
// "playProgressBar",
|
||||
// "seekHandle"
|
||||
// ]}
|
||||
// }
|
||||
// ]}
|
||||
// },
|
||||
// { name: "volumeControl", options: {
|
||||
// components: [
|
||||
// { name: "volumeBar", options: {
|
||||
// components: [
|
||||
// "volumeLevel",
|
||||
// "volumeHandle"
|
||||
// ]}
|
||||
// }
|
||||
// ]}
|
||||
// },
|
||||
// "muteToggle"
|
||||
// ]
|
||||
// }},
|
||||
// "subtitlesDisplay"/*, "replay"*/
|
||||
// ]
|
||||
};
|
||||
|
||||
// Set CDN Version of swf
|
||||
if (CDN_VERSION != "GENERATED_CDN_VSN") {
|
||||
_V_.options.flash.swf = "http://vjs.zencdn.net/"+CDN_VERSION+"/video-js.swf"
|
||||
}
|
@ -92,7 +92,7 @@ Instead of editing this file, I recommend creating your own skin CSS file to be
|
||||
so you can upgrade to newer versions easier. You can remove all these styles by removing the 'vjs-default-skin' class from the tag. */
|
||||
|
||||
/* The default control bar. Created by bar.js */
|
||||
.vjs-default-skin .vjs-controls {
|
||||
.vjs-default-skin .vjs-control-bar {
|
||||
position: absolute;
|
||||
bottom: 0; /* Distance from the bottom of the box/video. Keep 0. Use height to add more bottom margin. */
|
||||
left: 0; right: 0; /* 100% width of div */
|
||||
@ -496,4 +496,4 @@ div.vjs-loading-spinner .ball8 { opacity: 1.00; position:absolute; left: 6px; to
|
||||
/* Subtitles Button */
|
||||
.vjs-default-skin .vjs-captions-button div { background-position: -25px -75px; }
|
||||
.vjs-default-skin .vjs-chapters-button div { background-position: -100px -75px; }
|
||||
.vjs-default-skin .vjs-chapters-button ul { width: 20em; left: -8.5em; /* Width of menu - width of button / 2 */ }
|
||||
.vjs-default-skin .vjs-chapters-button ul { width: 20em; left: -8.5em; /* Width of menu - width of button / 2 */ }
|
BIN
src/css/video-js.fw.png
Normal file
BIN
src/css/video-js.fw.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
308
src/events.js
308
src/events.js
@ -1,308 +0,0 @@
|
||||
// Event System (J.Resig - Secrets of a JS Ninja http://jsninja.com/ [Go read it, really])
|
||||
// (Book version isn't completely usable, so fixed some things and borrowed from jQuery where it's working)
|
||||
//
|
||||
// This should work very similarly to jQuery's events, however it's based off the book version which isn't as
|
||||
// robust as jquery's, so there's probably some differences.
|
||||
//
|
||||
// When you add an event listener using _V_.addEvent,
|
||||
// it stores the handler function in seperate cache object,
|
||||
// and adds a generic handler to the element's event,
|
||||
// along with a unique id (guid) to the element.
|
||||
|
||||
_V_.extend({
|
||||
|
||||
// Add an event listener to element
|
||||
// It stores the handler function in a separate cache object
|
||||
// and adds a generic handler to the element's event,
|
||||
// along with a unique id (guid) to the element.
|
||||
on: function(elem, type, fn){
|
||||
var data = _V_.getData(elem), handlers;
|
||||
|
||||
// We only need to generate one handler per element
|
||||
if (data && !data.handler) {
|
||||
// Our new meta-handler that fixes the event object and the context
|
||||
data.handler = function(event){
|
||||
event = _V_.fixEvent(event);
|
||||
var handlers = _V_.getData(elem).events[event.type];
|
||||
// Go through and call all the real bound handlers
|
||||
if (handlers) {
|
||||
|
||||
// Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
|
||||
var handlersCopy = [];
|
||||
_V_.each(handlers, function(handler, i){
|
||||
handlersCopy[i] = handler;
|
||||
})
|
||||
|
||||
for (var i = 0, l = handlersCopy.length; i < l; i++) {
|
||||
handlersCopy[i].call(elem, event);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// We need a place to store all our event data
|
||||
if (!data.events) { data.events = {}; }
|
||||
|
||||
// And a place to store the handlers for this event type
|
||||
handlers = data.events[type];
|
||||
|
||||
if (!handlers) {
|
||||
handlers = data.events[ type ] = [];
|
||||
|
||||
// Attach our meta-handler to the element, since one doesn't exist
|
||||
if (document.addEventListener) {
|
||||
elem.addEventListener(type, data.handler, false);
|
||||
} else if (document.attachEvent) {
|
||||
elem.attachEvent("on" + type, data.handler);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fn.guid) { fn.guid = _V_.guid++; }
|
||||
|
||||
handlers.push(fn);
|
||||
},
|
||||
// Deprecated name for 'on' function
|
||||
addEvent: function(){ return _V_.on.apply(this, arguments); },
|
||||
|
||||
off: function(elem, type, fn) {
|
||||
var data = _V_.getData(elem), handlers;
|
||||
// If no events exist, nothing to unbind
|
||||
if (!data.events) { return; }
|
||||
|
||||
// Are we removing all bound events?
|
||||
if (!type) {
|
||||
for (type in data.events) {
|
||||
_V_.cleanUpEvents(elem, type);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// And a place to store the handlers for this event type
|
||||
handlers = data.events[type];
|
||||
|
||||
// If no handlers exist, nothing to unbind
|
||||
if (!handlers) { return; }
|
||||
|
||||
// See if we're only removing a single handler
|
||||
if (fn && fn.guid) {
|
||||
for (var i = 0; i < handlers.length; i++) {
|
||||
// We found a match (don't stop here, there could be a couple bound)
|
||||
if (handlers[i].guid === fn.guid) {
|
||||
// Remove the handler from the array of handlers
|
||||
handlers.splice(i--, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_V_.cleanUpEvents(elem, type);
|
||||
},
|
||||
// Deprecated name for 'on' function
|
||||
removeEvent: function(){ return _V_.off.apply(this, arguments); },
|
||||
|
||||
cleanUpEvents: function(elem, type) {
|
||||
var data = _V_.getData(elem);
|
||||
// Remove the events of a particular type if there are none left
|
||||
|
||||
if (data.events[type].length === 0) {
|
||||
delete data.events[type];
|
||||
|
||||
// Remove the meta-handler from the element
|
||||
if (document.removeEventListener) {
|
||||
elem.removeEventListener(type, data.handler, false);
|
||||
} else if (document.detachEvent) {
|
||||
elem.detachEvent("on" + type, data.handler);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the events object if there are no types left
|
||||
if (_V_.isEmpty(data.events)) {
|
||||
delete data.events;
|
||||
delete data.handler;
|
||||
}
|
||||
|
||||
// Finally remove the expando if there is no data left
|
||||
if (_V_.isEmpty(data)) {
|
||||
_V_.removeData(elem);
|
||||
}
|
||||
},
|
||||
|
||||
fixEvent: function(event) {
|
||||
if (event[_V_.expando]) { return event; }
|
||||
// store a copy of the original event object
|
||||
// and "clone" to set read-only properties
|
||||
var originalEvent = event;
|
||||
event = new _V_.Event(originalEvent);
|
||||
|
||||
for ( var i = _V_.Event.props.length, prop; i; ) {
|
||||
prop = _V_.Event.props[ --i ];
|
||||
event[prop] = originalEvent[prop];
|
||||
}
|
||||
|
||||
// Fix target property, if necessary
|
||||
if (!event.target) { event.target = event.srcElement || document; }
|
||||
|
||||
// check if target is a textnode (safari)
|
||||
if (event.target.nodeType === 3) { event.target = event.target.parentNode; }
|
||||
|
||||
// Add relatedTarget, if necessary
|
||||
if (!event.relatedTarget && event.fromElement) {
|
||||
event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
|
||||
}
|
||||
|
||||
// Calculate pageX/Y if missing and clientX/Y available
|
||||
if ( event.pageX == null && event.clientX != null ) {
|
||||
var eventDocument = event.target.ownerDocument || document,
|
||||
doc = eventDocument.documentElement,
|
||||
body = eventDocument.body;
|
||||
|
||||
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
|
||||
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
|
||||
}
|
||||
|
||||
// Add which for key events
|
||||
if (event.which == null && (event.charCode != null || event.keyCode != null)) {
|
||||
event.which = event.charCode != null ? event.charCode : event.keyCode;
|
||||
}
|
||||
|
||||
// Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
|
||||
if ( !event.metaKey && event.ctrlKey ) {
|
||||
event.metaKey = event.ctrlKey;
|
||||
}
|
||||
|
||||
// Add which for click: 1 === left; 2 === middle; 3 === right
|
||||
// Note: button is not normalized, so don't use it
|
||||
if ( !event.which && event.button !== undefined ) {
|
||||
event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
|
||||
}
|
||||
|
||||
return event;
|
||||
},
|
||||
|
||||
trigger: function(elem, event) {
|
||||
var data = _V_.getData(elem),
|
||||
parent = elem.parentNode || elem.ownerDocument,
|
||||
type = event.type || event,
|
||||
handler;
|
||||
|
||||
if (data) { handler = data.handler }
|
||||
|
||||
// Added in attion to book. Book code was broke.
|
||||
event = typeof event === "object" ?
|
||||
event[_V_.expando] ?
|
||||
event :
|
||||
new _V_.Event(type, event) :
|
||||
new _V_.Event(type);
|
||||
|
||||
event.type = type;
|
||||
if (handler) {
|
||||
handler.call(elem, event);
|
||||
}
|
||||
|
||||
// Clean up the event in case it is being reused
|
||||
event.result = undefined;
|
||||
event.target = elem;
|
||||
|
||||
// Bubble the event up the tree to the document,
|
||||
// Unless it's been explicitly stopped
|
||||
// if (parent && !event.isPropagationStopped()) {
|
||||
// _V_.triggerEvent(parent, event);
|
||||
//
|
||||
// // We're at the top document so trigger the default action
|
||||
// } else if (!parent && !event.isDefaultPrevented()) {
|
||||
// // log(type);
|
||||
// var targetData = _V_.getData(event.target);
|
||||
// // log(targetData);
|
||||
// var targetHandler = targetData.handler;
|
||||
// // log("2");
|
||||
// if (event.target[event.type]) {
|
||||
// // Temporarily disable the bound handler,
|
||||
// // don't want to execute it twice
|
||||
// if (targetHandler) {
|
||||
// targetData.handler = function(){};
|
||||
// }
|
||||
//
|
||||
// // Trigger the native event (click, focus, blur)
|
||||
// event.target[event.type]();
|
||||
//
|
||||
// // Restore the handler
|
||||
// if (targetHandler) {
|
||||
// targetData.handler = targetHandler;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
},
|
||||
// Deprecated name for 'on' function
|
||||
triggerEvent: function(){ return _V_.trigger.apply(this, arguments); },
|
||||
|
||||
one: function(elem, type, fn) {
|
||||
_V_.on(elem, type, function(){
|
||||
_V_.off(elem, type, arguments.callee)
|
||||
fn.apply(this, arguments);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Custom Event object for standardizing event objects between browsers.
|
||||
_V_.Event = function(src, props){
|
||||
// Event object
|
||||
if (src && src.type) {
|
||||
this.originalEvent = src;
|
||||
this.type = src.type;
|
||||
|
||||
// Events bubbling up the document may have been marked as prevented
|
||||
// by a handler lower down the tree; reflect the correct value.
|
||||
this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false ||
|
||||
src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;
|
||||
|
||||
// Event type
|
||||
} else {
|
||||
this.type = src;
|
||||
}
|
||||
|
||||
// Put explicitly provided properties onto the event object
|
||||
if (props) { _V_.merge(this, props); }
|
||||
|
||||
this.timeStamp = (new Date).getTime();
|
||||
|
||||
// Mark it as fixed
|
||||
this[_V_.expando] = true;
|
||||
};
|
||||
|
||||
_V_.Event.prototype = {
|
||||
preventDefault: function() {
|
||||
this.isDefaultPrevented = returnTrue;
|
||||
|
||||
var e = this.originalEvent;
|
||||
if (!e) { return; }
|
||||
|
||||
// if preventDefault exists run it on the original event
|
||||
if (e.preventDefault) {
|
||||
e.preventDefault();
|
||||
// otherwise set the returnValue property of the original event to false (IE)
|
||||
} else {
|
||||
e.returnValue = false;
|
||||
}
|
||||
},
|
||||
stopPropagation: function() {
|
||||
this.isPropagationStopped = returnTrue;
|
||||
|
||||
var e = this.originalEvent;
|
||||
if (!e) { return; }
|
||||
// if stopPropagation exists run it on the original event
|
||||
if (e.stopPropagation) { e.stopPropagation(); }
|
||||
// otherwise set the cancelBubble property of the original event to true (IE)
|
||||
e.cancelBubble = true;
|
||||
},
|
||||
stopImmediatePropagation: function() {
|
||||
this.isImmediatePropagationStopped = returnTrue;
|
||||
this.stopPropagation();
|
||||
},
|
||||
isDefaultPrevented: returnFalse,
|
||||
isPropagationStopped: returnFalse,
|
||||
isImmediatePropagationStopped: returnFalse
|
||||
};
|
||||
_V_.Event.props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" ");
|
||||
|
||||
function returnTrue(){ return true; }
|
||||
function returnFalse(){ return false; }
|
||||
|
598
src/js/component.js
Normal file
598
src/js/component.js
Normal file
@ -0,0 +1,598 @@
|
||||
/**
|
||||
* @fileoverview Player Component - Base class for all UI objects
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('vjs.Component');
|
||||
|
||||
goog.require('vjs.events');
|
||||
goog.require('vjs.dom');
|
||||
|
||||
/**
|
||||
* Base UI Component class
|
||||
* @param {Object} player Main Player
|
||||
* @param {Object=} options
|
||||
* @constructor
|
||||
*/
|
||||
vjs.Component = function(player, options, ready){
|
||||
this.player = player;
|
||||
|
||||
// // Allow for overridding default component options
|
||||
options = this.options = vjs.merge(this.options || {}, options);
|
||||
|
||||
// Get ID from options, element, or create using player ID and unique ID
|
||||
this.id_ = options.id || ((options.el && options.el.id) ? options.el.id : player.id + '_component_' + vjs.guid++ );
|
||||
|
||||
this.name_ = options.name || null;
|
||||
|
||||
// Create element if one wasn't provided in potions
|
||||
this.el_ = (options.el) ? options.el : this.createEl();
|
||||
|
||||
this.children_ = [];
|
||||
this.childIndex_ = {};
|
||||
this.childNameIndex_ = {};
|
||||
|
||||
// Add any child components in options
|
||||
this.initChildren();
|
||||
|
||||
this.ready(ready);
|
||||
// Don't want to trigger ready here or it will before init is actually
|
||||
// finished for all children that run this constructor
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of the component and all child components.
|
||||
*/
|
||||
vjs.Component.prototype.dispose = function(){
|
||||
// Dispose all children.
|
||||
if (this.children_) {
|
||||
for (var i = this.children_.length - 1; i >= 0; i--) {
|
||||
this.children_[i].dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Delete child references
|
||||
this.children_ = null;
|
||||
this.childIndex_ = null;
|
||||
this.childNameIndex_ = null;
|
||||
|
||||
// Remove all event listeners.
|
||||
this.off();
|
||||
|
||||
// Remove element from DOM
|
||||
if (this.el_.parentNode) {
|
||||
this.el_.parentNode.removeChild(this.el_);
|
||||
}
|
||||
|
||||
vjs.removeData(this.el_);
|
||||
this.el_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Component options object.
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.options;
|
||||
|
||||
/**
|
||||
* The DOM element for the component.
|
||||
* @type {Element}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.el_;
|
||||
|
||||
/**
|
||||
* Create the component's DOM element.
|
||||
* @param {String=} tagName Element's node type. e.g. 'div'
|
||||
* @param {Object=} attributes An object of element attributes that should be set on the element.
|
||||
* @return {Element}
|
||||
*/
|
||||
vjs.Component.prototype.createEl = function(tagName, attributes){
|
||||
return vjs.createEl(tagName, attributes);
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the component's DOM element.
|
||||
* @return {Element}
|
||||
*/
|
||||
vjs.Component.prototype.el = function(){
|
||||
return this.el_;
|
||||
};
|
||||
|
||||
/**
|
||||
* The ID for the component.
|
||||
* @type {String}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.id_;
|
||||
|
||||
/**
|
||||
* Return the component's ID.
|
||||
* @return {String}
|
||||
*/
|
||||
vjs.Component.prototype.id = function(){
|
||||
return this.id_;
|
||||
};
|
||||
|
||||
/**
|
||||
* The name for the component. Often used to reference the component.
|
||||
* @type {String}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.name_;
|
||||
|
||||
/**
|
||||
* Return the component's ID.
|
||||
* @return {String}
|
||||
*/
|
||||
vjs.Component.prototype.name = function(){
|
||||
return this.name_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Array of child components
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.children_;
|
||||
|
||||
/**
|
||||
* Returns array of all child components.
|
||||
* @return {Array}
|
||||
*/
|
||||
vjs.Component.prototype.children = function(){
|
||||
return this.children_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object of child components by ID
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.childIndex_;
|
||||
|
||||
/**
|
||||
* Returns a child component with the provided ID.
|
||||
* @return {Array}
|
||||
*/
|
||||
vjs.Component.prototype.getChildById = function(id){
|
||||
return this.childIndex_[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Object of child components by Name
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.childNameIndex_;
|
||||
|
||||
/**
|
||||
* Returns a child component with the provided ID.
|
||||
* @return {Array}
|
||||
*/
|
||||
vjs.Component.prototype.getChild = function(name){
|
||||
return this.childNameIndex_[name];
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a child component inside this component.
|
||||
* @param {String|vjs.Component} child The class name or instance of a child to add.
|
||||
* @param {Object=} options Optional options, including options to be passed to
|
||||
* children of the child.
|
||||
* @return {vjs.Component} The child component, because it might be created in this process.
|
||||
* @suppress {accessControls|checkRegExp|checkTypes|checkVars|const|constantProperty|deprecated|duplicate|es5Strict|fileoverviewTags|globalThis|invalidCasts|missingProperties|nonStandardJsDocs|strictModuleDepCheck|undefinedNames|undefinedVars|unknownDefines|uselessCode|visibility}
|
||||
*/
|
||||
vjs.Component.prototype.addChild = function(child, options){
|
||||
var component, componentClass, componentName, componentId;
|
||||
|
||||
// If string, create new component with options
|
||||
if (typeof child === 'string') {
|
||||
|
||||
componentName = child;
|
||||
|
||||
// Make sure options is at least an empty object to protect against errors
|
||||
options = options || {};
|
||||
|
||||
// Assume name of set is a lowercased name of the UI Class (PlayButton, etc.)
|
||||
componentClass = options.componentClass || vjs.capitalize(componentName);
|
||||
|
||||
// Set name through options
|
||||
options.name = componentName;
|
||||
|
||||
// Create a new object & element for this controls set
|
||||
// If there's no .player, this is a player
|
||||
// Closure Compiler throws an 'incomplete alias' warning if we use the vjs variable directly.
|
||||
// Every class should be exported, so this should never be a problem here.
|
||||
component = new window['videojs'][componentClass](this.player || this, options);
|
||||
|
||||
// child is a component instance
|
||||
} else {
|
||||
component = child;
|
||||
}
|
||||
|
||||
componentName = component.name();
|
||||
componentId = component.id();
|
||||
|
||||
this.children_.push(component);
|
||||
|
||||
if (componentId) {
|
||||
this.childIndex_[componentId] = component;
|
||||
}
|
||||
|
||||
if (componentName) {
|
||||
this.childNameIndex_[componentName] = component;
|
||||
}
|
||||
|
||||
// Add the UI object's element to the container div (box)
|
||||
this.el_.appendChild(component.el());
|
||||
|
||||
// Return so it can stored on parent object if desired.
|
||||
return component;
|
||||
};
|
||||
|
||||
vjs.Component.prototype.removeChild = function(component){
|
||||
if (typeof component === 'string') {
|
||||
component = this.getChild(component);
|
||||
}
|
||||
|
||||
if (!component || !this.children_) return;
|
||||
|
||||
var childFound = false;
|
||||
for (var i = this.children_.length - 1; i >= 0; i--) {
|
||||
if (this.children_[i] === component) {
|
||||
childFound = true;
|
||||
this.children_.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!childFound) return;
|
||||
|
||||
this.childIndex_[component.id] = null;
|
||||
this.childNameIndex_[component.name] = null;
|
||||
|
||||
var compEl = component.el();
|
||||
if (compEl && compEl.parentNode === this.el_) {
|
||||
this.el_.removeChild(component.el());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize default child components from options
|
||||
*/
|
||||
vjs.Component.prototype.initChildren = function(){
|
||||
var options = this.options;
|
||||
|
||||
if (options && options.children) {
|
||||
var self = this;
|
||||
|
||||
// Loop through components and add them to the player
|
||||
vjs.eachProp(options.children, function(name, opts){
|
||||
|
||||
// Allow for disabling default components
|
||||
// e.g. vjs.options.components.posterImage = false
|
||||
if (opts === false) return;
|
||||
|
||||
// Allow waiting to add components until a specific event is called
|
||||
var tempAdd = function(){
|
||||
// Set property name on player. Could cause conflicts with other prop names, but it's worth making refs easy.
|
||||
self[name] = self.addChild(name, opts);
|
||||
};
|
||||
|
||||
if (opts.loadEvent) {
|
||||
// this.one(opts.loadEvent, tempAdd)
|
||||
} else {
|
||||
tempAdd();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Component.prototype.buildCSSClass = function(){
|
||||
// Child classes can include a function that does:
|
||||
// return 'CLASS NAME' + this._super();
|
||||
return '';
|
||||
};
|
||||
|
||||
/* Events
|
||||
============================================================================= */
|
||||
|
||||
/**
|
||||
* Add an event listener to this component's element. Context will be the component.
|
||||
* @param {String} type Event type e.g. 'click'
|
||||
* @param {Function} fn Event listener
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.on = function(type, fn){
|
||||
vjs.on(this.el_, type, vjs.bind(this, fn));
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove an event listener from the component's element
|
||||
* @param {String=} type Optional event type. Without type it will remove all listeners.
|
||||
* @param {Function=} fn Optional event listener. Without fn it will remove all listeners for a type.
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.off = function(type, fn){
|
||||
vjs.off(this.el_, type, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add an event listener to be triggered only once and then removed
|
||||
* @param {String} type Event type
|
||||
* @param {Function} fn Event listener
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.one = function(type, fn) {
|
||||
vjs.one(this.el_, type, vjs.bind(this, fn));
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event on an element
|
||||
* @param {String} type Event type to trigger
|
||||
* @param {Event|Object} event Event object to be passed to the listener
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.trigger = function(type, event){
|
||||
vjs.trigger(this.el_, type, event);
|
||||
return this;
|
||||
};
|
||||
|
||||
/* Ready
|
||||
================================================================================ */
|
||||
/**
|
||||
* Is the component loaded.
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.isReady_;
|
||||
|
||||
/**
|
||||
* Trigger ready as soon as initialization is finished.
|
||||
* Allows for delaying ready. Override on a sub class prototype.
|
||||
* If you set this.isReadyOnInitFinish_ it will affect all components.
|
||||
* Specially used when waiting for the Flash player to asynchrnously load.
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.isReadyOnInitFinish_ = true;
|
||||
|
||||
/**
|
||||
* List of ready listeners
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.readyQueue_;
|
||||
|
||||
/**
|
||||
* Bind a listener to the component's ready state.
|
||||
* Different from event listeners in that if the ready event has already happend
|
||||
* it will trigger the function immediately.
|
||||
* @param {Function} fn Ready listener
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.ready = function(fn){
|
||||
if (fn) {
|
||||
if (this.isReady_) {
|
||||
fn.call(this);
|
||||
} else {
|
||||
if (this.readyQueue_ === undefined) {
|
||||
this.readyQueue_ = [];
|
||||
}
|
||||
this.readyQueue_.push(fn);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger the ready listeners
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.triggerReady = function(){
|
||||
this.isReady_ = true;
|
||||
|
||||
var readyQueue = this.readyQueue_;
|
||||
|
||||
if (readyQueue && readyQueue.length > 0) {
|
||||
|
||||
for (var i = 0, j = readyQueue.length; i < j; i++) {
|
||||
readyQueue[i].call(this);
|
||||
}
|
||||
|
||||
// Reset Ready Queue
|
||||
this.readyQueue_ = [];
|
||||
|
||||
// Allow for using event listeners also, in case you want to do something everytime a source is ready.
|
||||
this.trigger('ready');
|
||||
}
|
||||
};
|
||||
|
||||
/* Display
|
||||
============================================================================= */
|
||||
|
||||
/**
|
||||
* Add a CSS class name to the component's element
|
||||
* @param {String} classToAdd Classname to add
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.addClass = function(classToAdd){
|
||||
vjs.addClass(this.el_, classToAdd);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a CSS class name from the component's element
|
||||
* @param {String} classToRemove Classname to remove
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.removeClass = function(classToRemove){
|
||||
vjs.removeClass(this.el_, classToRemove);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the component element if hidden
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.show = function(){
|
||||
this.el_.style.display = 'block';
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the component element if hidden
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.hide = function(){
|
||||
this.el_.style.display = 'none';
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fade a component in using CSS
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.fadeIn = function(){
|
||||
this.removeClass('vjs-fade-out');
|
||||
this.addClass('vjs-fade-in');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fade a component out using CSS
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.fadeOut = function(){
|
||||
this.removeClass('vjs-fade-in');
|
||||
this.addClass('vjs-fade-out');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Lock an item in its visible state. To be used with fadeIn/fadeOut.
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.lockShowing = function(){
|
||||
var style = this.el_.style;
|
||||
style.display = 'block';
|
||||
style.opacity = 1;
|
||||
style.visiblity = 'visible';
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Unlock an item to be hidden. To be used with fadeIn/fadeOut.
|
||||
* @return {vjs.Component}
|
||||
*/
|
||||
vjs.Component.prototype.unlockShowing = function(){
|
||||
var style = this.el_.style;
|
||||
style.display = '';
|
||||
style.opacity = '';
|
||||
style.visiblity = '';
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* If a value is provided it will change the width of the player to that value
|
||||
* otherwise the width is returned
|
||||
* http://dev.w3.org/html5/spec/dimension-attributes.html#attr-dim-height
|
||||
* Video tag width/height only work in pixels. No percents.
|
||||
* But allowing limited percents use. e.g. width() will return number+%, not computed width
|
||||
* @param {Number|String=} num Optional width number
|
||||
* @param {[type]} skipListeners Skip the 'resize' event trigger
|
||||
* @return {vjs.Component|Number|String} Returns 'this' if dimension was set.
|
||||
* Otherwise it returns the dimension.
|
||||
*/
|
||||
vjs.Component.prototype.width = function(num, skipListeners){
|
||||
return this.dimension('width', num, skipListeners);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set the height of the player
|
||||
* @param {Number|String=} num Optional new player height
|
||||
* @param {Boolean=} skipListeners Optional skip resize event trigger
|
||||
* @return {vjs.Component|Number|String} The player, or the dimension
|
||||
*/
|
||||
vjs.Component.prototype.height = function(num, skipListeners){
|
||||
return this.dimension('height', num, skipListeners);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set both width and height at the same time.
|
||||
* @param {Number|String} width
|
||||
* @param {Number|String} height
|
||||
* @return {vjs.Component} The player.
|
||||
*/
|
||||
vjs.Component.prototype.dimensions = function(width, height){
|
||||
// Skip resize listeners on width for optimization
|
||||
return this.width(width, true).height(height);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get or set width or height.
|
||||
* All for an integer, integer + 'px' or integer + '%';
|
||||
* Known issue: hidden elements. Hidden elements officially have a width of 0.
|
||||
* So we're defaulting to the style.width value and falling back to computedStyle
|
||||
* which has the hidden element issue.
|
||||
* Info, but probably not an efficient fix:
|
||||
* http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/
|
||||
* @param {String=} widthOrHeight 'width' or 'height'
|
||||
* @param {Number|String=} num New dimension
|
||||
* @param {Boolean=} skipListeners Skip resize event trigger
|
||||
* @return {vjs.Component|Number|String} Return the player if setting a dimension.
|
||||
* Otherwise it returns the dimension.
|
||||
*/
|
||||
vjs.Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
|
||||
if (num !== undefined) {
|
||||
|
||||
// Check if using css width/height (% or px) and adjust
|
||||
if ((''+num).indexOf('%') !== -1 || (''+num).indexOf('px') !== -1) {
|
||||
this.el_.style[widthOrHeight] = num;
|
||||
} else {
|
||||
this.el_.style[widthOrHeight] = num+'px';
|
||||
}
|
||||
|
||||
// skipListeners allows us to avoid triggering the resize event when setting both width and height
|
||||
if (!skipListeners) { this.trigger('resize'); }
|
||||
|
||||
// Return component
|
||||
return this;
|
||||
}
|
||||
|
||||
// Not setting a value, so getting it
|
||||
// Make sure element exists
|
||||
if (!this.el_) return 0;
|
||||
|
||||
// Get dimension value from style
|
||||
var val = this.el_.style[widthOrHeight];
|
||||
var pxIndex = val.indexOf('px');
|
||||
if (pxIndex !== -1) {
|
||||
// Return the pixel value with no 'px'
|
||||
return parseInt(val.slice(0,pxIndex), 10);
|
||||
|
||||
// No px so using % or no style was set, so falling back to offsetWidth/height
|
||||
// If component has display:none, offset will return 0
|
||||
// TODO: handle display:none and no dimension style using px
|
||||
} else {
|
||||
|
||||
return parseInt(this.el_['offset'+vjs.capitalize(widthOrHeight)], 10);
|
||||
|
||||
// ComputedStyle version.
|
||||
// Only difference is if the element is hidden it will return
|
||||
// the percent value (e.g. '100%'')
|
||||
// instead of zero like offsetWidth returns.
|
||||
// var val = vjs.getComputedStyleValue(this.el_, widthOrHeight);
|
||||
// var pxIndex = val.indexOf('px');
|
||||
|
||||
// if (pxIndex !== -1) {
|
||||
// return val.slice(0, pxIndex);
|
||||
// } else {
|
||||
// return val;
|
||||
// }
|
||||
}
|
||||
};
|
1002
src/js/controls.js
vendored
Normal file
1002
src/js/controls.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
104
src/js/core.js
Normal file
104
src/js/core.js
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* @fileoverview Main function src.
|
||||
*/
|
||||
|
||||
goog.provide('vjs');
|
||||
goog.provide('videojs');
|
||||
|
||||
// HTML5 Shiv. Must be in <head> to support older browsers.
|
||||
document.createElement('video');document.createElement('audio');
|
||||
|
||||
/**
|
||||
* Doubles as the main function for users to create a player instance and also
|
||||
* the main library object.
|
||||
*
|
||||
* @param {String|Element} id Video element or video element ID
|
||||
* @param {Object=} options Optional options object for config/settings
|
||||
* @param {Function=} ready Optional ready callback
|
||||
* @return {vjs.Player} A player instance
|
||||
*/
|
||||
vjs = function(id, options, ready){
|
||||
var tag; // Element of ID
|
||||
|
||||
// Allow for element or ID to be passed in
|
||||
// String ID
|
||||
if (typeof id === 'string') {
|
||||
|
||||
// Adjust for jQuery ID syntax
|
||||
if (id.indexOf('#') === 0) {
|
||||
id = id.slice(1);
|
||||
}
|
||||
|
||||
// If a player instance has already been created for this ID return it.
|
||||
if (vjs.players[id]) {
|
||||
return vjs.players[id];
|
||||
|
||||
// Otherwise get element for ID
|
||||
} else {
|
||||
tag = vjs.el(id);
|
||||
}
|
||||
|
||||
// ID is a media element
|
||||
} else {
|
||||
tag = id;
|
||||
}
|
||||
|
||||
// Check for a useable element
|
||||
if (!tag || !tag.nodeName) { // re: nodeName, could be a box div also
|
||||
throw new TypeError('The element or ID supplied is not valid. (videojs)'); // Returns
|
||||
}
|
||||
|
||||
// Element may have a player attr referring to an already created player instance.
|
||||
// If not, set up a new player and return the instance.
|
||||
return tag.player || new vjs.Player(tag, options, ready);
|
||||
};
|
||||
|
||||
// Extended name, also available externally, window.videojs
|
||||
var videojs = vjs;
|
||||
|
||||
// CDN Version. Used to target right flash swf.
|
||||
var CDN_VERSION = 'GENERATED_CDN_VSN';
|
||||
|
||||
/**
|
||||
* Global Player instance options
|
||||
* @type {Object}
|
||||
*/
|
||||
// var vjs = videojs;
|
||||
|
||||
vjs.options = {
|
||||
// Default order of fallback technology
|
||||
'techOrder': ['html5','flash'],
|
||||
// techOrder: ['flash','html5'],
|
||||
|
||||
'html5': {},
|
||||
'flash': { swf: 'http://vjs.zencdn.net/c/video-js.swf' },
|
||||
|
||||
// Default of web browser is 300x150. Should rely on source width/height.
|
||||
'width': 300,
|
||||
'height': 150,
|
||||
|
||||
// defaultVolume: 0.85,
|
||||
'defaultVolume': 0.00, // The freakin seaguls are driving me crazy!
|
||||
|
||||
// Included control sets
|
||||
'children': {
|
||||
'mediaLoader': {},
|
||||
'posterImage': {},
|
||||
'textTrackDisplay': {},
|
||||
'loadingSpinner': {},
|
||||
'bigPlayButton': {},
|
||||
'controlBar': {}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Global player list
|
||||
* @type {Object}
|
||||
*/
|
||||
vjs.players = {};
|
||||
|
||||
|
||||
// Set CDN Version of swf
|
||||
if (CDN_VERSION != 'GENERATED_CDN_VSN') {
|
||||
videojs.options['flash']['swf'] = 'http://vjs.zencdn.net/'+CDN_VERSION+'/video-js.swf';
|
||||
}
|
322
src/js/events.js
Normal file
322
src/js/events.js
Normal file
@ -0,0 +1,322 @@
|
||||
/**
|
||||
* @fileoverview Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/)
|
||||
* (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible)
|
||||
* This should work very similarly to jQuery's events, however it's based off the book version which isn't as
|
||||
* robust as jquery's, so there's probably some differences.
|
||||
*/
|
||||
|
||||
goog.provide('vjs.events');
|
||||
|
||||
goog.require('vjs');
|
||||
|
||||
/**
|
||||
* Add an event listener to element
|
||||
* It stores the handler function in a separate cache object
|
||||
* and adds a generic handler to the element's event,
|
||||
* along with a unique id (guid) to the element.
|
||||
* @param {Element|Object} elem Element or object to bind listeners to
|
||||
* @param {String} type Type of event to bind to.
|
||||
* @param {Function} fn Event listener.
|
||||
*/
|
||||
vjs.on = function(elem, type, fn){
|
||||
var data = vjs.getData(elem);
|
||||
|
||||
// We need a place to store all our handler data
|
||||
if (!data.handlers) data.handlers = {};
|
||||
|
||||
if (!data.handlers[type]) data.handlers[type] = [];
|
||||
|
||||
if (!fn.guid) fn.guid = vjs.guid++;
|
||||
|
||||
data.handlers[type].push(fn);
|
||||
|
||||
if (!data.dispatcher) {
|
||||
data.disabled = false;
|
||||
|
||||
data.dispatcher = function (event){
|
||||
|
||||
if (data.disabled) return;
|
||||
event = vjs.fixEvent(event);
|
||||
|
||||
var handlers = data.handlers[event.type];
|
||||
|
||||
/* Was making a copy of handlers to protect
|
||||
* against removal of listeners mid loop.
|
||||
* Removing for v4 to test if we still need it. */
|
||||
// Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
|
||||
if (handlers) {
|
||||
var handlersCopy = [];
|
||||
for (var i = 0, j = handlers.length; i < j; i++) {
|
||||
handlersCopy[i] = handlers[i];
|
||||
}
|
||||
|
||||
for (var m = 0, n = handlersCopy.length; m < n; m++) {
|
||||
handlersCopy[m].call(elem, event);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (data.handlers[type].length == 1) {
|
||||
if (document.addEventListener) {
|
||||
elem.addEventListener(type, data.dispatcher, false);
|
||||
} else if (document.attachEvent) {
|
||||
elem.attachEvent('on' + type, data.dispatcher);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes event listeners from an element
|
||||
* @param {Element|Object} elem Object to remove listeners from
|
||||
* @param {String=} type Type of listener to remove. Don't include to remove all events from element.
|
||||
* @param {Function} fn Specific listener to remove. Don't incldue to remove listeners for an event type.
|
||||
*/
|
||||
vjs.off = function(elem, type, fn) {
|
||||
// Don't want to add a cache object through getData if not needed
|
||||
if (!vjs.hasData(elem)) return;
|
||||
|
||||
var data = vjs.getData(elem);
|
||||
|
||||
// If no events exist, nothing to unbind
|
||||
if (!data.handlers) { return; }
|
||||
|
||||
// Utility function
|
||||
var removeType = function(t){
|
||||
data.handlers[t] = [];
|
||||
vjs.cleanUpEvents(elem,t);
|
||||
};
|
||||
|
||||
// Are we removing all bound events?
|
||||
if (!type) {
|
||||
for (var t in data.handlers) removeType(t);
|
||||
return;
|
||||
}
|
||||
|
||||
var handlers = data.handlers[type];
|
||||
|
||||
// If no handlers exist, nothing to unbind
|
||||
if (!handlers) return;
|
||||
|
||||
// If no listener was provided, remove all listeners for type
|
||||
if (!fn) {
|
||||
removeType(type);
|
||||
return;
|
||||
}
|
||||
|
||||
// We're only removing a single handler
|
||||
if (fn.guid) {
|
||||
for (var n = 0; n < handlers.length; n++) {
|
||||
if (handlers[n].guid === fn.guid) {
|
||||
handlers.splice(n--, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vjs.cleanUpEvents(elem, type);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up the listener cache and dispatchers
|
||||
* @param {Element|Object} elem Element to clean up
|
||||
* @param {String} type Type of event to clean up
|
||||
*/
|
||||
vjs.cleanUpEvents = function(elem, type) {
|
||||
var data = vjs.getData(elem);
|
||||
|
||||
// Remove the events of a particular type if there are none left
|
||||
if (data.handlers[type].length === 0) {
|
||||
delete data.handlers[type];
|
||||
// data.handlers[type] = null;
|
||||
// Setting to null was causing an error with data.handlers
|
||||
|
||||
// Remove the meta-handler from the element
|
||||
if (document.removeEventListener) {
|
||||
elem.removeEventListener(type, data.dispatcher, false);
|
||||
} else if (document.detachEvent) {
|
||||
elem.detachEvent('on' + type, data.dispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the events object if there are no types left
|
||||
if (vjs.isEmpty(data.handlers)) {
|
||||
delete data.handlers;
|
||||
delete data.dispatcher;
|
||||
delete data.disabled;
|
||||
|
||||
// data.handlers = null;
|
||||
// data.dispatcher = null;
|
||||
// data.disabled = null;
|
||||
}
|
||||
|
||||
// Finally remove the expando if there is no data left
|
||||
if (vjs.isEmpty(data)) {
|
||||
vjs.removeData(elem);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fix a native event to have standard property values
|
||||
* @param {Object} event Event object to fix
|
||||
* @return {Object}
|
||||
*/
|
||||
vjs.fixEvent = function(event) {
|
||||
|
||||
function returnTrue() { return true; }
|
||||
function returnFalse() { return false; }
|
||||
|
||||
// Test if fixing up is needed
|
||||
// Used to check if !event.stopPropagation instead of isPropagationStopped
|
||||
// But native events return true for stopPropagation, but don't have
|
||||
// other expected methods like isPropagationStopped. Seems to be a problem
|
||||
// with the Javascript Ninja code. So we're just overriding all events now.
|
||||
if (!event || !event.isPropagationStopped) {
|
||||
var old = event || window.event;
|
||||
|
||||
// Clone the old object so that we can modify the values event = {};
|
||||
for (var prop in old) {
|
||||
event[prop] = old[prop];
|
||||
}
|
||||
|
||||
// The event occurred on this element
|
||||
if (!event.target) {
|
||||
event.target = event.srcElement || document;
|
||||
}
|
||||
|
||||
// Handle which other element the event is related to
|
||||
event.relatedTarget = event.fromElement === event.target ?
|
||||
event.toElement :
|
||||
event.fromElement;
|
||||
|
||||
// Stop the default browser action
|
||||
event.preventDefault = function () {
|
||||
event.returnValue = false;
|
||||
event.isDefaultPrevented = returnTrue;
|
||||
};
|
||||
|
||||
event.isDefaultPrevented = returnFalse;
|
||||
|
||||
// Stop the event from bubbling
|
||||
event.stopPropagation = function () {
|
||||
event.cancelBubble = true;
|
||||
event.isPropagationStopped = returnTrue;
|
||||
};
|
||||
|
||||
event.isPropagationStopped = returnFalse;
|
||||
|
||||
// Stop the event from bubbling and executing other handlers
|
||||
event.stopImmediatePropagation = function () {
|
||||
event.isImmediatePropagationStopped = returnTrue;
|
||||
event.stopPropagation();
|
||||
};
|
||||
|
||||
event.isImmediatePropagationStopped = returnFalse;
|
||||
|
||||
// Handle mouse position
|
||||
if (event.clientX != null) {
|
||||
var doc = document.documentElement, body = document.body;
|
||||
|
||||
event.pageX = event.clientX +
|
||||
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
|
||||
(doc && doc.clientLeft || body && body.clientLeft || 0);
|
||||
event.pageY = event.clientY +
|
||||
(doc && doc.scrollTop || body && body.scrollTop || 0) -
|
||||
(doc && doc.clientTop || body && body.clientTop || 0);
|
||||
}
|
||||
|
||||
// Handle key presses
|
||||
event.which = event.charCode || event.keyCode;
|
||||
|
||||
// Fix button for mouse clicks:
|
||||
// 0 == left; 1 == middle; 2 == right
|
||||
if (event.button != null) {
|
||||
event.button = (event.button & 1 ? 0 :
|
||||
(event.button & 4 ? 1 :
|
||||
(event.button & 2 ? 2 : 0)));
|
||||
}
|
||||
}
|
||||
|
||||
// Returns fixed-up instance
|
||||
return event;
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event for an element
|
||||
* @param {Element|Object} elem Element to trigger an event on
|
||||
* @param {String} event Type of event to trigger
|
||||
*/
|
||||
vjs.trigger = function(elem, event) {
|
||||
// Fetches element data and a reference to the parent (for bubbling).
|
||||
// Don't want to add a data object to cache for every parent,
|
||||
// so checking hasData first.
|
||||
var elemData = (vjs.hasData(elem)) ? vjs.getData(elem) : {};
|
||||
var parent = elem.parentNode || elem.ownerDocument;
|
||||
// type = event.type || event,
|
||||
// handler;
|
||||
|
||||
// If an event name was passed as a string, creates an event out of it
|
||||
if (typeof event === 'string') {
|
||||
event = { type:event, target:elem };
|
||||
}
|
||||
// Normalizes the event properties.
|
||||
event = vjs.fixEvent(event);
|
||||
|
||||
// If the passed element has a dispatcher, executes the established handlers.
|
||||
if (elemData.dispatcher) {
|
||||
elemData.dispatcher.call(elem, event);
|
||||
}
|
||||
|
||||
// Unless explicitly stopped, recursively calls this function to bubble the event up the DOM.
|
||||
if (parent && !event.isPropagationStopped()) {
|
||||
vjs.trigger(parent, event);
|
||||
|
||||
// If at the top of the DOM, triggers the default action unless disabled.
|
||||
} else if (!parent && !event.isDefaultPrevented()) {
|
||||
var targetData = vjs.getData(event.target);
|
||||
|
||||
// Checks if the target has a default action for this event.
|
||||
if (event.target[event.type]) {
|
||||
// Temporarily disables event dispatching on the target as we have already executed the handler.
|
||||
targetData.disabled = true;
|
||||
// Executes the default action.
|
||||
if (typeof event.target[event.type] === 'function') {
|
||||
event.target[event.type]();
|
||||
}
|
||||
// Re-enables event dispatching.
|
||||
targetData.disabled = false;
|
||||
}
|
||||
}
|
||||
/* Original version of js ninja events wasn't complete.
|
||||
* We've since updated to the latest version, but keeping this around
|
||||
* for now just in case.
|
||||
*/
|
||||
// // Added in attion to book. Book code was broke.
|
||||
// event = typeof event === 'object' ?
|
||||
// event[vjs.expando] ?
|
||||
// event :
|
||||
// new vjs.Event(type, event) :
|
||||
// new vjs.Event(type);
|
||||
|
||||
// event.type = type;
|
||||
// if (handler) {
|
||||
// handler.call(elem, event);
|
||||
// }
|
||||
|
||||
// // Clean up the event in case it is being reused
|
||||
// event.result = undefined;
|
||||
// event.target = elem;
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger a listener only once for an event
|
||||
* @param {Element|Object} elem Element or object to
|
||||
* @param {[type]} type [description]
|
||||
* @param {Function} fn [description]
|
||||
* @return {[type]}
|
||||
*/
|
||||
vjs.one = function(elem, type, fn) {
|
||||
vjs.on(elem, type, function(){
|
||||
vjs.off(elem, type, arguments.callee);
|
||||
fn.apply(this, arguments);
|
||||
});
|
||||
};
|
131
src/js/exports.js
Normal file
131
src/js/exports.js
Normal file
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* @fileoverview Exports for Video.js.
|
||||
* Exports are publically available variables.
|
||||
* All other variables (including function names) will probably
|
||||
* be renamed by closure compiler.
|
||||
*/
|
||||
|
||||
goog.require('vjs');
|
||||
goog.require('vjs.Component');
|
||||
goog.require('vjs.Player');
|
||||
goog.require('vjs.Control');
|
||||
goog.require('vjs.Html5');
|
||||
goog.require('vjs.Flash');
|
||||
goog.require('vjs.TextTrack');
|
||||
goog.require('vjs.autoSetup');
|
||||
|
||||
/**
|
||||
* vjs (internal only) = videojs = _V_ (external only)
|
||||
*
|
||||
* vjs is the same as the goog var in Closure Library. It holds all variables
|
||||
* used in Video.js development. Closure compiler will rename all variables,
|
||||
* including class prototype functions, except those specifcally
|
||||
* exported (eports.js). Don't assume any function you can use in Video.js
|
||||
* development will be available on window.videojs for use with other js.
|
||||
*
|
||||
* For example, vjs.trim is an internal function and will be renamed by compiler
|
||||
* to something like 'a.b', or actually more likely 'a' removing it from
|
||||
* a parent object.
|
||||
*
|
||||
* videojs is a var that helps bridge bewteen internal and external development.
|
||||
* Avoid using it over vjs when developing the Video.js core.
|
||||
*
|
||||
* _V_ is only external. It's just cute and short(er). Like jQuery === $.
|
||||
* Also because it's nice having a different var for internal (vjs) vs.
|
||||
* external (_V_) because it makes it clearer what context we're in.
|
||||
*/
|
||||
goog.exportSymbol('videojs', vjs);
|
||||
goog.exportSymbol('_V_', vjs);
|
||||
|
||||
goog.exportSymbol('videojs.options', vjs.options);
|
||||
|
||||
// Allow external components to use global cache
|
||||
goog.exportSymbol('videojs.cache', vjs.cache);
|
||||
|
||||
goog.exportSymbol('videojs.Component', vjs.Component);
|
||||
goog.exportProperty(vjs.Component.prototype, 'dispose', vjs.Component.prototype.dispose);
|
||||
goog.exportProperty(vjs.Component.prototype, 'createEl', vjs.Component.prototype.createEl);
|
||||
goog.exportProperty(vjs.Component.prototype, 'getEl', vjs.Component.prototype.getEl);
|
||||
goog.exportProperty(vjs.Component.prototype, 'addChild', vjs.Component.prototype.addChild);
|
||||
goog.exportProperty(vjs.Component.prototype, 'getChildren', vjs.Component.prototype.getChildren);
|
||||
goog.exportProperty(vjs.Component.prototype, 'on', vjs.Component.prototype.on);
|
||||
goog.exportProperty(vjs.Component.prototype, 'off', vjs.Component.prototype.off);
|
||||
goog.exportProperty(vjs.Component.prototype, 'one', vjs.Component.prototype.one);
|
||||
goog.exportProperty(vjs.Component.prototype, 'trigger', vjs.Component.prototype.trigger);
|
||||
goog.exportProperty(vjs.Component.prototype, 'show', vjs.Component.prototype.show);
|
||||
goog.exportProperty(vjs.Component.prototype, 'hide', vjs.Component.prototype.hide);
|
||||
goog.exportProperty(vjs.Component.prototype, 'width', vjs.Component.prototype.width);
|
||||
goog.exportProperty(vjs.Component.prototype, 'height', vjs.Component.prototype.height);
|
||||
goog.exportProperty(vjs.Component.prototype, 'dimensions', vjs.Component.prototype.dimensions);
|
||||
|
||||
goog.exportSymbol('videojs.Player', vjs.Player);
|
||||
|
||||
goog.exportSymbol('videojs.MediaLoader', vjs.MediaLoader);
|
||||
goog.exportSymbol('videojs.PosterImage', vjs.PosterImage);
|
||||
goog.exportSymbol('videojs.LoadingSpinner', vjs.LoadingSpinner);
|
||||
goog.exportSymbol('videojs.BigPlayButton', vjs.BigPlayButton);
|
||||
goog.exportSymbol('videojs.ControlBar', vjs.ControlBar);
|
||||
goog.exportSymbol('videojs.TextTrackDisplay', vjs.TextTrackDisplay);
|
||||
|
||||
goog.exportSymbol('videojs.Control', vjs.Control);
|
||||
goog.exportSymbol('videojs.ControlBar', vjs.ControlBar);
|
||||
goog.exportSymbol('videojs.Button', vjs.Button);
|
||||
goog.exportSymbol('videojs.PlayButton', vjs.PlayButton);
|
||||
goog.exportSymbol('videojs.PauseButton', vjs.PauseButton);
|
||||
goog.exportSymbol('videojs.PlayToggle', vjs.PlayToggle);
|
||||
goog.exportSymbol('videojs.FullscreenToggle', vjs.FullscreenToggle);
|
||||
goog.exportSymbol('videojs.BigPlayButton', vjs.BigPlayButton);
|
||||
goog.exportSymbol('videojs.LoadingSpinner', vjs.LoadingSpinner);
|
||||
goog.exportSymbol('videojs.CurrentTimeDisplay', vjs.CurrentTimeDisplay);
|
||||
goog.exportSymbol('videojs.DurationDisplay', vjs.DurationDisplay);
|
||||
goog.exportSymbol('videojs.TimeDivider', vjs.TimeDivider);
|
||||
goog.exportSymbol('videojs.RemainingTimeDisplay', vjs.RemainingTimeDisplay);
|
||||
goog.exportSymbol('videojs.Slider', vjs.Slider);
|
||||
goog.exportSymbol('videojs.ProgressControl', vjs.ProgressControl);
|
||||
goog.exportSymbol('videojs.SeekBar', vjs.SeekBar);
|
||||
goog.exportSymbol('videojs.LoadProgressBar', vjs.LoadProgressBar);
|
||||
goog.exportSymbol('videojs.PlayProgressBar', vjs.PlayProgressBar);
|
||||
goog.exportSymbol('videojs.SeekHandle', vjs.SeekHandle);
|
||||
goog.exportSymbol('videojs.VolumeControl', vjs.VolumeControl);
|
||||
goog.exportSymbol('videojs.VolumeBar', vjs.VolumeBar);
|
||||
goog.exportSymbol('videojs.VolumeLevel', vjs.VolumeLevel);
|
||||
goog.exportSymbol('videojs.VolumeHandle', vjs.VolumeHandle);
|
||||
goog.exportSymbol('videojs.MuteToggle', vjs.MuteToggle);
|
||||
goog.exportSymbol('videojs.PosterImage', vjs.PosterImage);
|
||||
goog.exportSymbol('videojs.Menu', vjs.Menu);
|
||||
goog.exportSymbol('videojs.MenuItem', vjs.MenuItem);
|
||||
|
||||
goog.exportSymbol('videojs.SubtitlesButton', vjs.SubtitlesButton);
|
||||
goog.exportSymbol('videojs.CaptionsButton', vjs.CaptionsButton);
|
||||
goog.exportSymbol('videojs.ChaptersButton', vjs.ChaptersButton);
|
||||
|
||||
goog.exportSymbol('videojs.MediaTechController', vjs.MediaTechController);
|
||||
|
||||
goog.exportSymbol('videojs.Html5', vjs.Html5);
|
||||
goog.exportProperty(vjs.Html5, 'Events', vjs.Html5.Events);
|
||||
goog.exportProperty(vjs.Html5, 'isSupported', vjs.Html5.isSupported);
|
||||
goog.exportProperty(vjs.Html5, 'canPlaySource', vjs.Html5.canPlaySource);
|
||||
|
||||
// Export non-standard HTML5 video API methods.
|
||||
// Standard method names already protected by default externs.
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setCurrentTime', vjs.Html5.prototype.setCurrentTime);
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setVolume', vjs.Html5.prototype.setVolume);
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setMuted', vjs.Html5.prototype.setMuted);
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setPreload', vjs.Html5.prototype.setPreload);
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setAutoplay', vjs.Html5.prototype.setAutoplay);
|
||||
goog.exportProperty(vjs.Html5.prototype, 'setLoop', vjs.Html5.prototype.setLoop);
|
||||
|
||||
goog.exportSymbol('videojs.Flash', vjs.Flash);
|
||||
goog.exportProperty(vjs.Flash, 'Events', vjs.Flash.Events);
|
||||
goog.exportProperty(vjs.Flash, 'isSupported', vjs.Flash.isSupported);
|
||||
goog.exportProperty(vjs.Flash, 'canPlaySource', vjs.Flash.canPlaySource);
|
||||
goog.exportProperty(vjs.Flash, 'onReady', vjs.Flash['onReady']);
|
||||
|
||||
goog.exportSymbol('videojs.TextTrack', vjs.TextTrack);
|
||||
goog.exportProperty(vjs.TextTrack.prototype, 'label', vjs.TextTrack.prototype.label);
|
||||
|
||||
goog.exportSymbol('videojs.CaptionsTrack', vjs.CaptionsTrack);
|
||||
goog.exportSymbol('videojs.SubtitlesTrack', vjs.SubtitlesTrack);
|
||||
goog.exportSymbol('videojs.ChaptersTrack', vjs.ChaptersTrack);
|
||||
|
||||
goog.exportSymbol('videojs.autoSetup', vjs.autoSetup);
|
1574
src/js/goog.base.js
Normal file
1574
src/js/goog.base.js
Normal file
File diff suppressed because it is too large
Load Diff
61
src/js/json.js
Normal file
61
src/js/json.js
Normal file
@ -0,0 +1,61 @@
|
||||
goog.provide('vjs.JSON');
|
||||
|
||||
/**
|
||||
* Javascript JSON implementation
|
||||
* (Parse Method Only)
|
||||
* https://github.com/douglascrockford/JSON-js/blob/master/json2.js
|
||||
* Only using for parse method when parsing data-setup attribute JSON.
|
||||
* @type {Object}
|
||||
*/
|
||||
vjs.JSON;
|
||||
|
||||
if (JSON && JSON.parse === 'function') {
|
||||
vjs.JSON = JSON;
|
||||
|
||||
} else {
|
||||
vjs.JSON = {};
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
|
||||
vjs.JSON.parse = function (text, reviver) {
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
542
src/js/lib.js
Normal file
542
src/js/lib.js
Normal file
@ -0,0 +1,542 @@
|
||||
goog.provide('vjs.dom');
|
||||
|
||||
goog.require('vjs');
|
||||
|
||||
/**
|
||||
* Creates an element and applies properties.
|
||||
* @param {String=} tagName Name of tag to be created.
|
||||
* @param {Object=} properties Element properties to be applied.
|
||||
* @return {Element}
|
||||
*/
|
||||
vjs.createEl = function(tagName, properties){
|
||||
var el = document.createElement(tagName || 'div');
|
||||
|
||||
for (var propName in properties){
|
||||
if (properties.hasOwnProperty(propName)) {
|
||||
el[propName] = properties[propName];
|
||||
// Not remembering why we were checking for dash
|
||||
// but using setAttribute means you have to use getAttribute
|
||||
// if (propName.indexOf('-') !== -1) {
|
||||
// el.setAttribute(propName, properties[propName]);
|
||||
// } else {
|
||||
// el[propName] = properties[propName];
|
||||
// }
|
||||
}
|
||||
}
|
||||
return el;
|
||||
};
|
||||
|
||||
/**
|
||||
* Uppercase the first letter of a string
|
||||
* @param {String} string String to be uppercased
|
||||
* @return {String}
|
||||
*/
|
||||
vjs.capitalize = function(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loop through each property in an object and call a function
|
||||
* whose arguments are (key,value)
|
||||
* @param {Object} obj Object of properties
|
||||
* @param {Function} fn Function to be called on each property.
|
||||
* @this {*}
|
||||
*/
|
||||
vjs.eachProp = function(obj, fn){
|
||||
if (!obj) { return; }
|
||||
for (var name in obj) {
|
||||
if (obj.hasOwnProperty(name)) {
|
||||
fn.call(this, name, obj[name]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Merge two objects together and return the original.
|
||||
* @param {[type]} obj1 [description]
|
||||
* @param {[type]} obj2 [description]
|
||||
* @param {[type]} safe [description]
|
||||
* @return {[type]}
|
||||
*/
|
||||
vjs.merge = function(obj1, obj2, safe){
|
||||
// Make sure second object exists
|
||||
if (!obj2) { return obj1; }
|
||||
|
||||
for (var attrname in obj2){
|
||||
if (obj2.hasOwnProperty(attrname) && (!safe || !obj1.hasOwnProperty(attrname))) { obj1[attrname]=obj2[attrname]; }
|
||||
}
|
||||
return obj1;
|
||||
};
|
||||
// vjs.extend = function(obj){ this.merge(this, obj, true); };
|
||||
|
||||
/**
|
||||
* Bind (a.k.a proxy or Context). A simple method for changing the context of a function
|
||||
It also stores a unique id on the function so it can be easily removed from events
|
||||
* @param {*} context The object to bind as scope
|
||||
* @param {Function} fn The function to be bound to a scope
|
||||
* @param {Number=} uid An optional unique ID for the function to be set
|
||||
* @return {Function}
|
||||
*/
|
||||
vjs.bind = function(context, fn, uid) {
|
||||
// Make sure the function has a unique ID
|
||||
if (!fn.guid) { fn.guid = vjs.guid++; }
|
||||
|
||||
// Create the new function that changes the context
|
||||
var ret = function() {
|
||||
return fn.apply(context, arguments);
|
||||
};
|
||||
|
||||
// Allow for the ability to individualize this function
|
||||
// Needed in the case where multiple objects might share the same prototype
|
||||
// IF both items add an event listener with the same function, then you try to remove just one
|
||||
// it will remove both because they both have the same guid.
|
||||
// when using this, you need to use the bind method when you remove the listener as well.
|
||||
// currently used in text tracks
|
||||
ret.guid = (uid) ? uid + '_' + fn.guid : fn.guid;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* Element Data Store. Allows for binding data to an element without putting it directly on the element.
|
||||
* Ex. Event listneres are stored here.
|
||||
* (also from jsninja.com, slightly modified and updated for closure compiler)
|
||||
* @type {Object}
|
||||
*/
|
||||
vjs.cache = {};
|
||||
|
||||
/**
|
||||
* Unique ID for an element or function
|
||||
* @type {Number}
|
||||
*/
|
||||
vjs.guid = 1;
|
||||
|
||||
/**
|
||||
* Unique attribute name to store an element's guid in
|
||||
* @type {String}
|
||||
* @constant
|
||||
*/
|
||||
vjs.expando = 'vdata' + (new Date()).getTime();
|
||||
|
||||
/**
|
||||
* Returns the cache object where data for an element is stored
|
||||
* @param {Element} el Element to store data for.
|
||||
* @return {Object}
|
||||
*/
|
||||
vjs.getData = function(el){
|
||||
var id = el[vjs.expando];
|
||||
if (!id) {
|
||||
id = el[vjs.expando] = vjs.guid++;
|
||||
vjs.cache[id] = {};
|
||||
}
|
||||
return vjs.cache[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the cache object where data for an element is stored
|
||||
* @param {Element} el Element to store data for.
|
||||
* @return {Object}
|
||||
*/
|
||||
vjs.hasData = function(el){
|
||||
var id = el[vjs.expando];
|
||||
return !(!id || vjs.isEmpty(vjs.cache[id]));
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete data for the element from the cache and the guid attr from getElementById
|
||||
* @param {Element} el Remove data for an element
|
||||
*/
|
||||
vjs.removeData = function(el){
|
||||
var id = el[vjs.expando];
|
||||
if (!id) { return; }
|
||||
// Remove all stored data
|
||||
// Changed to = null
|
||||
// http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/
|
||||
// vjs.cache[id] = null;
|
||||
delete vjs.cache[id];
|
||||
|
||||
// Remove the expando property from the DOM node
|
||||
try {
|
||||
delete el[vjs.expando];
|
||||
} catch(e) {
|
||||
if (el.removeAttribute) {
|
||||
el.removeAttribute(vjs.expando);
|
||||
} else {
|
||||
// IE doesn't appear to support removeAttribute on the document element
|
||||
el[vjs.expando] = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
vjs.isEmpty = function(obj) {
|
||||
for (var prop in obj) {
|
||||
// Inlude null properties as empty.
|
||||
if (obj[prop] !== null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a CSS class name to an element
|
||||
* @param {Element} element Element to add class name to
|
||||
* @param {String} classToAdd Classname to add
|
||||
*/
|
||||
vjs.addClass = function(element, classToAdd){
|
||||
if ((' '+element.className+' ').indexOf(' '+classToAdd+' ') == -1) {
|
||||
element.className = element.className === '' ? classToAdd : element.className + ' ' + classToAdd;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a CSS class name from an element
|
||||
* @param {Element} element Element to remove from class name
|
||||
* @param {String} classToAdd Classname to remove
|
||||
*/
|
||||
vjs.removeClass = function(element, classToRemove){
|
||||
if (element.className.indexOf(classToRemove) == -1) { return; }
|
||||
var classNames = element.className.split(' ');
|
||||
classNames.splice(classNames.indexOf(classToRemove),1);
|
||||
element.className = classNames.join(' ');
|
||||
};
|
||||
|
||||
/**
|
||||
* Element for testing browser HTML5 video capabilities
|
||||
* @type {Element}
|
||||
* @constant
|
||||
*/
|
||||
vjs.TEST_VID = vjs.createEl('video');
|
||||
|
||||
/**
|
||||
* Useragent for browser testing.
|
||||
* @type {String}
|
||||
* @constant
|
||||
*/
|
||||
vjs.USER_AGENT = navigator.userAgent;
|
||||
|
||||
/**
|
||||
* Device is an iPhone
|
||||
* @type {Boolean}
|
||||
* @constant
|
||||
*/
|
||||
vjs.IS_IPHONE = !!vjs.USER_AGENT.match(/iPad/i);
|
||||
vjs.IS_IPAD = !!vjs.USER_AGENT.match(/iPhone/i);
|
||||
vjs.IS_IPOD = !!vjs.USER_AGENT.match(/iPod/i);
|
||||
vjs.IS_IOS = vjs.IS_IPHONE || vjs.IS_IPAD || vjs.IS_IPOD;
|
||||
|
||||
vjs.IOS_VERSION = (function(){
|
||||
var match = vjs.USER_AGENT.match(/OS (\d+)_/i);
|
||||
if (match && match[1]) { return match[1]; }
|
||||
})();
|
||||
|
||||
vjs.IS_ANDROID = !!vjs.USER_AGENT.match(/Android.*AppleWebKit/i);
|
||||
vjs.ANDROID_VERSION = (function() {
|
||||
var match = vjs.USER_AGENT.match(/Android (\d+)\./i);
|
||||
if (match && match[1]) {
|
||||
return match[1];
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
|
||||
vjs.IS_FIREFOX = function(){ return !!vjs.USER_AGENT.match('Firefox'); };
|
||||
|
||||
|
||||
/**
|
||||
* Get an element's attribute values, as defined on the HTML tag
|
||||
* Attributs are not the same as properties. They're defined on the tag
|
||||
* or with setAttribute (which shouldn't be used with HTML)
|
||||
* This will return true or false for boolean attributes.
|
||||
* @param {Element} tag Element from which to get tag attributes
|
||||
* @return {Object}
|
||||
*/
|
||||
vjs.getAttributeValues = function(tag){
|
||||
var obj = {};
|
||||
|
||||
// Known boolean attributes
|
||||
// We can check for matching boolean properties, but older browsers
|
||||
// won't know about HTML5 boolean attributes that we still read from.
|
||||
// Bookending with commas to allow for an easy string search.
|
||||
var knownBooleans = ','+'autoplay,controls,loop,muted,default'+',';
|
||||
|
||||
if (tag && tag.attributes && tag.attributes.length > 0) {
|
||||
var attrs = tag.attributes;
|
||||
var attrName, attrVal;
|
||||
|
||||
for (var i = attrs.length - 1; i >= 0; i--) {
|
||||
attrName = attrs[i].name;
|
||||
attrVal = attrs[i].value;
|
||||
|
||||
// Check for known booleans
|
||||
// The matching element property will return a value for typeof
|
||||
if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(','+attrName+',') !== -1) {
|
||||
// The value of an included boolean attribute is typically an empty string ('')
|
||||
// which would equal false if we just check for a false value.
|
||||
// We also don't want support bad code like autoplay='false'
|
||||
attrVal = (attrVal !== null) ? true : false;
|
||||
}
|
||||
|
||||
obj[attrName] = attrVal;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the computed style value for an element
|
||||
* From http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
|
||||
* @param {Element} el Element to get style value for
|
||||
* @param {String} strCssRule Style name
|
||||
* @return {String} Style value
|
||||
*/
|
||||
vjs.getComputedStyleValue = function(el, strCssRule){
|
||||
var strValue = '';
|
||||
if(document.defaultView && document.defaultView.getComputedStyle){
|
||||
strValue = document.defaultView.getComputedStyle(el, '').getPropertyValue(strCssRule);
|
||||
|
||||
} else if(el.currentStyle){
|
||||
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
|
||||
return p1.toUpperCase();
|
||||
});
|
||||
strValue = el.currentStyle[strCssRule];
|
||||
}
|
||||
return strValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* Insert an element as the first child node of another
|
||||
* @param {Element} child Element to insert
|
||||
* @param {[type]} parent Element to insert child into
|
||||
*/
|
||||
vjs.insertFirst = function(child, parent){
|
||||
if (parent.firstChild) {
|
||||
parent.insertBefore(child, parent.firstChild);
|
||||
} else {
|
||||
parent.appendChild(child);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Object to hold browser support information
|
||||
* @type {Object}
|
||||
*/
|
||||
vjs.support = {};
|
||||
|
||||
/**
|
||||
* Shorthand for document.getElementById()
|
||||
* Also allows for CSS (jQuery) ID syntax. But nothing other than IDs.
|
||||
* @param {String} id Element ID
|
||||
* @return {Element} Element with supplied ID
|
||||
*/
|
||||
vjs.el = function(id){
|
||||
if (id.indexOf('#') === 0) {
|
||||
id = id.slice(1);
|
||||
}
|
||||
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Format seconds as a time string, H:MM:SS or M:SS
|
||||
* Supplying a guide (in seconds) will force a number of leading zeros
|
||||
* to cover the length of the guide
|
||||
* @param {Number} seconds Number of seconds to be turned into a string
|
||||
* @param {Number} guide Number (in seconds) to model the string after
|
||||
* @return {String} Time formatted as H:MM:SS or M:SS
|
||||
*/
|
||||
vjs.formatTime = function(seconds, guide) {
|
||||
guide = guide || seconds; // Default to using seconds as guide
|
||||
var s = Math.floor(seconds % 60),
|
||||
m = Math.floor(seconds / 60 % 60),
|
||||
h = Math.floor(seconds / 3600),
|
||||
gm = Math.floor(guide / 60 % 60),
|
||||
gh = Math.floor(guide / 3600);
|
||||
|
||||
// Check if we need to show hours
|
||||
h = (h > 0 || gh > 0) ? h + ':' : '';
|
||||
|
||||
// If hours are showing, we may need to add a leading zero.
|
||||
// Always show at least one digit of minutes.
|
||||
m = (((h || gm >= 10) && m < 10) ? '0' + m : m) + ':';
|
||||
|
||||
// Check if leading zero is need for seconds
|
||||
s = (s < 10) ? '0' + s : s;
|
||||
|
||||
return h + m + s;
|
||||
};
|
||||
|
||||
// Attempt to block the ability to select text while dragging controls
|
||||
vjs.blockTextSelection = function(){
|
||||
document.body.focus();
|
||||
document.onselectstart = function () { return false; };
|
||||
};
|
||||
// Turn off text selection blocking
|
||||
vjs.unblockTextSelection = function(){ document.onselectstart = function () { return true; }; };
|
||||
|
||||
/**
|
||||
* Trim whitespace from the ends of a string.
|
||||
* @param {String} string String to trim
|
||||
* @return {String} Trimmed string
|
||||
*/
|
||||
vjs.trim = function(string){
|
||||
return string.toString().replace(/^\s+/, '').replace(/\s+$/, '');
|
||||
};
|
||||
|
||||
/**
|
||||
* Should round off a number to a decimal place
|
||||
* @param {Number} num Number to round
|
||||
* @param {Number} dec Number of decimal places to round to
|
||||
* @return {Number} Rounded number
|
||||
*/
|
||||
vjs.round = function(num, dec) {
|
||||
if (!dec) { dec = 0; }
|
||||
return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
|
||||
};
|
||||
|
||||
/**
|
||||
* Should create a fake TimeRange object
|
||||
* Mimics an HTML5 time range instance, which has functions that
|
||||
* return the start and end times for a range
|
||||
* TimeRanges are returned by the buffered() method
|
||||
* @param {Number} start Start time in seconds
|
||||
* @param {Number} end End time in seconds
|
||||
* @return {Object} Fake TimeRange object
|
||||
*/
|
||||
vjs.createTimeRange = function(start, end){
|
||||
return {
|
||||
length: 1,
|
||||
start: function() { return start; },
|
||||
end: function() { return end; }
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple http request for retrieving external files (e.g. text tracks)
|
||||
* @param {String} url URL of resource
|
||||
* @param {Function=} onSuccess Success callback
|
||||
* @param {Function=} onError Error callback
|
||||
*/
|
||||
vjs.get = function(url, onSuccess, onError){
|
||||
var local = (url.indexOf('file:') === 0 || (window.location.href.indexOf('file:') === 0 && url.indexOf('http') === -1));
|
||||
|
||||
if (typeof XMLHttpRequest === 'undefined') {
|
||||
window.XMLHttpRequest = function () {
|
||||
try { return new window.ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch (e) {}
|
||||
try { return new window.ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch (f) {}
|
||||
try { return new window.ActiveXObject('Msxml2.XMLHTTP'); } catch (g) {}
|
||||
throw new Error('This browser does not support XMLHttpRequest.');
|
||||
};
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
try {
|
||||
request.open('GET', url);
|
||||
} catch(e) {
|
||||
onError(e);
|
||||
}
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === 4) {
|
||||
if (request.status === 200 || local && request.status === 0) {
|
||||
onSuccess(request.responseText);
|
||||
} else {
|
||||
if (onError) {
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
request.send();
|
||||
} catch(e) {
|
||||
if (onError) {
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* Local Storage
|
||||
================================================================================ */
|
||||
vjs.setLocalStorage = function(key, value){
|
||||
// IE was throwing errors referencing the var anywhere without this
|
||||
var localStorage = window.localStorage || false;
|
||||
if (!localStorage) { return; }
|
||||
try {
|
||||
localStorage[key] = value;
|
||||
} catch(e) {
|
||||
if (e.code == 22 || e.code == 1014) { // Webkit == 22 / Firefox == 1014
|
||||
vjs.log('LocalStorage Full (VideoJS)', e);
|
||||
} else {
|
||||
vjs.log('LocalStorage Error (VideoJS)', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get abosolute version of relative URL. Used to tell flash correct URL.
|
||||
* http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
|
||||
* @param {String} url URL to make absolute
|
||||
* @return {String} Absolute URL
|
||||
*/
|
||||
vjs.getAbsoluteURL = function(url){
|
||||
|
||||
// Check if absolute URL
|
||||
if (!url.match(/^https?:\/\//)) {
|
||||
// Convert to absolute URL. Flash hosted off-site needs an absolute URL.
|
||||
url = vjs.createEl('div', {
|
||||
innerHTML: '<a href="'+url+'">x</a>'
|
||||
}).firstChild.href;
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
// usage: log('inside coolFunc',this,arguments);
|
||||
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
|
||||
vjs.log = function(){
|
||||
vjs.log.history = vjs.log.history || []; // store logs to an array for reference
|
||||
vjs.log.history.push(arguments);
|
||||
if(window.console){
|
||||
window.console.log(Array.prototype.slice.call(arguments));
|
||||
}
|
||||
};
|
||||
|
||||
// Offset Left
|
||||
// getBoundingClientRect technique from John Resig http://ejohn.org/blog/getboundingclientrect-is-awesome/
|
||||
if ('getBoundingClientRect' in document.documentElement) {
|
||||
vjs.findPosX = function(el) {
|
||||
var box;
|
||||
|
||||
try {
|
||||
box = el.getBoundingClientRect();
|
||||
} catch(e) {}
|
||||
|
||||
if (!box) { return 0; }
|
||||
|
||||
var docEl = document.documentElement,
|
||||
body = document.body,
|
||||
clientLeft = docEl.clientLeft || body.clientLeft || 0,
|
||||
scrollLeft = window.pageXOffset || body.scrollLeft,
|
||||
left = box.left + scrollLeft - clientLeft;
|
||||
|
||||
return left;
|
||||
};
|
||||
} else {
|
||||
vjs.findPosX = function(el) {
|
||||
var curleft = el.offsetLeft;
|
||||
// vjs.log(obj.className, obj.offsetLeft)
|
||||
while(el = el.offsetParent) {
|
||||
if (el.className.indexOf('video-js') == -1) {
|
||||
// vjs.log(el.offsetParent, 'OFFSETLEFT', el.offsetLeft)
|
||||
// vjs.log('-webkit-full-screen', el.webkitMatchesSelector('-webkit-full-screen'));
|
||||
// vjs.log('-webkit-full-screen', el.querySelectorAll('.video-js:-webkit-full-screen'));
|
||||
} else {
|
||||
}
|
||||
curleft += el.offsetLeft;
|
||||
}
|
||||
return curleft;
|
||||
};
|
||||
}
|
27
src/js/media.flash.externs.js
Normal file
27
src/js/media.flash.externs.js
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @fileoverview Externs for video-js.swf. Externs are functions
|
||||
* that the compiler shouldn't obfuscate.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
*/
|
||||
HTMLObjectElement.prototype.vjs_getProperty = function(name) {};
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string|number} value
|
||||
*/
|
||||
HTMLObjectElement.prototype.vjs_setProperty = function(name, value) {};
|
||||
|
||||
/**
|
||||
* Control methods
|
||||
*/
|
||||
HTMLObjectElement.prototype.vjs_play = function() {};
|
||||
HTMLObjectElement.prototype.vjs_pause = function() {};
|
||||
HTMLObjectElement.prototype.vjs_load = function() {};
|
||||
|
||||
/**
|
||||
* @param {string} src
|
||||
*/
|
||||
HTMLObjectElement.prototype.vjs_src = function(src) {};
|
468
src/js/media.flash.js
Normal file
468
src/js/media.flash.js
Normal file
@ -0,0 +1,468 @@
|
||||
/**
|
||||
* @fileoverview VideoJS-SWF - Custom Flash Player with HTML5-ish API
|
||||
* https://github.com/zencoder/video-js-swf
|
||||
* Not using setupTriggers. Using global onEvent func to distribute events
|
||||
*/
|
||||
|
||||
goog.provide('vjs.Flash');
|
||||
|
||||
goog.require('vjs.MediaTechController');
|
||||
|
||||
/**
|
||||
* HTML5 Media Controller - Wrapper for HTML5 Media API
|
||||
* @param {vjs.Player|Object} player
|
||||
* @param {Object=} options
|
||||
* @param {Function=} ready
|
||||
* @constructor
|
||||
*/
|
||||
vjs.Flash = function(player, options, ready){
|
||||
goog.base(this, player, options, ready);
|
||||
|
||||
var source = options.source,
|
||||
|
||||
// Which element to embed in
|
||||
parentEl = options.parentEl,
|
||||
|
||||
// Create a temporary element to be replaced by swf object
|
||||
placeHolder = this.el_ = vjs.createEl('div', { id: player.id() + '_temp_flash' }),
|
||||
|
||||
// Generate ID for swf object
|
||||
objId = player.id()+'_flash_api',
|
||||
|
||||
// Store player options in local var for optimization
|
||||
// TODO: switch to using player methods instead of options
|
||||
// e.g. player.autoplay();
|
||||
playerOptions = player.options,
|
||||
|
||||
// Merge default flashvars with ones passed in to init
|
||||
flashVars = vjs.merge({
|
||||
|
||||
// SWF Callback Functions
|
||||
'readyFunction': 'videojs.Flash.onReady',
|
||||
'eventProxyFunction': 'videojs.Flash.onEvent',
|
||||
'errorEventProxyFunction': 'videojs.Flash.onError',
|
||||
|
||||
// Player Settings
|
||||
'autoplay': playerOptions.autoplay,
|
||||
'preload': playerOptions.preload,
|
||||
'loop': playerOptions.loop,
|
||||
'muted': playerOptions.muted
|
||||
|
||||
}, options['flashVars']),
|
||||
|
||||
// Merge default parames with ones passed in
|
||||
params = vjs.merge({
|
||||
'wmode': 'opaque', // Opaque is needed to overlay controls, but can affect playback performance
|
||||
'bgcolor': '#000000' // Using bgcolor prevents a white flash when the object is loading
|
||||
}, options['params']),
|
||||
|
||||
// Merge default attributes with ones passed in
|
||||
attributes = vjs.merge({
|
||||
'id': objId,
|
||||
'name': objId, // Both ID and Name needed or swf to identifty itself
|
||||
'class': 'vjs-tech'
|
||||
}, options['attributes'])
|
||||
;
|
||||
|
||||
// If source was supplied pass as a flash var.
|
||||
if (source) {
|
||||
flashVars['src'] = encodeURIComponent(vjs.getAbsoluteURL(source.src));
|
||||
}
|
||||
|
||||
// Add placeholder to player div
|
||||
vjs.insertFirst(placeHolder, parentEl);
|
||||
|
||||
// Having issues with Flash reloading on certain page actions (hide/resize/fullscreen) in certain browsers
|
||||
// This allows resetting the playhead when we catch the reload
|
||||
if (options.startTime) {
|
||||
this.ready(function(){
|
||||
this.load();
|
||||
this.play();
|
||||
this.currentTime(options.startTime);
|
||||
});
|
||||
}
|
||||
|
||||
// Flash iFrame Mode
|
||||
// In web browsers there are multiple instances where changing the parent element or visibility of a plugin causes the plugin to reload.
|
||||
// - Firefox just about always. https://bugzilla.mozilla.org/show_bug.cgi?id=90268 (might be fixed by version 13)
|
||||
// - Webkit when hiding the plugin
|
||||
// - Webkit and Firefox when using requestFullScreen on a parent element
|
||||
// Loading the flash plugin into a dynamically generated iFrame gets around most of these issues.
|
||||
// Issues that remain include hiding the element and requestFullScreen in Firefox specifically
|
||||
|
||||
// There's on particularly annoying issue with this method which is that Firefox throws a security error on an offsite Flash object loaded into a dynamically created iFrame.
|
||||
// Even though the iframe was inserted into a page on the web, Firefox + Flash considers it a local app trying to access an internet file.
|
||||
// I tried mulitple ways of setting the iframe src attribute but couldn't find a src that worked well. Tried a real/fake source, in/out of domain.
|
||||
// Also tried a method from stackoverflow that caused a security error in all browsers. http://stackoverflow.com/questions/2486901/how-to-set-document-domain-for-a-dynamically-generated-iframe
|
||||
// In the end the solution I found to work was setting the iframe window.location.href right before doing a document.write of the Flash object.
|
||||
// The only downside of this it seems to trigger another http request to the original page (no matter what's put in the href). Not sure why that is.
|
||||
|
||||
// NOTE (2012-01-29): Cannot get Firefox to load the remote hosted SWF into a dynamically created iFrame
|
||||
// Firefox 9 throws a security error, unleess you call location.href right before doc.write.
|
||||
// Not sure why that even works, but it causes the browser to look like it's continuously trying to load the page.
|
||||
// Firefox 3.6 keeps calling the iframe onload function anytime I write to it, causing an endless loop.
|
||||
|
||||
if (options.iFrameMode === true && !vjs.IS_FIREFOX) {
|
||||
|
||||
// Create iFrame with vjs-tech class so it's 100% width/height
|
||||
var iFrm = vjs.createEl('iframe', {
|
||||
'id': objId + '_iframe',
|
||||
'name': objId + '_iframe',
|
||||
'className': 'vjs-tech',
|
||||
'scrolling': 'no',
|
||||
'marginWidth': 0,
|
||||
'marginHeight': 0,
|
||||
'frameBorder': 0
|
||||
});
|
||||
|
||||
// Update ready function names in flash vars for iframe window
|
||||
flashVars['readyFunction'] = 'ready';
|
||||
flashVars['eventProxyFunction'] = 'events';
|
||||
flashVars['errorEventProxyFunction'] = 'errors';
|
||||
|
||||
// Tried multiple methods to get this to work in all browsers
|
||||
|
||||
// Tried embedding the flash object in the page first, and then adding a place holder to the iframe, then replacing the placeholder with the page object.
|
||||
// The goal here was to try to load the swf URL in the parent page first and hope that got around the firefox security error
|
||||
// var newObj = vjs.Flash.embed(options.swf, placeHolder, flashVars, params, attributes);
|
||||
// (in onload)
|
||||
// var temp = vjs.createEl('a', { id:'asdf', innerHTML: 'asdf' } );
|
||||
// iDoc.body.appendChild(temp);
|
||||
|
||||
// Tried embedding the flash object through javascript in the iframe source.
|
||||
// This works in webkit but still triggers the firefox security error
|
||||
// iFrm.src = 'javascript: document.write('"+vjs.Flash.getEmbedCode(options.swf, flashVars, params, attributes)+"');";
|
||||
|
||||
// Tried an actual local iframe just to make sure that works, but it kills the easiness of the CDN version if you require the user to host an iframe
|
||||
// We should add an option to host the iframe locally though, because it could help a lot of issues.
|
||||
// iFrm.src = "iframe.html";
|
||||
|
||||
// Wait until iFrame has loaded to write into it.
|
||||
vjs.on(iFrm, 'load', vjs.bind(this, function(){
|
||||
|
||||
var iDoc,
|
||||
iWin = iFrm.contentWindow;
|
||||
|
||||
// The one working method I found was to use the iframe's document.write() to create the swf object
|
||||
// This got around the security issue in all browsers except firefox.
|
||||
// I did find a hack where if I call the iframe's window.location.href='', it would get around the security error
|
||||
// However, the main page would look like it was loading indefinitely (URL bar loading spinner would never stop)
|
||||
// Plus Firefox 3.6 didn't work no matter what I tried.
|
||||
// if (vjs.USER_AGENT.match('Firefox')) {
|
||||
// iWin.location.href = '';
|
||||
// }
|
||||
|
||||
// Get the iFrame's document depending on what the browser supports
|
||||
iDoc = iFrm.contentDocument ? iFrm.contentDocument : iFrm.contentWindow.document;
|
||||
|
||||
// Tried ensuring both document domains were the same, but they already were, so that wasn't the issue.
|
||||
// Even tried adding /. that was mentioned in a browser security writeup
|
||||
// document.domain = document.domain+'/.';
|
||||
// iDoc.domain = document.domain+'/.';
|
||||
|
||||
// Tried adding the object to the iframe doc's innerHTML. Security error in all browsers.
|
||||
// iDoc.body.innerHTML = swfObjectHTML;
|
||||
|
||||
// Tried appending the object to the iframe doc's body. Security error in all browsers.
|
||||
// iDoc.body.appendChild(swfObject);
|
||||
|
||||
// Using document.write actually got around the security error that browsers were throwing.
|
||||
// Again, it's a dynamically generated (same domain) iframe, loading an external Flash swf.
|
||||
// Not sure why that's a security issue, but apparently it is.
|
||||
iDoc.write(vjs.Flash.getEmbedCode(options['swf'], flashVars, params, attributes));
|
||||
|
||||
// Setting variables on the window needs to come after the doc write because otherwise they can get reset in some browsers
|
||||
// So far no issues with swf ready event being called before it's set on the window.
|
||||
iWin.player = this.player;
|
||||
|
||||
// Create swf ready function for iFrame window
|
||||
iWin.ready = vjs.bind(this.player, function(currSwf){
|
||||
var el = iDoc.getElementById(currSwf),
|
||||
player = this,
|
||||
tech = player.tech;
|
||||
|
||||
// Update reference to playback technology element
|
||||
tech.el = el;
|
||||
|
||||
// Now that the element is ready, make a click on the swf play the video
|
||||
vjs.on(el, 'click', tech.bind(tech.onClick));
|
||||
|
||||
// Make sure swf is actually ready. Sometimes the API isn't actually yet.
|
||||
vjs.Flash.checkReady(tech);
|
||||
});
|
||||
|
||||
// Create event listener for all swf events
|
||||
iWin.events = vjs.bind(this.player, function(swfID, eventName){
|
||||
var player = this;
|
||||
if (player && player.techName === 'flash') {
|
||||
player.trigger(eventName);
|
||||
}
|
||||
});
|
||||
|
||||
// Create error listener for all swf errors
|
||||
iWin.errors = vjs.bind(this.player, function(swfID, eventName){
|
||||
vjs.log('Flash Error', eventName);
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// Replace placeholder with iFrame (it will load now)
|
||||
placeHolder.parentNode.replaceChild(iFrm, placeHolder);
|
||||
|
||||
// If not using iFrame mode, embed as normal object
|
||||
} else {
|
||||
vjs.Flash.embed(options['swf'], placeHolder, flashVars, params, attributes);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(vjs.Flash, vjs.MediaTechController);
|
||||
|
||||
vjs.Flash.prototype.dispose = function(){
|
||||
goog.base(this, 'dispose');
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.play = function(){
|
||||
this.el_.vjs_play();
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.pause = function(){
|
||||
this.el_.vjs_pause();
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.src = function(src){
|
||||
// Make sure source URL is abosolute.
|
||||
src = vjs.getAbsoluteURL(src);
|
||||
|
||||
this.el_.vjs_src(src);
|
||||
|
||||
// Currently the SWF doesn't autoplay if you load a source later.
|
||||
// e.g. Load player w/ no source, wait 2s, set src.
|
||||
if (this.player.autoplay()) {
|
||||
var tech = this;
|
||||
setTimeout(function(){ tech.play(); }, 0);
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.load = function(){
|
||||
this.el_.vjs_load();
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.poster = function(){
|
||||
this.el_.vjs_getProperty('poster');
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.buffered = function(){
|
||||
return vjs.createTimeRange(0, this.el_.vjs_getProperty('buffered'));
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.supportsFullScreen = function(){
|
||||
return false; // Flash does not allow fullscreen through javascript
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.enterFullScreen = function(){
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
// Create setters and getters for attributes
|
||||
var api = vjs.Flash.prototype,
|
||||
readWrite = 'preload,currentTime,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(','),
|
||||
readOnly = 'error,currentSrc,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks'.split(',');
|
||||
// Overridden: buffered
|
||||
|
||||
/**
|
||||
* @this {*}
|
||||
*/
|
||||
var createSetter = function(attr){
|
||||
var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
|
||||
api['set'+attrUpper] = function(val){ return this.el_.vjs_setProperty(attr, val); };
|
||||
};
|
||||
|
||||
/**
|
||||
* @this {*}
|
||||
*/
|
||||
var createGetter = function(attr){
|
||||
api[attr] = function(){ return this.el_.vjs_getProperty(attr); };
|
||||
};
|
||||
|
||||
// Create getter and setters for all read/write attributes
|
||||
for (var i = 0; i < readWrite.length; i++) {
|
||||
createGetter(readWrite[i]);
|
||||
createSetter(readWrite[i]);
|
||||
}
|
||||
|
||||
// Create getters for read-only attributes
|
||||
for (var i = 0; i < readOnly.length; i++) {
|
||||
createGetter(readOnly[i]);
|
||||
}
|
||||
|
||||
/* Flash Support Testing -------------------------------------------------------- */
|
||||
|
||||
vjs.Flash.isSupported = function(){
|
||||
return vjs.Flash.version()[0] >= 10;
|
||||
// return swfobject.hasFlashPlayerVersion('10');
|
||||
};
|
||||
|
||||
vjs.Flash.canPlaySource = function(srcObj){
|
||||
if (srcObj.type in vjs.Flash.prototype.features.formats) { return 'maybe'; }
|
||||
};
|
||||
|
||||
vjs.Flash.prototype.features = {
|
||||
formats: {
|
||||
'video/flv': 'FLV',
|
||||
'video/x-flv': 'FLV',
|
||||
'video/mp4': 'MP4',
|
||||
'video/m4v': 'MP4'
|
||||
},
|
||||
|
||||
// Optional events that we can manually mimic with timers
|
||||
// currently not triggered by video-js-swf
|
||||
progressEvents: false,
|
||||
timeupdateEvents: false,
|
||||
|
||||
// Resizing plugins using request fullscreen reloads the plugin
|
||||
fullscreenResize: false,
|
||||
|
||||
// Resizing plugins in Firefox always reloads the plugin (e.g. full window mode)
|
||||
parentResize: !(vjs.USER_AGENT.match('Firefox'))
|
||||
};
|
||||
|
||||
vjs.Flash['onReady'] = function(currSwf){
|
||||
var el = vjs.el(currSwf);
|
||||
|
||||
// Get player from box
|
||||
// On firefox reloads, el might already have a player
|
||||
var player = el.player || el.parentNode.player,
|
||||
tech = player.tech;
|
||||
|
||||
// Reference player on tech element
|
||||
el.player = player;
|
||||
|
||||
// Update reference to playback technology element
|
||||
tech.el_ = el;
|
||||
|
||||
// Now that the element is ready, make a click on the swf play the video
|
||||
tech.on('click', tech.onClick);
|
||||
|
||||
vjs.Flash.checkReady(tech);
|
||||
};
|
||||
|
||||
// The SWF isn't alwasy ready when it says it is. Sometimes the API functions still need to be added to the object.
|
||||
// If it's not ready, we set a timeout to check again shortly.
|
||||
vjs.Flash.checkReady = function(tech){
|
||||
|
||||
// Check if API property exists
|
||||
if (tech.el().vjs_getProperty) {
|
||||
|
||||
// If so, tell tech it's ready
|
||||
tech.triggerReady();
|
||||
|
||||
// Otherwise wait longer.
|
||||
} else {
|
||||
|
||||
setTimeout(function(){
|
||||
vjs.Flash.checkReady(tech);
|
||||
}, 50);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger events from the swf on the player
|
||||
vjs.Flash['onEvent'] = function(swfID, eventName){
|
||||
var player = vjs.el(swfID).player;
|
||||
player.trigger(eventName);
|
||||
};
|
||||
|
||||
// Log errors from the swf
|
||||
vjs.Flash['onError'] = function(swfID, err){
|
||||
var player = vjs.el(swfID).player;
|
||||
player.trigger('error');
|
||||
vjs.log('Flash Error', err, swfID);
|
||||
};
|
||||
|
||||
// Flash Version Check
|
||||
vjs.Flash.version = function(){
|
||||
var version = '0,0,0';
|
||||
|
||||
// IE
|
||||
try {
|
||||
version = new window.ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
|
||||
|
||||
// other browsers
|
||||
} catch(e) {
|
||||
try {
|
||||
if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin){
|
||||
version = (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']).description.replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
|
||||
}
|
||||
} catch(err) {}
|
||||
}
|
||||
return version.split(',');
|
||||
};
|
||||
|
||||
// Flash embedding method. Only used in non-iframe mode
|
||||
vjs.Flash.embed = function(swf, placeHolder, flashVars, params, attributes){
|
||||
var code = vjs.Flash.getEmbedCode(swf, flashVars, params, attributes),
|
||||
|
||||
// Get element by embedding code and retrieving created element
|
||||
obj = vjs.createEl('div', { innerHTML: code }).childNodes[0],
|
||||
|
||||
par = placeHolder.parentNode
|
||||
;
|
||||
|
||||
placeHolder.parentNode.replaceChild(obj, placeHolder);
|
||||
|
||||
// IE6 seems to have an issue where it won't initialize the swf object after injecting it.
|
||||
// This is a dumb fix
|
||||
var newObj = par.childNodes[0];
|
||||
setTimeout(function(){
|
||||
newObj.style.display = 'block';
|
||||
}, 1000);
|
||||
|
||||
return obj;
|
||||
|
||||
};
|
||||
|
||||
vjs.Flash.getEmbedCode = function(swf, flashVars, params, attributes){
|
||||
|
||||
var objTag = '<object type="application/x-shockwave-flash"',
|
||||
flashVarsString = '',
|
||||
paramsString = '',
|
||||
attrsString = '';
|
||||
|
||||
// Convert flash vars to string
|
||||
if (flashVars) {
|
||||
vjs.eachProp(flashVars, function(key, val){
|
||||
flashVarsString += (key + '=' + val + '&');
|
||||
});
|
||||
}
|
||||
|
||||
// Add swf, flashVars, and other default params
|
||||
params = vjs.merge({
|
||||
'movie': swf,
|
||||
'flashvars': flashVarsString,
|
||||
'allowScriptAccess': 'always', // Required to talk to swf
|
||||
'allowNetworking': 'all' // All should be default, but having security issues.
|
||||
}, params);
|
||||
|
||||
// Create param tags string
|
||||
vjs.eachProp(params, function(key, val){
|
||||
paramsString += '<param name="'+key+'" value="'+val+'" />';
|
||||
});
|
||||
|
||||
attributes = vjs.merge({
|
||||
// Add swf to attributes (need both for IE and Others to work)
|
||||
'data': swf,
|
||||
|
||||
// Default to 100% width/height
|
||||
'width': '100%',
|
||||
'height': '100%'
|
||||
|
||||
}, attributes);
|
||||
|
||||
// Create Attributes string
|
||||
vjs.eachProp(attributes, function(key, val){
|
||||
attrsString += (key + '="' + val + '" ');
|
||||
});
|
||||
|
||||
return objTag + attrsString + '>' + paramsString + '</object>';
|
||||
};
|
247
src/js/media.html5.js
Normal file
247
src/js/media.html5.js
Normal file
@ -0,0 +1,247 @@
|
||||
/**
|
||||
* @fileoverview HTML5 Media Controller - Wrapper for HTML5 Media API
|
||||
*/
|
||||
|
||||
goog.provide('vjs.Html5');
|
||||
|
||||
goog.require('vjs.MediaTechController');
|
||||
|
||||
/**
|
||||
* HTML5 Media Controller - Wrapper for HTML5 Media API
|
||||
* @param {vjs.Player|Object} player
|
||||
* @param {Object=} options
|
||||
* @param {Function=} ready
|
||||
* @constructor
|
||||
*/
|
||||
vjs.Html5 = function(player, options, ready){
|
||||
goog.base(this, player, options, ready);
|
||||
|
||||
var source = options.source;
|
||||
|
||||
// If the element source is already set, we may have missed the loadstart event, and want to trigger it.
|
||||
// We don't want to set the source again and interrupt playback.
|
||||
if (source && this.el_.currentSrc == source.src) {
|
||||
player.trigger('loadstart');
|
||||
|
||||
// Otherwise set the source if one was provided.
|
||||
} else if (source) {
|
||||
this.el_.src = source.src;
|
||||
}
|
||||
|
||||
// Chrome and Safari both have issues with autoplay.
|
||||
// In Safari (5.1.1), when we move the video element into the container div, autoplay doesn't work.
|
||||
// In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
|
||||
// This fixes both issues. Need to wait for API, so it updates displays correctly
|
||||
player.ready(function(){
|
||||
if (this.options.autoplay && this.paused()) {
|
||||
this.tag.poster = null; // Chrome Fix. Fixed in Chrome v16.
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.on('click', this.onClick);
|
||||
|
||||
this.setupTriggers();
|
||||
|
||||
this.triggerReady();
|
||||
};
|
||||
goog.inherits(vjs.Html5, vjs.MediaTechController);
|
||||
|
||||
vjs.Html5.prototype.dispose = function(){
|
||||
// this.player.tag = false;
|
||||
this.removeTriggers();
|
||||
|
||||
goog.base(this, 'dispose');
|
||||
};
|
||||
|
||||
vjs.Html5.prototype.createEl = function(){
|
||||
var player = this.player,
|
||||
// If possible, reuse original tag for HTML5 playback technology element
|
||||
el = player.tag,
|
||||
newEl;
|
||||
|
||||
// Check if this browser supports moving the element into the box.
|
||||
// On the iPhone video will break if you move the element,
|
||||
// So we have to create a brand new element.
|
||||
if (!el || this.features.movingMediaElementInDOM === false) {
|
||||
|
||||
// If the original tag is still there, remove it.
|
||||
if (el) {
|
||||
player.el().removeChild(el);
|
||||
}
|
||||
|
||||
newEl = vjs.createElement('video', {
|
||||
id: el.id || player.id + '_html5_api',
|
||||
className: el.className || 'vjs-tech'
|
||||
});
|
||||
|
||||
el = newEl;
|
||||
vjs.insertFirst(el, player.el);
|
||||
}
|
||||
|
||||
// Update specific tag settings, in case they were overridden
|
||||
var attrs = ['autoplay','preload','loop','muted'];
|
||||
for (var i = attrs.length - 1; i >= 0; i--) {
|
||||
var attr = attrs[i];
|
||||
if (player.options[attr] !== null) {
|
||||
el[attr] = player.options[attr];
|
||||
}
|
||||
}
|
||||
|
||||
return el;
|
||||
// jenniisawesome = true;
|
||||
};
|
||||
|
||||
// Make video events trigger player events
|
||||
// May seem verbose here, but makes other APIs possible.
|
||||
vjs.Html5.prototype.setupTriggers = function(){
|
||||
for (var i = vjs.Html5.Events.length - 1; i >= 0; i--) {
|
||||
vjs.on(this.el_, vjs.Html5.Events[i], vjs.bind(this.player, this.eventHandler));
|
||||
}
|
||||
};
|
||||
vjs.Html5.prototype.removeTriggers = function(){
|
||||
for (var i = vjs.Html5.Events.length - 1; i >= 0; i--) {
|
||||
vjs.off(this.el_, vjs.Html5.Events[i], vjs.bind(this.player, this.eventHandler));
|
||||
}
|
||||
// console.log('removeTriggers', vjs.getData(this.el_));
|
||||
};
|
||||
vjs.Html5.prototype.eventHandler = function(e){
|
||||
// console.log('eventHandler', e.type, e, this.el_)
|
||||
this.trigger(e);
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
|
||||
vjs.Html5.prototype.play = function(){ this.el_.play(); };
|
||||
vjs.Html5.prototype.pause = function(){ this.el_.pause(); };
|
||||
vjs.Html5.prototype.paused = function(){ return this.el_.paused; };
|
||||
|
||||
vjs.Html5.prototype.currentTime = function(){ return this.el_.currentTime; };
|
||||
vjs.Html5.prototype.setCurrentTime = function(seconds){
|
||||
try {
|
||||
this.el_.currentTime = seconds;
|
||||
} catch(e) {
|
||||
vjs.log(e, 'Video is not ready. (Video.js)');
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Html5.prototype.duration = function(){ return this.el_.duration || 0; };
|
||||
vjs.Html5.prototype.buffered = function(){ return this.el_.buffered; };
|
||||
|
||||
vjs.Html5.prototype.volume = function(){ return this.el_.volume; };
|
||||
vjs.Html5.prototype.setVolume = function(percentAsDecimal){ this.el_.volume = percentAsDecimal; };
|
||||
vjs.Html5.prototype.muted = function(){ return this.el_.muted; };
|
||||
vjs.Html5.prototype.setMuted = function(muted){ this.el_.muted = muted; };
|
||||
|
||||
vjs.Html5.prototype.width = function(){ return this.el_.offsetWidth; };
|
||||
vjs.Html5.prototype.height = function(){ return this.el_.offsetHeight; };
|
||||
|
||||
vjs.Html5.prototype.supportsFullScreen = function(){
|
||||
if (typeof this.el_.webkitEnterFullScreen == 'function') {
|
||||
|
||||
// Seems to be broken in Chromium/Chrome && Safari in Leopard
|
||||
if (!navigator.userAgent.match('Chrome') && !navigator.userAgent.match('Mac OS X 10.5')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
vjs.Html5.prototype.enterFullScreen = function(){
|
||||
try {
|
||||
this.el_.webkitEnterFullScreen();
|
||||
} catch (e) {
|
||||
if (e.code == 11) {
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
vjs.log('Video.js: Video not ready.');
|
||||
}
|
||||
}
|
||||
};
|
||||
vjs.Html5.prototype.exitFullScreen = function(){
|
||||
try {
|
||||
this.el_.webkitExitFullScreen();
|
||||
} catch (e) {
|
||||
if (e.code == 11) {
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
vjs.log('Video.js: Video not ready.');
|
||||
}
|
||||
}
|
||||
};
|
||||
vjs.Html5.prototype.src = function(src){ this.el_.src = src; };
|
||||
vjs.Html5.prototype.load = function(){ this.el_.load(); };
|
||||
vjs.Html5.prototype.currentSrc = function(){ return this.el_.currentSrc; };
|
||||
|
||||
vjs.Html5.prototype.preload = function(){ return this.el_.preload; };
|
||||
vjs.Html5.prototype.setPreload = function(val){ this.el_.preload = val; };
|
||||
vjs.Html5.prototype.autoplay = function(){ return this.el_.autoplay; };
|
||||
vjs.Html5.prototype.setAutoplay = function(val){ this.el_.autoplay = val; };
|
||||
vjs.Html5.prototype.loop = function(){ return this.el_.loop; };
|
||||
vjs.Html5.prototype.setLoop = function(val){ this.el_.loop = val; };
|
||||
|
||||
vjs.Html5.prototype.error = function(){ return this.el_.error; };
|
||||
// networkState: function(){ return this.el_.networkState; },
|
||||
// readyState: function(){ return this.el_.readyState; },
|
||||
vjs.Html5.prototype.seeking = function(){ return this.el_.seeking; };
|
||||
// initialTime: function(){ return this.el_.initialTime; },
|
||||
// startOffsetTime: function(){ return this.el_.startOffsetTime; },
|
||||
// played: function(){ return this.el_.played; },
|
||||
// seekable: function(){ return this.el_.seekable; },
|
||||
vjs.Html5.prototype.ended = function(){ return this.el_.ended; };
|
||||
// videoTracks: function(){ return this.el_.videoTracks; },
|
||||
// audioTracks: function(){ return this.el_.audioTracks; },
|
||||
// videoWidth: function(){ return this.el_.videoWidth; },
|
||||
// videoHeight: function(){ return this.el_.videoHeight; },
|
||||
// textTracks: function(){ return this.el_.textTracks; },
|
||||
// defaultPlaybackRate: function(){ return this.el_.defaultPlaybackRate; },
|
||||
// playbackRate: function(){ return this.el_.playbackRate; },
|
||||
// mediaGroup: function(){ return this.el_.mediaGroup; },
|
||||
// controller: function(){ return this.el_.controller; },
|
||||
vjs.Html5.prototype.controls = function(){ return this.player.options.controls; };
|
||||
vjs.Html5.prototype.defaultMuted = function(){ return this.el_.defaultMuted; };
|
||||
|
||||
/* HTML5 Support Testing ---------------------------------------------------- */
|
||||
|
||||
vjs.Html5.isSupported = function(){
|
||||
return !!document.createElement('video').canPlayType;
|
||||
};
|
||||
|
||||
vjs.Html5.canPlaySource = function(srcObj){
|
||||
return !!document.createElement('video').canPlayType(srcObj.type);
|
||||
// TODO: Check Type
|
||||
// If no Type, check ext
|
||||
// Check Media Type
|
||||
};
|
||||
|
||||
// List of all HTML5 events (various uses).
|
||||
vjs.Html5.Events = 'loadstart,suspend,abort,error,emptied,stalled,loadedmetadata,loadeddata,canplay,canplaythrough,playing,waiting,seeking,seeked,ended,durationchange,timeupdate,progress,play,pause,ratechange,volumechange'.split(',');
|
||||
|
||||
|
||||
// HTML5 Feature detection and Device Fixes --------------------------------- //
|
||||
vjs.Html5.prototype.features = {
|
||||
|
||||
// Support for video element specific full screen. (webkitEnterFullScreen, not requestFullscreen which we use on the player div)
|
||||
// http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/HTMLVideoElementClassReference/HTMLVideoElement/HTMLVideoElement.html
|
||||
// Seems to be broken in Chromium/Chrome && Safari in Leopard
|
||||
fullscreen: (vjs.TEST_VID.webkitEnterFullScreen)
|
||||
? ((!vjs.USER_AGENT.match('Chrome') && !vjs.USER_AGENT.match('Mac OS X 10.5')
|
||||
? true
|
||||
: false))
|
||||
: false,
|
||||
|
||||
// In iOS, if you move a video element in the DOM, it breaks video playback.
|
||||
movingMediaElementInDOM: !vjs.IS_IOS
|
||||
|
||||
};
|
||||
|
||||
// Android
|
||||
if (vjs.IS_ANDROID) {
|
||||
|
||||
// Override Android 2.2 and less canPlayType method which is broken
|
||||
if (vjs.ANDROID_VERSION < 3) {
|
||||
document.createElement('video').constructor.prototype.canPlayType = function(type){
|
||||
return (type && type.toLowerCase().indexOf('video/mp4') != -1) ? 'maybe' : '';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
59
src/js/media.js
Normal file
59
src/js/media.js
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @fileoverview Media Technology Controller - Base class for media playback technologies
|
||||
*/
|
||||
|
||||
goog.provide('vjs.MediaTechController');
|
||||
|
||||
goog.require('vjs.Component');
|
||||
|
||||
/**
|
||||
* Base class for media (HTML5 Video, Flash) controllers
|
||||
* @param {vjs.Player|Object} player Central player instance
|
||||
* @param {Object=} options Options object
|
||||
* @constructor
|
||||
*/
|
||||
vjs.MediaTechController = function(player, options, ready){
|
||||
goog.base(this, player, options, ready);
|
||||
|
||||
// Make playback element clickable
|
||||
// this.addEvent('click', this.proxy(this.onClick));
|
||||
|
||||
// player.triggerEvent('techready');
|
||||
};
|
||||
goog.inherits(vjs.MediaTechController, vjs.Component);
|
||||
|
||||
// destroy: function(){},
|
||||
// createElement: function(){},
|
||||
|
||||
/**
|
||||
* Handle a click on the media element. By default will play the media.
|
||||
*/
|
||||
vjs.MediaTechController.prototype.onClick = function(){
|
||||
if (this.player.options.controls) {
|
||||
if (this.player.paused()) {
|
||||
this.player.play();
|
||||
} else {
|
||||
this.player.pause();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
vjs.media = {};
|
||||
|
||||
/**
|
||||
* List of default API methods for any MediaTechController
|
||||
* @type {String}
|
||||
*/
|
||||
vjs.media.ApiMethods = 'play,pause,paused,currentTime,setCurrentTime,duration,buffered,volume,setVolume,muted,setMuted,width,height,supportsFullScreen,enterFullScreen,src,load,currentSrc,preload,setPreload,autoplay,setAutoplay,loop,setLoop,error,networkState,readyState,seeking,initialTime,startOffsetTime,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks,defaultPlaybackRate,playbackRate,mediaGroup,controller,controls,defaultMuted'.split(',');
|
||||
// Create placeholder methods for each that warn when a method isn't supported by the current playback technology
|
||||
|
||||
function createMethod(methodName){
|
||||
return function(){
|
||||
throw new Error('The "'+methodName+'" method is not available on the playback technology\'s API');
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = vjs.media.ApiMethods.length - 1; i >= 0; i--) {
|
||||
var methodName = vjs.media.ApiMethods[i];
|
||||
vjs.MediaTechController.prototype[vjs.media.ApiMethods[i]] = createMethod(methodName);
|
||||
}
|
886
src/js/player.js
Normal file
886
src/js/player.js
Normal file
@ -0,0 +1,886 @@
|
||||
goog.provide('vjs.Player');
|
||||
|
||||
goog.require('vjs.Component');
|
||||
|
||||
/**
|
||||
* Main player class. A player instance is returned by _V_(id);
|
||||
* @param {Element} tag The original video tag used for configuring options
|
||||
* @param {Object=} options Player options
|
||||
* @param {Function=} ready Ready callback function
|
||||
* @constructor
|
||||
*/
|
||||
vjs.Player = function(tag, options, ready){
|
||||
this.tag = tag; // Store the original tag used to set options
|
||||
|
||||
// Set Options
|
||||
// The options argument overrides options set in the video tag
|
||||
// which overrides globally set options.
|
||||
// This latter part coincides with the load order
|
||||
// (tag must exist before Player)
|
||||
var opts = {};
|
||||
vjs.merge(opts, vjs.options); // Copy Global Defaults
|
||||
vjs.merge(opts, this.getTagSettings(tag)); // Override with Video Tag Options
|
||||
vjs.merge(opts, options); // Override/extend with options from setup call
|
||||
|
||||
// Cache for video property values.
|
||||
this.cache_ = {};
|
||||
|
||||
// Run base component initializing with new options.
|
||||
// Builds the element through createEl()
|
||||
// Inits and embeds any child components in opts
|
||||
vjs.Component.call(this, this, opts, ready);
|
||||
|
||||
this.on('ended', this.onEnded);
|
||||
this.on('play', this.onPlay);
|
||||
this.on('pause', this.onPause);
|
||||
this.on('progress', this.onProgress);
|
||||
this.on('durationchange', this.onDurationChange);
|
||||
this.on('error', this.onError);
|
||||
|
||||
// Make player easily findable by ID
|
||||
vjs.players[this.id_] = this;
|
||||
};
|
||||
goog.inherits(vjs.Player, vjs.Component);
|
||||
|
||||
vjs.Player.prototype.dispose = function(){
|
||||
// this.isReady_ = false;
|
||||
|
||||
// Kill reference to this player
|
||||
vjs.players[this.id_] = null;
|
||||
if (this.tag && this.tag.player) { this.tag.player = null; }
|
||||
if (this.el_ && this.el_.player) { this.el_.player = null; }
|
||||
|
||||
// Ensure that tracking progress and time progress will stop and plater deleted
|
||||
this.stopTrackingProgress();
|
||||
// this.stopTrackingCurrentTime();
|
||||
|
||||
if (this.tech) { this.tech.dispose(); }
|
||||
|
||||
// Component dispose
|
||||
goog.base(this, 'dispose');
|
||||
};
|
||||
|
||||
vjs.Player.prototype.getTagSettings = function(tag){
|
||||
var options = {
|
||||
'sources': [],
|
||||
'tracks': []
|
||||
};
|
||||
|
||||
vjs.merge(options, vjs.getAttributeValues(tag));
|
||||
|
||||
// Get tag children settings
|
||||
if (tag.hasChildNodes()) {
|
||||
var child, childName,
|
||||
children = tag.childNodes,
|
||||
i = 0,
|
||||
j = children.length;
|
||||
|
||||
for (; i < j; i++) {
|
||||
child = children[i];
|
||||
// Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
|
||||
childName = child.nodeName.toLowerCase();
|
||||
|
||||
if (childName === 'source') {
|
||||
options['sources'].push(vjs.getAttributeValues(child));
|
||||
|
||||
} else if (childName === 'track') {
|
||||
options['tracks'].push(vjs.getAttributeValues(child));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
vjs.Player.prototype.createEl = function(){
|
||||
var el = this.el_ = goog.base(this, 'createEl', 'div');
|
||||
var tag = this.tag;
|
||||
|
||||
// Original tag settings stored in options
|
||||
// now remove immediately so native controls don't flash.
|
||||
tag.removeAttribute('controls');
|
||||
// Poster will be handled by a manual <img>
|
||||
tag.removeAttribute('poster');
|
||||
// Remove width/height attrs from tag so CSS can make it 100% width/height
|
||||
tag.removeAttribute('width');
|
||||
tag.removeAttribute('height');
|
||||
// Empty video tag sources and tracks so the built-in player doesn't use them also.
|
||||
// This may not be fast enough to stop HTML5 browsers from reading the tags
|
||||
// so we'll need to turn off any default tracks if we're manually doing
|
||||
// captions and subtitles. videoElement.textTracks
|
||||
if (tag.hasChildNodes()) {
|
||||
var nrOfChildNodes = tag.childNodes.length;
|
||||
for (var i=0,j=tag.childNodes;i<nrOfChildNodes;i++) {
|
||||
if (j[0].nodeName.toLowerCase() == 'source' || j[0].nodeName.toLowerCase() == 'track') {
|
||||
tag.removeChild(j[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure tag ID exists
|
||||
tag.id = tag.id || 'vjs_video_' + vjs.guid++;
|
||||
|
||||
// Give video tag ID and class to player div
|
||||
// ID will now reference player box, not the video tag
|
||||
el.id = tag.id;
|
||||
el.className = tag.className;
|
||||
|
||||
// Update tag id/class for use as HTML5 playback tech
|
||||
// Might think we should do this after embedding in container so .vjs-tech class
|
||||
// doesn't flash 100% width/height, but class only applies with .video-js parent
|
||||
tag.id += '_html5_api';
|
||||
tag.className = 'vjs-tech';
|
||||
|
||||
// Make player findable on elements
|
||||
tag.player = el.player = this;
|
||||
|
||||
// Default state of video is paused
|
||||
this.addClass('vjs-paused');
|
||||
|
||||
// Make box use width/height of tag, or default 300x150
|
||||
// Enforce with CSS since width/height attrs don't work on divs
|
||||
this.width(this.options['width'], true); // (true) Skip resize listener on load
|
||||
this.height(this.options['height'], true);
|
||||
|
||||
// Wrap video tag in div (el/box) container
|
||||
if (tag.parentNode) {
|
||||
tag.parentNode.insertBefore(el, tag);
|
||||
}
|
||||
vjs.insertFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup.
|
||||
|
||||
return el;
|
||||
};
|
||||
|
||||
// /* Media Technology (tech)
|
||||
// ================================================================================ */
|
||||
// Load/Create an instance of playback technlogy including element and API methods
|
||||
// And append playback element in player div.
|
||||
vjs.Player.prototype.loadTech = function(techName, source){
|
||||
|
||||
// Pause and remove current playback technology
|
||||
if (this.tech) {
|
||||
this.unloadTech();
|
||||
|
||||
// If the first time loading, HTML5 tag will exist but won't be initialized
|
||||
// So we need to remove it if we're not loading HTML5
|
||||
} else if (techName !== 'Html5' && this.tag) {
|
||||
this.el_.removeChild(this.tag);
|
||||
this.tag = null;
|
||||
}
|
||||
|
||||
this.techName = techName;
|
||||
|
||||
// Turn off API access because we're loading a new tech that might load asynchronously
|
||||
this.isReady_ = false;
|
||||
|
||||
var techReady = function(){
|
||||
this.player.triggerReady();
|
||||
|
||||
// Manually track progress in cases where the browser/flash player doesn't report it.
|
||||
if (!this.features.progressEvents) {
|
||||
this.player.manualProgressOn();
|
||||
}
|
||||
|
||||
// Manually track timeudpates in cases where the browser/flash player doesn't report it.
|
||||
if (!this.features.timeupdateEvents) {
|
||||
this.player.manualTimeUpdatesOn();
|
||||
}
|
||||
};
|
||||
|
||||
// Grab tech-specific options from player options and add source and parent element to use.
|
||||
var techOptions = vjs.merge({ source: source, parentEl: this.el_ }, this.options[techName.toLowerCase()]);
|
||||
|
||||
if (source) {
|
||||
if (source.src == this.cache_.src && this.cache_.currentTime > 0) {
|
||||
techOptions['startTime'] = this.cache_.currentTime;
|
||||
}
|
||||
|
||||
this.cache_.src = source.src;
|
||||
}
|
||||
|
||||
// Initialize tech instance
|
||||
this.tech = new window['videojs'][techName](this, techOptions);
|
||||
|
||||
this.tech.ready(techReady);
|
||||
};
|
||||
|
||||
vjs.Player.prototype.unloadTech = function(){
|
||||
this.tech.dispose();
|
||||
|
||||
// Turn off any manual progress or timeupdate tracking
|
||||
if (this.manualProgress) { this.manualProgressOff(); }
|
||||
|
||||
if (this.manualTimeUpdates) { this.manualTimeUpdatesOff(); }
|
||||
|
||||
this.tech = false;
|
||||
};
|
||||
|
||||
// There's many issues around changing the size of a Flash (or other plugin) object.
|
||||
// First is a plugin reload issue in Firefox that has been around for 11 years: https://bugzilla.mozilla.org/show_bug.cgi?id=90268
|
||||
// Then with the new fullscreen API, Mozilla and webkit browsers will reload the flash object after going to fullscreen.
|
||||
// To get around this, we're unloading the tech, caching source and currentTime values, and reloading the tech once the plugin is resized.
|
||||
// reloadTech: function(betweenFn){
|
||||
// vjs.log('unloadingTech')
|
||||
// this.unloadTech();
|
||||
// vjs.log('unloadedTech')
|
||||
// if (betweenFn) { betweenFn.call(); }
|
||||
// vjs.log('LoadingTech')
|
||||
// this.loadTech(this.techName, { src: this.cache_.src })
|
||||
// vjs.log('loadedTech')
|
||||
// },
|
||||
|
||||
/* Fallbacks for unsupported event types
|
||||
================================================================================ */
|
||||
// Manually trigger progress events based on changes to the buffered amount
|
||||
// Many flash players and older HTML5 browsers don't send progress or progress-like events
|
||||
vjs.Player.prototype.manualProgressOn = function(){
|
||||
this.manualProgress = true;
|
||||
|
||||
// Trigger progress watching when a source begins loading
|
||||
this.trackProgress();
|
||||
|
||||
// Watch for a native progress event call on the tech element
|
||||
// In HTML5, some older versions don't support the progress event
|
||||
// So we're assuming they don't, and turning off manual progress if they do.
|
||||
// As opposed to doing user agent detection
|
||||
this.tech.one('progress', function(){
|
||||
|
||||
// Update known progress support for this playback technology
|
||||
this.features.progressEvents = true;
|
||||
|
||||
// Turn off manual progress tracking
|
||||
this.player.manualProgressOff();
|
||||
});
|
||||
};
|
||||
|
||||
vjs.Player.prototype.manualProgressOff = function(){
|
||||
this.manualProgress = false;
|
||||
this.stopTrackingProgress();
|
||||
};
|
||||
|
||||
vjs.Player.prototype.trackProgress = function(){
|
||||
|
||||
this.progressInterval = setInterval(vjs.bind(this, function(){
|
||||
// Don't trigger unless buffered amount is greater than last time
|
||||
// log(this.cache_.bufferEnd, this.buffered().end(0), this.duration())
|
||||
/* TODO: update for multiple buffered regions */
|
||||
if (this.cache_.bufferEnd < this.buffered().end(0)) {
|
||||
this.trigger('progress');
|
||||
} else if (this.bufferedPercent() == 1) {
|
||||
this.stopTrackingProgress();
|
||||
this.trigger('progress'); // Last update
|
||||
}
|
||||
}), 500);
|
||||
};
|
||||
vjs.Player.prototype.stopTrackingProgress = function(){ clearInterval(this.progressInterval); };
|
||||
|
||||
/* Time Tracking -------------------------------------------------------------- */
|
||||
vjs.Player.prototype.manualTimeUpdatesOn = function(){
|
||||
this.manualTimeUpdates = true;
|
||||
|
||||
this.on('play', this.trackCurrentTime);
|
||||
this.on('pause', this.stopTrackingCurrentTime);
|
||||
// timeupdate is also called by .currentTime whenever current time is set
|
||||
|
||||
// Watch for native timeupdate event
|
||||
this.tech.one('timeupdate', function(){
|
||||
// Update known progress support for this playback technology
|
||||
this.features.timeupdateEvents = true;
|
||||
// Turn off manual progress tracking
|
||||
this.player.manualTimeUpdatesOff();
|
||||
});
|
||||
};
|
||||
|
||||
vjs.Player.prototype.manualTimeUpdatesOff = function(){
|
||||
this.manualTimeUpdates = false;
|
||||
this.stopTrackingCurrentTime();
|
||||
this.off('play', this.trackCurrentTime);
|
||||
this.off('pause', this.stopTrackingCurrentTime);
|
||||
};
|
||||
|
||||
vjs.Player.prototype.trackCurrentTime = function(){
|
||||
if (this.currentTimeInterval) { this.stopTrackingCurrentTime(); }
|
||||
this.currentTimeInterval = setInterval(vjs.bind(this, function(){
|
||||
this.trigger('timeupdate');
|
||||
}), 250); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
|
||||
};
|
||||
|
||||
// Turn off play progress tracking (when paused or dragging)
|
||||
vjs.Player.prototype.stopTrackingCurrentTime = function(){ clearInterval(this.currentTimeInterval); };
|
||||
|
||||
// /* Player event handlers (how the player reacts to certain events)
|
||||
// ================================================================================ */
|
||||
vjs.Player.prototype.onEnded = function(){
|
||||
if (this.options['loop']) {
|
||||
this.currentTime(0);
|
||||
this.play();
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Player.prototype.onPlay = function(){
|
||||
vjs.removeClass(this.el_, 'vjs-paused');
|
||||
vjs.addClass(this.el_, 'vjs-playing');
|
||||
};
|
||||
|
||||
vjs.Player.prototype.onPause = function(){
|
||||
vjs.removeClass(this.el_, 'vjs-playing');
|
||||
vjs.addClass(this.el_, 'vjs-paused');
|
||||
};
|
||||
|
||||
vjs.Player.prototype.onProgress = function(){
|
||||
// Add custom event for when source is finished downloading.
|
||||
if (this.bufferedPercent() == 1) {
|
||||
this.trigger('loadedalldata');
|
||||
}
|
||||
};
|
||||
|
||||
// Update duration with durationchange event
|
||||
// Allows for cacheing value instead of asking player each time.
|
||||
vjs.Player.prototype.onDurationChange = function(){
|
||||
this.duration(this.techGet('duration'));
|
||||
};
|
||||
|
||||
vjs.Player.prototype.onError = function(e) {
|
||||
vjs.log('Video Error', e);
|
||||
};
|
||||
|
||||
// /* Player API
|
||||
// ================================================================================ */
|
||||
|
||||
/**
|
||||
* Object for cached values.
|
||||
* @private
|
||||
*/
|
||||
vjs.Player.prototype.cache_;
|
||||
|
||||
vjs.Player.prototype.getCache = function(){
|
||||
return this.cache_;
|
||||
};
|
||||
|
||||
// Pass values to the playback tech
|
||||
vjs.Player.prototype.techCall = function(method, arg){
|
||||
// If it's not ready yet, call method when it is
|
||||
if (!this.tech.isReady_) {
|
||||
this.tech.ready(function(){
|
||||
this[method](arg);
|
||||
});
|
||||
|
||||
// Otherwise call method now
|
||||
} else {
|
||||
try {
|
||||
this.tech[method](arg);
|
||||
} catch(e) {
|
||||
vjs.log(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Get calls can't wait for the tech, and sometimes don't need to.
|
||||
vjs.Player.prototype.techGet = function(method){
|
||||
|
||||
// Make sure tech is ready
|
||||
if (this.tech.isReady_) {
|
||||
|
||||
// Flash likes to die and reload when you hide or reposition it.
|
||||
// In these cases the object methods go away and we get errors.
|
||||
// When that happens we'll catch the errors and inform tech that it's not ready any more.
|
||||
try {
|
||||
return this.tech[method]();
|
||||
} catch(e) {
|
||||
|
||||
// When building additional tech libs, an expected method may not be defined yet
|
||||
if (this.tech[method] === undefined) {
|
||||
vjs.log('Video.js: ' + method + ' method not defined for '+this.techName+' playback technology.', e);
|
||||
|
||||
} else {
|
||||
|
||||
// When a method isn't available on the object it throws a TypeError
|
||||
if (e.name == 'TypeError') {
|
||||
vjs.log('Video.js: ' + method + ' unavailable on '+this.techName+' playback technology element.', e);
|
||||
this.tech.isReady_ = false;
|
||||
throw e;
|
||||
} else {
|
||||
vjs.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-play
|
||||
vjs.Player.prototype.play = function(){
|
||||
this.techCall('play');
|
||||
return this;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-pause
|
||||
vjs.Player.prototype.pause = function(){
|
||||
this.techCall('pause');
|
||||
return this;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-paused
|
||||
// The initial state of paused should be true (in Safari it's actually false)
|
||||
vjs.Player.prototype.paused = function(){
|
||||
return (this.techGet('paused') === false) ? false : true;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-currenttime
|
||||
vjs.Player.prototype.currentTime = function(seconds){
|
||||
if (seconds !== undefined) {
|
||||
|
||||
// Cache the last set value for smoother scrubbing.
|
||||
this.cache_.lastSetCurrentTime = seconds;
|
||||
|
||||
this.techCall('setCurrentTime', seconds);
|
||||
|
||||
// Improve the accuracy of manual timeupdates
|
||||
if (this.manualTimeUpdates) { this.trigger('timeupdate'); }
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// Cache last currentTime and return
|
||||
// Default to 0 seconds
|
||||
return this.cache_.currentTime = (this.techGet('currentTime') || 0);
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-duration
|
||||
// Duration should return NaN if not available. ParseFloat will turn false-ish values to NaN.
|
||||
vjs.Player.prototype.duration = function(seconds){
|
||||
if (seconds !== undefined) {
|
||||
|
||||
// Cache the last set value for optimiized scrubbing (esp. Flash)
|
||||
this.cache_.duration = parseFloat(seconds);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
return this.cache_.duration;
|
||||
};
|
||||
|
||||
// Calculates how much time is left. Not in spec, but useful.
|
||||
vjs.Player.prototype.remainingTime = function(){
|
||||
return this.duration() - this.currentTime();
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-buffered
|
||||
// Buffered returns a timerange object.
|
||||
// Kind of like an array of portions of the video that have been downloaded.
|
||||
// So far no browsers return more than one range (portion)
|
||||
vjs.Player.prototype.buffered = function(){
|
||||
var buffered = this.techGet('buffered'),
|
||||
start = 0,
|
||||
// Default end to 0 and store in values
|
||||
end = this.cache_.bufferEnd = this.cache_.bufferEnd || 0;
|
||||
|
||||
if (buffered && buffered.length > 0 && buffered.end(0) !== end) {
|
||||
end = buffered.end(0);
|
||||
// Storing values allows them be overridden by setBufferedFromProgress
|
||||
this.cache_.bufferEnd = end;
|
||||
}
|
||||
|
||||
return vjs.createTimeRange(start, end);
|
||||
};
|
||||
|
||||
// Calculates amount of buffer is full. Not in spec but useful.
|
||||
vjs.Player.prototype.bufferedPercent = function(){
|
||||
return (this.duration()) ? this.buffered().end(0) / this.duration() : 0;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-volume
|
||||
vjs.Player.prototype.volume = function(percentAsDecimal){
|
||||
var vol;
|
||||
|
||||
if (percentAsDecimal !== undefined) {
|
||||
vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal))); // Force value to between 0 and 1
|
||||
this.cache_.volume = vol;
|
||||
this.techCall('setVolume', vol);
|
||||
vjs.setLocalStorage('volume', vol);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Default to 1 when returning current volume.
|
||||
vol = parseFloat(this.techGet('volume'));
|
||||
return (isNaN(vol)) ? 1 : vol;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#attr-media-muted
|
||||
vjs.Player.prototype.muted = function(muted){
|
||||
if (muted !== undefined) {
|
||||
this.techCall('setMuted', muted);
|
||||
return this;
|
||||
}
|
||||
return this.techGet('muted') || false; // Default to false
|
||||
};
|
||||
|
||||
// Check if current tech can support native fullscreen (e.g. with built in controls lik iOS, so not our flash swf)
|
||||
vjs.Player.prototype.supportsFullScreen = function(){ return this.techGet('supportsFullScreen') || false; };
|
||||
|
||||
// Turn on fullscreen (or window) mode
|
||||
vjs.Player.prototype.requestFullScreen = function(){
|
||||
var requestFullScreen = vjs.support.requestFullScreen;
|
||||
|
||||
this.isFullScreen = true;
|
||||
|
||||
// Check for browser element fullscreen support
|
||||
if (requestFullScreen) {
|
||||
|
||||
// Trigger fullscreenchange event after change
|
||||
vjs.on(document, requestFullScreen.eventName, vjs.bind(this, function(){
|
||||
this.isFullScreen = document[requestFullScreen.isFullScreen];
|
||||
|
||||
// If cancelling fullscreen, remove event listener.
|
||||
if (this.isFullScreen === false) {
|
||||
vjs.off(document, requestFullScreen.eventName, arguments.callee);
|
||||
}
|
||||
|
||||
this.trigger('fullscreenchange');
|
||||
}));
|
||||
|
||||
// Flash and other plugins get reloaded when you take their parent to fullscreen.
|
||||
// To fix that we'll remove the tech, and reload it after the resize has finished.
|
||||
if (this.tech.features.fullscreenResize === false && this.options['flash']['iFrameMode'] !== true) {
|
||||
|
||||
this.pause();
|
||||
this.unloadTech();
|
||||
|
||||
vjs.on(document, requestFullScreen.eventName, vjs.bind(this, function(){
|
||||
vjs.off(document, requestFullScreen.eventName, arguments.callee);
|
||||
this.loadTech(this.techName, { src: this.cache_.src });
|
||||
}));
|
||||
|
||||
this.el_[requestFullScreen.requestFn]();
|
||||
|
||||
} else {
|
||||
this.el_[requestFullScreen.requestFn]();
|
||||
}
|
||||
|
||||
} else if (this.tech.supportsFullScreen()) {
|
||||
this.trigger('fullscreenchange');
|
||||
this.techCall('enterFullScreen');
|
||||
|
||||
} else {
|
||||
this.trigger('fullscreenchange');
|
||||
this.enterFullWindow();
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
vjs.Player.prototype.cancelFullScreen = function(){
|
||||
var requestFullScreen = vjs.support.requestFullScreen;
|
||||
|
||||
this.isFullScreen = false;
|
||||
|
||||
// Check for browser element fullscreen support
|
||||
if (requestFullScreen) {
|
||||
|
||||
// Flash and other plugins get reloaded when you take their parent to fullscreen.
|
||||
// To fix that we'll remove the tech, and reload it after the resize has finished.
|
||||
if (this.tech.features.fullscreenResize === false && this.options['flash']['iFrameMode'] !== true) {
|
||||
|
||||
this.pause();
|
||||
this.unloadTech();
|
||||
|
||||
vjs.on(document, requestFullScreen.eventName, vjs.bind(this, function(){
|
||||
vjs.off(document, requestFullScreen.eventName, arguments.callee);
|
||||
this.loadTech(this.techName, { src: this.cache_.src });
|
||||
}));
|
||||
|
||||
document[requestFullScreen.cancelFn]();
|
||||
|
||||
} else {
|
||||
document[requestFullScreen.cancelFn]();
|
||||
}
|
||||
|
||||
} else if (this.tech.supportsFullScreen()) {
|
||||
this.techCall('exitFullScreen');
|
||||
this.trigger('fullscreenchange');
|
||||
|
||||
} else {
|
||||
this.exitFullWindow();
|
||||
this.trigger('fullscreenchange');
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
// When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.
|
||||
vjs.Player.prototype.enterFullWindow = function(){
|
||||
this.isFullWindow = true;
|
||||
|
||||
// Storing original doc overflow value to return to when fullscreen is off
|
||||
this.docOrigOverflow = document.documentElement.style.overflow;
|
||||
|
||||
// Add listener for esc key to exit fullscreen
|
||||
vjs.on(document, 'keydown', vjs.bind(this, this.fullWindowOnEscKey));
|
||||
|
||||
// Hide any scroll bars
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
|
||||
// Apply fullscreen styles
|
||||
vjs.addClass(document.body, 'vjs-full-window');
|
||||
vjs.addClass(this.el_, 'vjs-fullscreen');
|
||||
|
||||
this.trigger('enterFullWindow');
|
||||
};
|
||||
vjs.Player.prototype.fullWindowOnEscKey = function(event){
|
||||
if (event.keyCode === 27) {
|
||||
if (this.isFullScreen === true) {
|
||||
this.cancelFullScreen();
|
||||
} else {
|
||||
this.exitFullWindow();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
vjs.Player.prototype.exitFullWindow = function(){
|
||||
this.isFullWindow = false;
|
||||
vjs.off(document, 'keydown', this.fullWindowOnEscKey);
|
||||
|
||||
// Unhide scroll bars.
|
||||
document.documentElement.style.overflow = this.docOrigOverflow;
|
||||
|
||||
// Remove fullscreen styles
|
||||
vjs.removeClass(document.body, 'vjs-full-window');
|
||||
vjs.removeClass(this.el_, 'vjs-fullscreen');
|
||||
|
||||
// Resize the box, controller, and poster to original sizes
|
||||
// this.positionAll();
|
||||
this.trigger('exitFullWindow');
|
||||
};
|
||||
|
||||
vjs.Player.prototype.selectSource = function(sources){
|
||||
|
||||
// Loop through each playback technology in the options order
|
||||
for (var i=0,j=this.options['techOrder'];i<j.length;i++) {
|
||||
var techName = vjs.capitalize(j[i]),
|
||||
tech = window['videojs'][techName];
|
||||
|
||||
// Check if the browser supports this technology
|
||||
if (tech.isSupported()) {
|
||||
// Loop through each source object
|
||||
for (var a=0,b=sources;a<b.length;a++) {
|
||||
var source = b[a];
|
||||
|
||||
// Check if source can be played with this technology
|
||||
if (tech['canPlaySource'](source)) {
|
||||
return { source: source, tech: techName };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// src is a pretty powerful function
|
||||
// If you pass it an array of source objects, it will find the best source to play and use that object.src
|
||||
// If the new source requires a new playback technology, it will switch to that.
|
||||
// If you pass it an object, it will set the source to object.src
|
||||
// If you pass it anything else (url string) it will set the video source to that
|
||||
vjs.Player.prototype.src = function(source){
|
||||
// Case: Array of source objects to choose from and pick the best to play
|
||||
if (source instanceof Array) {
|
||||
|
||||
var sourceTech = this.selectSource(source),
|
||||
techName;
|
||||
|
||||
if (sourceTech) {
|
||||
source = sourceTech.source;
|
||||
techName = sourceTech.tech;
|
||||
|
||||
// If this technology is already loaded, set source
|
||||
if (techName == this.techName) {
|
||||
this.src(source); // Passing the source object
|
||||
// Otherwise load this technology with chosen source
|
||||
} else {
|
||||
this.loadTech(techName, source);
|
||||
}
|
||||
} else {
|
||||
this.el_.appendChild(vjs.createEl('p', {
|
||||
innerHTML: 'Sorry, no compatible source and playback technology were found for this video. Try using another browser like <a href="http://www.google.com/chrome">Google Chrome</a> or download the latest <a href="http://get.adobe.com/flashplayer/">Adobe Flash Player</a>.'
|
||||
}));
|
||||
}
|
||||
|
||||
// Case: Source object { src: '', type: '' ... }
|
||||
} else if (source instanceof Object) {
|
||||
|
||||
if (window['videojs'][this.techName]['canPlaySource'](source)) {
|
||||
this.src(source.src);
|
||||
} else {
|
||||
// Send through tech loop to check for a compatible technology.
|
||||
this.src([source]);
|
||||
}
|
||||
|
||||
// Case: URL String (http://myvideo...)
|
||||
} else {
|
||||
// Cache for getting last set source
|
||||
this.cache_.src = source;
|
||||
|
||||
if (!this.isReady_) {
|
||||
this.ready(function(){
|
||||
this.src(source);
|
||||
});
|
||||
} else {
|
||||
this.techCall('src', source);
|
||||
if (this.options['preload'] == 'auto') {
|
||||
this.load();
|
||||
}
|
||||
if (this.options['autoplay']) {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
// Begin loading the src data
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-load
|
||||
vjs.Player.prototype.load = function(){
|
||||
this.techCall('load');
|
||||
return this;
|
||||
};
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-currentsrc
|
||||
vjs.Player.prototype.currentSrc = function(){
|
||||
return this.techGet('currentSrc') || this.cache_.src || '';
|
||||
};
|
||||
|
||||
// Attributes/Options
|
||||
vjs.Player.prototype.preload = function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall('setPreload', value);
|
||||
this.options['preload'] = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet('preload');
|
||||
};
|
||||
vjs.Player.prototype.autoplay = function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall('setAutoplay', value);
|
||||
this.options['autoplay'] = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet('autoplay', value);
|
||||
};
|
||||
vjs.Player.prototype.loop = function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall('setLoop', value);
|
||||
this.options['loop'] = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet('loop');
|
||||
};
|
||||
|
||||
vjs.Player.prototype.controls = function(){ return this.options['controls']; };
|
||||
vjs.Player.prototype.poster = function(){ return this.techGet('poster'); };
|
||||
vjs.Player.prototype.error = function(){ return this.techGet('error'); };
|
||||
vjs.Player.prototype.ended = function(){ return this.techGet('ended'); };
|
||||
|
||||
// Methods to add support for
|
||||
// networkState: function(){ return this.techCall('networkState'); },
|
||||
// readyState: function(){ return this.techCall('readyState'); },
|
||||
// seeking: function(){ return this.techCall('seeking'); },
|
||||
// initialTime: function(){ return this.techCall('initialTime'); },
|
||||
// startOffsetTime: function(){ return this.techCall('startOffsetTime'); },
|
||||
// played: function(){ return this.techCall('played'); },
|
||||
// seekable: function(){ return this.techCall('seekable'); },
|
||||
// videoTracks: function(){ return this.techCall('videoTracks'); },
|
||||
// audioTracks: function(){ return this.techCall('audioTracks'); },
|
||||
// videoWidth: function(){ return this.techCall('videoWidth'); },
|
||||
// videoHeight: function(){ return this.techCall('videoHeight'); },
|
||||
// defaultPlaybackRate: function(){ return this.techCall('defaultPlaybackRate'); },
|
||||
// playbackRate: function(){ return this.techCall('playbackRate'); },
|
||||
// mediaGroup: function(){ return this.techCall('mediaGroup'); },
|
||||
// controller: function(){ return this.techCall('controller'); },
|
||||
// defaultMuted: function(){ return this.techCall('defaultMuted'); }
|
||||
|
||||
// TODO
|
||||
// currentSrcList: the array of sources including other formats and bitrates
|
||||
// playList: array of source lists in order of playback
|
||||
|
||||
// RequestFullscreen API
|
||||
(function(){
|
||||
var requestFn, cancelFn, eventName, isFullScreen;
|
||||
|
||||
// Current W3C Spec
|
||||
// http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api
|
||||
// Mozilla Draft: https://wiki.mozilla.org/Gecko:FullScreenAPI#fullscreenchange_event
|
||||
if (document.cancelFullscreen !== undefined) {
|
||||
requestFn = 'requestFullscreen';
|
||||
cancelFn = 'exitFullscreen';
|
||||
eventName = 'fullscreenchange';
|
||||
isFullScreen = 'fullScreen';
|
||||
|
||||
// Webkit (Chrome/Safari) and Mozilla (Firefox) have working implementaitons
|
||||
// that use prefixes and vary slightly from the new W3C spec. Specifically, using 'exit' instead of 'cancel',
|
||||
// and lowercasing the 'S' in Fullscreen.
|
||||
// Other browsers don't have any hints of which version they might follow yet, so not going to try to predict by loopeing through all prefixes.
|
||||
} else {
|
||||
|
||||
var prefixes = ['moz', 'webkit'];
|
||||
|
||||
for (var i = prefixes.length - 1; i >= 0; i--) {
|
||||
var prefix = prefixes[i];
|
||||
|
||||
// https://github.com/zencoder/video-js/pull/128
|
||||
if ((prefix != 'moz' || document.mozFullScreenEnabled) && document[prefix + 'CancelFullScreen'] !== undefined) {
|
||||
requestFn = prefix + 'RequestFullScreen';
|
||||
cancelFn = prefix + 'CancelFullScreen';
|
||||
eventName = prefix + 'fullscreenchange';
|
||||
|
||||
if (prefix == 'webkit') {
|
||||
isFullScreen = prefix + 'IsFullScreen';
|
||||
} else {
|
||||
isFullScreen = prefix + 'FullScreen';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (requestFn) {
|
||||
vjs.support.requestFullScreen = {
|
||||
requestFn: requestFn,
|
||||
cancelFn: cancelFn,
|
||||
eventName: eventName,
|
||||
isFullScreen: isFullScreen
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
vjs.MediaLoader = function(player, options, ready){
|
||||
vjs.Component.call(this, player, options, ready);
|
||||
|
||||
// If there are no sources when the player is initialized,
|
||||
// load the first supported playback technology.
|
||||
if (!player.options['sources'] || player.options['sources'].length === 0) {
|
||||
for (var i=0,j=player.options['techOrder']; i<j.length; i++) {
|
||||
var techName = vjs.capitalize(j[i]),
|
||||
tech = window['videojs'][techName];
|
||||
|
||||
// Check if the browser supports this technology
|
||||
if (tech && tech.isSupported()) {
|
||||
player.loadTech(techName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// // Loop through playback technologies (HTML5, Flash) and check for support.
|
||||
// // Then load the best source.
|
||||
// // A few assumptions here:
|
||||
// // All playback technologies respect preload false.
|
||||
player.src(player.options['sources']);
|
||||
}
|
||||
};
|
||||
goog.inherits(vjs.MediaLoader, vjs.Component);
|
||||
|
||||
|
@ -1,7 +1,17 @@
|
||||
/**
|
||||
* @fileoverview Functions for automatically setting up a player
|
||||
* based on the data-setup attribute of the video tag
|
||||
*/
|
||||
|
||||
goog.provide('vjs.autoSetup');
|
||||
|
||||
goog.require('vjs.JSON');
|
||||
goog.require('vjs.events');
|
||||
|
||||
// Automatically set up any tags that have a data-setup attribute
|
||||
_V_.autoSetup = function(){
|
||||
vjs.autoSetup = function(){
|
||||
var options, vid, player,
|
||||
vids = document.getElementsByTagName("video");
|
||||
vids = document.getElementsByTagName('video');
|
||||
|
||||
// Check if any media elements exist
|
||||
if (vids && vids.length > 0) {
|
||||
@ -10,47 +20,47 @@ _V_.autoSetup = function(){
|
||||
vid = vids[i];
|
||||
|
||||
// Check if element exists, has getAttribute func.
|
||||
// IE seems to consider typeof el.getAttribute == "object" instead of "function" like expected, at least when loading the player immediately.
|
||||
// IE seems to consider typeof el.getAttribute == 'object' instead of 'function' like expected, at least when loading the player immediately.
|
||||
if (vid && vid.getAttribute) {
|
||||
|
||||
// Make sure this player hasn't already been set up.
|
||||
if (vid.player === undefined) {
|
||||
options = vid.getAttribute("data-setup");
|
||||
options = vid.getAttribute('data-setup');
|
||||
|
||||
// Check if data-setup attr exists.
|
||||
// Check if data-setup attr exists.
|
||||
// We only auto-setup if they've added the data-setup attr.
|
||||
if (options !== null) {
|
||||
|
||||
// Parse options JSON
|
||||
// If empty string, make it a parsable json object.
|
||||
options = JSON.parse(options || "{}");
|
||||
options = vjs.JSON.parse(options || '{}');
|
||||
|
||||
// Create new video.js instance.
|
||||
player = _V_(vid, options);
|
||||
player = videojs(vid, options);
|
||||
}
|
||||
}
|
||||
|
||||
// If getAttribute isn't defined, we need to wait for the DOM.
|
||||
} else {
|
||||
_V_.autoSetupTimeout(1);
|
||||
vjs.autoSetupTimeout(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// No videos were found, so keep looping unless page is finisehd loading.
|
||||
} else if (!_V_.windowLoaded) {
|
||||
_V_.autoSetupTimeout(1);
|
||||
} else if (!vjs.windowLoaded) {
|
||||
vjs.autoSetupTimeout(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Pause to let the DOM keep processing
|
||||
_V_.autoSetupTimeout = function(wait){
|
||||
setTimeout(_V_.autoSetup, wait);
|
||||
vjs.autoSetupTimeout = function(wait){
|
||||
setTimeout(vjs.autoSetup, wait);
|
||||
};
|
||||
|
||||
_V_.addEvent(window, "load", function(){
|
||||
_V_.windowLoaded = true;
|
||||
vjs.one(window, 'load', function(){
|
||||
vjs.windowLoaded = true;
|
||||
});
|
||||
|
||||
// Run Auto-load players
|
||||
_V_.autoSetup();
|
||||
vjs.autoSetup();
|
1025
src/js/tracks.js
Normal file
1025
src/js/tracks.js
Normal file
File diff suppressed because it is too large
Load Diff
54
src/json.js
54
src/json.js
@ -1,54 +0,0 @@
|
||||
// Javascript JSON implementation
|
||||
// (Parse Method Only)
|
||||
// https://github.com/douglascrockford/JSON-js/blob/master/json2.js
|
||||
|
||||
var JSON;
|
||||
if (!JSON) { JSON = {}; }
|
||||
|
||||
(function(){
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
text = String(text);
|
||||
cx.lastIndex = 0;
|
||||
if (cx.test(text)) {
|
||||
text = text.replace(cx, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
if (/^[\],:{}\s]*$/
|
||||
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
return typeof reviver === 'function' ?
|
||||
walk({'': j}, '') : j;
|
||||
}
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
346
src/lib.js
346
src/lib.js
@ -1,346 +0,0 @@
|
||||
_V_.merge = function(obj1, obj2, safe){
|
||||
// Make sure second object exists
|
||||
if (!obj2) { obj2 = {}; };
|
||||
|
||||
for (var attrname in obj2){
|
||||
if (obj2.hasOwnProperty(attrname) && (!safe || !obj1.hasOwnProperty(attrname))) { obj1[attrname]=obj2[attrname]; }
|
||||
}
|
||||
return obj1;
|
||||
};
|
||||
_V_.extend = function(obj){ this.merge(this, obj, true); };
|
||||
|
||||
_V_.extend({
|
||||
tech: {}, // Holder for playback technology settings
|
||||
controlSets: {}, // Holder for control set definitions
|
||||
|
||||
// Device Checks
|
||||
isIE: function(){ return !+"\v1"; },
|
||||
isFF: function(){ return !!_V_.ua.match("Firefox") },
|
||||
isIPad: function(){ return navigator.userAgent.match(/iPad/i) !== null; },
|
||||
isIPhone: function(){ return navigator.userAgent.match(/iPhone/i) !== null; },
|
||||
isIOS: function(){ return VideoJS.isIPhone() || VideoJS.isIPad(); },
|
||||
iOSVersion: function() {
|
||||
var match = navigator.userAgent.match(/OS (\d+)_/i);
|
||||
if (match && match[1]) { return match[1]; }
|
||||
},
|
||||
isAndroid: function(){ return navigator.userAgent.match(/Android.*AppleWebKit/i) !== null; },
|
||||
androidVersion: function() {
|
||||
var match = navigator.userAgent.match(/Android (\d+)\./i);
|
||||
if (match && match[1]) { return match[1]; }
|
||||
},
|
||||
|
||||
testVid: document.createElement("video"),
|
||||
ua: navigator.userAgent,
|
||||
support: {},
|
||||
|
||||
each: function(arr, fn){
|
||||
if (!arr || arr.length === 0) { return; }
|
||||
for (var i=0,j=arr.length; i<j; i++) {
|
||||
fn.call(this, arr[i], i);
|
||||
}
|
||||
},
|
||||
|
||||
eachProp: function(obj, fn){
|
||||
if (!obj) { return; }
|
||||
for (var name in obj) {
|
||||
if (obj.hasOwnProperty(name)) {
|
||||
fn.call(this, name, obj[name]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
el: function(id){ return document.getElementById(id); },
|
||||
createElement: function(tagName, attributes){
|
||||
var el = document.createElement(tagName),
|
||||
attrname;
|
||||
for (attrname in attributes){
|
||||
if (attributes.hasOwnProperty(attrname)) {
|
||||
if (attrname.indexOf("-") !== -1) {
|
||||
el.setAttribute(attrname, attributes[attrname]);
|
||||
} else {
|
||||
el[attrname] = attributes[attrname];
|
||||
}
|
||||
}
|
||||
}
|
||||
return el;
|
||||
},
|
||||
|
||||
insertFirst: function(node, parent){
|
||||
if (parent.firstChild) {
|
||||
parent.insertBefore(node, parent.firstChild);
|
||||
} else {
|
||||
parent.appendChild(node);
|
||||
}
|
||||
},
|
||||
|
||||
addClass: function(element, classToAdd){
|
||||
if ((" "+element.className+" ").indexOf(" "+classToAdd+" ") == -1) {
|
||||
element.className = element.className === "" ? classToAdd : element.className + " " + classToAdd;
|
||||
}
|
||||
},
|
||||
|
||||
removeClass: function(element, classToRemove){
|
||||
if (element.className.indexOf(classToRemove) == -1) { return; }
|
||||
var classNames = element.className.split(" ");
|
||||
classNames.splice(classNames.indexOf(classToRemove),1);
|
||||
element.className = classNames.join(" ");
|
||||
},
|
||||
|
||||
// Attempt to block the ability to select text while dragging controls
|
||||
blockTextSelection: function(){
|
||||
document.body.focus();
|
||||
document.onselectstart = function () { return false; };
|
||||
},
|
||||
// Turn off text selection blocking
|
||||
unblockTextSelection: function(){ document.onselectstart = function () { return true; }; },
|
||||
|
||||
// Return seconds as H:MM:SS or M:SS
|
||||
// Supplying a guide (in seconds) will include enough leading zeros to cover the length of the guide
|
||||
formatTime: function(seconds, guide) {
|
||||
guide = guide || seconds; // Default to using seconds as guide
|
||||
var s = Math.floor(seconds % 60),
|
||||
m = Math.floor(seconds / 60 % 60),
|
||||
h = Math.floor(seconds / 3600),
|
||||
gm = Math.floor(guide / 60 % 60),
|
||||
gh = Math.floor(guide / 3600);
|
||||
|
||||
// Check if we need to show hours
|
||||
h = (h > 0 || gh > 0) ? h + ":" : "";
|
||||
|
||||
// If hours are showing, we may need to add a leading zero.
|
||||
// Always show at least one digit of minutes.
|
||||
m = (((h || gm >= 10) && m < 10) ? "0" + m : m) + ":";
|
||||
|
||||
// Check if leading zero is need for seconds
|
||||
s = (s < 10) ? "0" + s : s;
|
||||
|
||||
return h + m + s;
|
||||
},
|
||||
|
||||
uc: function(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
},
|
||||
|
||||
// Return the relative horizonal position of an event as a value from 0-1
|
||||
getRelativePosition: function(x, relativeElement){
|
||||
return Math.max(0, Math.min(1, (x - _V_.findPosX(relativeElement)) / relativeElement.offsetWidth));
|
||||
},
|
||||
|
||||
getComputedStyleValue: function(element, style){
|
||||
return window.getComputedStyle(element, null).getPropertyValue(style);
|
||||
},
|
||||
|
||||
trim: function(string){ return string.toString().replace(/^\s+/, "").replace(/\s+$/, ""); },
|
||||
round: function(num, dec) {
|
||||
if (!dec) { dec = 0; }
|
||||
return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
|
||||
},
|
||||
|
||||
isEmpty: function(object) {
|
||||
for (var prop in object) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
// Mimic HTML5 TimeRange Spec.
|
||||
createTimeRange: function(start, end){
|
||||
return {
|
||||
length: 1,
|
||||
start: function() { return start; },
|
||||
end: function() { return end; }
|
||||
};
|
||||
},
|
||||
|
||||
/* Element Data Store. Allows for binding data to an element without putting it directly on the element.
|
||||
Ex. Event listneres are stored here.
|
||||
(also from jsninja.com)
|
||||
================================================================================ */
|
||||
cache: {}, // Where the data is stored
|
||||
guid: 1, // Unique ID for the element
|
||||
expando: "vdata" + (new Date).getTime(), // Unique attribute to store element's guid in
|
||||
|
||||
// Returns the cache object where data for the element is stored
|
||||
getData: function(elem){
|
||||
var id = elem[_V_.expando];
|
||||
if (!id) {
|
||||
id = elem[_V_.expando] = _V_.guid++;
|
||||
_V_.cache[id] = {};
|
||||
}
|
||||
return _V_.cache[id];
|
||||
},
|
||||
// Delete data for the element from the cache and the guid attr from element
|
||||
removeData: function(elem){
|
||||
var id = elem[_V_.expando];
|
||||
if (!id) { return; }
|
||||
// Remove all stored data
|
||||
delete _V_.cache[id];
|
||||
// Remove the expando property from the DOM node
|
||||
try {
|
||||
delete elem[_V_.expando];
|
||||
} catch(e) {
|
||||
if (elem.removeAttribute) {
|
||||
elem.removeAttribute(_V_.expando);
|
||||
} else {
|
||||
// IE doesn't appear to support removeAttribute on the document element
|
||||
elem[_V_.expando] = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/* Proxy (a.k.a Bind or Context). A simple method for changing the context of a function
|
||||
It also stores a unique id on the function so it can be easily removed from events
|
||||
================================================================================ */
|
||||
proxy: function(context, fn, uid) {
|
||||
// Make sure the function has a unique ID
|
||||
if (!fn.guid) { fn.guid = _V_.guid++; }
|
||||
|
||||
// Create the new function that changes the context
|
||||
var ret = function() {
|
||||
return fn.apply(context, arguments);
|
||||
}
|
||||
|
||||
// Allow for the ability to individualize this function
|
||||
// Needed in the case where multiple objects might share the same prototype
|
||||
// IF both items add an event listener with the same function, then you try to remove just one
|
||||
// it will remove both because they both have the same guid.
|
||||
// when using this, you need to use the proxy method when you remove the listener as well.
|
||||
ret.guid = (uid) ? uid + "_" + fn.guid : fn.guid;
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
get: function(url, onSuccess, onError){
|
||||
// if (netscape.security.PrivilegeManager.enablePrivilege) {
|
||||
// netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
|
||||
// }
|
||||
|
||||
var local = (url.indexOf("file:") == 0 || (window.location.href.indexOf("file:") == 0 && url.indexOf("http:") == -1));
|
||||
|
||||
if (typeof XMLHttpRequest == "undefined") {
|
||||
XMLHttpRequest = function () {
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (f) {}
|
||||
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (g) {}
|
||||
throw new Error("This browser does not support XMLHttpRequest.");
|
||||
};
|
||||
}
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
|
||||
try {
|
||||
request.open("GET", url);
|
||||
} catch(e) {
|
||||
_V_.log("VideoJS XMLHttpRequest (open)", e);
|
||||
// onError(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
request.onreadystatechange = _V_.proxy(this, function() {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200 || local && request.status == 0) {
|
||||
onSuccess(request.responseText);
|
||||
} else {
|
||||
if (onError) {
|
||||
onError();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
request.send();
|
||||
} catch(e) {
|
||||
_V_.log("VideoJS XMLHttpRequest (send)", e);
|
||||
if (onError) {
|
||||
onError(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/* Local Storage
|
||||
================================================================================ */
|
||||
setLocalStorage: function(key, value){
|
||||
// IE was throwing errors referencing the var anywhere without this
|
||||
var localStorage = window.localStorage || false;
|
||||
if (!localStorage) { return; }
|
||||
try {
|
||||
localStorage[key] = value;
|
||||
} catch(e) {
|
||||
if (e.code == 22 || e.code == 1014) { // Webkit == 22 / Firefox == 1014
|
||||
_V_.log("LocalStorage Full (VideoJS)", e);
|
||||
} else {
|
||||
_V_.log("LocalStorage Error (VideoJS)", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Get abosolute version of relative URL. Used to tell flash correct URL.
|
||||
// http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
|
||||
getAbsoluteURL: function(url){
|
||||
|
||||
// Check if absolute URL
|
||||
if (!url.match(/^https?:\/\//)) {
|
||||
// Convert to absolute URL. Flash hosted off-site needs an absolute URL.
|
||||
url = _V_.createElement('div', {
|
||||
innerHTML: '<a href="'+url+'">x</a>'
|
||||
}).firstChild.href;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// usage: log('inside coolFunc', this, arguments);
|
||||
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
|
||||
_V_.log = function(){
|
||||
_V_.log.history = _V_.log.history || [];// store logs to an array for reference
|
||||
_V_.log.history.push(arguments);
|
||||
if(window.console) {
|
||||
arguments.callee = arguments.callee.caller;
|
||||
var newarr = [].slice.call(arguments);
|
||||
(typeof console.log === 'object' ? _V_.log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
|
||||
}
|
||||
};
|
||||
|
||||
// make it safe to use console.log always
|
||||
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
|
||||
{console.log();return window.console;}catch(err){return window.console={};}})());
|
||||
|
||||
// Offset Left
|
||||
// getBoundingClientRect technique from John Resig http://ejohn.org/blog/getboundingclientrect-is-awesome/
|
||||
if ("getBoundingClientRect" in document.documentElement) {
|
||||
_V_.findPosX = function(el) {
|
||||
var box;
|
||||
|
||||
try {
|
||||
box = el.getBoundingClientRect();
|
||||
} catch(e) {}
|
||||
|
||||
if (!box) { return 0; }
|
||||
|
||||
var docEl = document.documentElement,
|
||||
body = document.body,
|
||||
clientLeft = docEl.clientLeft || body.clientLeft || 0,
|
||||
scrollLeft = window.pageXOffset || body.scrollLeft,
|
||||
left = box.left + scrollLeft - clientLeft;
|
||||
|
||||
return left;
|
||||
};
|
||||
} else {
|
||||
_V_.findPosX = function(el) {
|
||||
var curleft = el.offsetLeft;
|
||||
// _V_.log(obj.className, obj.offsetLeft)
|
||||
while(el = obj.offsetParent) {
|
||||
if (el.className.indexOf("video-js") == -1) {
|
||||
// _V_.log(el.offsetParent, "OFFSETLEFT", el.offsetLeft)
|
||||
// _V_.log("-webkit-full-screen", el.webkitMatchesSelector("-webkit-full-screen"));
|
||||
// _V_.log("-webkit-full-screen", el.querySelectorAll(".video-js:-webkit-full-screen"));
|
||||
} else {
|
||||
}
|
||||
curleft += el.offsetLeft;
|
||||
}
|
||||
return curleft;
|
||||
};
|
||||
}
|
927
src/player.js
927
src/player.js
@ -1,927 +0,0 @@
|
||||
/* UI Component- Base class for all UI objects
|
||||
================================================================================ */
|
||||
_V_.Player = _V_.Component.extend({
|
||||
|
||||
init: function(tag, addOptions, ready){
|
||||
|
||||
this.tag = tag; // Store the original tag used to set options
|
||||
|
||||
var el = this.el = _V_.createElement("div"), // Div to contain video and controls
|
||||
options = this.options = {};
|
||||
|
||||
// Set Options
|
||||
_V_.merge(options, _V_.options); // Copy Global Defaults
|
||||
_V_.merge(options, this.getVideoTagSettings()); // Override with Video Tag Options
|
||||
_V_.merge(options, addOptions); // Override/extend with options from setup call
|
||||
|
||||
// Cache for video property values.
|
||||
this.values = {};
|
||||
|
||||
// Store controls setting, and then remove immediately so native controls don't flash.
|
||||
tag.removeAttribute("controls");
|
||||
|
||||
// Poster will be handled by a manual <img>
|
||||
tag.removeAttribute("poster");
|
||||
|
||||
// Make player findable on elements
|
||||
tag.player = el.player = this;
|
||||
|
||||
// Make sure tag ID exists
|
||||
tag.id = tag.id || "vjs_video_" + _V_.guid++;
|
||||
|
||||
// Give video tag properties to box
|
||||
// ID will now reference box, not the video tag
|
||||
this.id = el.id = tag.id;
|
||||
el.className = tag.className;
|
||||
|
||||
// Make player easily findable by ID
|
||||
_V_.players[el.id] = this;
|
||||
|
||||
// Make box use width/height of tag, or default 300x150
|
||||
// Enforce with CSS since width/height attrs don't work on divs
|
||||
this.width(options.width, true); // (true) Skip resize listener on load
|
||||
this.height(options.height, true);
|
||||
|
||||
// Update tag id/class for use as HTML5 playback tech
|
||||
// Might think we should do this after embedding in container so .vjs-tech class
|
||||
// doesn't flash 100% width/height, but class only applies with .video-js parent
|
||||
tag.id += "_html5_api";
|
||||
tag.className = "vjs-tech";
|
||||
|
||||
// Remove width/height attrs from tag so CSS can make it 100% width/height
|
||||
tag.removeAttribute("width");
|
||||
tag.removeAttribute("height");
|
||||
|
||||
// Wrap video tag in div (el/box) container
|
||||
tag.parentNode.insertBefore(el, tag);
|
||||
el.appendChild(tag); // Breaks iPhone, fixed in HTML5 setup.
|
||||
|
||||
// Empty video tag sources and tracks so the built-in player doesn't use them also.
|
||||
if (tag.hasChildNodes()) {
|
||||
var nrOfChildNodes = tag.childNodes.length;
|
||||
for (var i=0,j=tag.childNodes;i<nrOfChildNodes;i++) {
|
||||
if (j[0].nodeName.toLowerCase() == "source" || j[0].nodeName.toLowerCase() == "track") {
|
||||
tag.removeChild(j[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.addClass("vjs-paused");
|
||||
|
||||
this.on("ended", this.onEnded);
|
||||
this.on("play", this.onPlay);
|
||||
this.on("pause", this.onPause);
|
||||
this.on("progress", this.onProgress);
|
||||
this.on("durationchange", this.onDurationChange);
|
||||
this.on("error", this.onError);
|
||||
|
||||
// When the API is ready, loop through the components and add to the player.
|
||||
if (options.controls) {
|
||||
this.ready(function(){
|
||||
this.initComponents();
|
||||
});
|
||||
}
|
||||
|
||||
// Add callback to ready queue
|
||||
this.ready(ready);
|
||||
|
||||
// Tracks defined in tracks.js
|
||||
this.textTracks = [];
|
||||
if (options.tracks && options.tracks.length > 0) {
|
||||
this.addTextTracks(options.tracks);
|
||||
}
|
||||
|
||||
// If there are no sources when the player is initialized,
|
||||
// load the first supported playback technology.
|
||||
if (!options.sources || options.sources.length == 0) {
|
||||
for (var i=0,j=options.techOrder; i<j.length; i++) {
|
||||
var techName = j[i],
|
||||
tech = _V_[techName];
|
||||
|
||||
// Check if the browser supports this technology
|
||||
if (tech.isSupported()) {
|
||||
this.loadTech(techName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Loop through playback technologies (HTML5, Flash) and check for support. Then load the best source.
|
||||
// A few assumptions here:
|
||||
// All playback technologies respect preload false.
|
||||
this.src(options.sources);
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function(){
|
||||
// Ensure that tracking progress and time progress will stop and plater deleted
|
||||
this.stopTrackingProgress();
|
||||
this.stopTrackingCurrentTime();
|
||||
_V_.players[this.id] = null;
|
||||
delete _V_.players[this.id];
|
||||
this.tech.destroy();
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
},
|
||||
|
||||
createElement: function(type, options){},
|
||||
|
||||
getVideoTagSettings: function(){
|
||||
var options = {
|
||||
sources: [],
|
||||
tracks: []
|
||||
},
|
||||
tag = this.tag,
|
||||
getAttribute = "getAttribute"; // For better minification
|
||||
|
||||
options.src = tag[getAttribute]("src");
|
||||
options.controls = tag[getAttribute]("controls") !== null;
|
||||
options.poster = tag[getAttribute]("poster");
|
||||
options.preload = tag[getAttribute]("preload");
|
||||
options.autoplay = tag[getAttribute]("autoplay") !== null; // hasAttribute not IE <8 compatible
|
||||
options.loop = tag[getAttribute]("loop") !== null;
|
||||
options.muted = tag[getAttribute]("muted") !== null;
|
||||
|
||||
options.width = tag[getAttribute]("width");
|
||||
options.height = tag[getAttribute]("height");
|
||||
|
||||
if (this.tag.hasChildNodes()) {
|
||||
for (var c,i=0,j=this.tag.childNodes;i<j.length;i++) {
|
||||
c = j[i];
|
||||
if (c.nodeName.toLowerCase() == "source") {
|
||||
options.sources.push({
|
||||
src: c[getAttribute]('src'),
|
||||
type: c[getAttribute]('type'),
|
||||
media: c[getAttribute]('media'),
|
||||
title: c[getAttribute]('title')
|
||||
});
|
||||
}
|
||||
if (c.nodeName.toLowerCase() == "track") {
|
||||
options.tracks.push({
|
||||
src: c[getAttribute]("src"),
|
||||
kind: c[getAttribute]("kind"),
|
||||
srclang: c[getAttribute]("srclang"),
|
||||
label: c[getAttribute]("label"),
|
||||
'default': c[getAttribute]("default") !== null,
|
||||
title: c[getAttribute]("title")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return options;
|
||||
},
|
||||
|
||||
/* PLayback Technology (tech)
|
||||
================================================================================ */
|
||||
// Load/Create an instance of playback technlogy including element and API methods
|
||||
// And append playback element in player div.
|
||||
loadTech: function(techName, source){
|
||||
|
||||
// Pause and remove current playback technology
|
||||
if (this.tech) {
|
||||
this.unloadTech();
|
||||
|
||||
// If the first time loading, HTML5 tag will exist but won't be initialized
|
||||
// So we need to remove it if we're not loading HTML5
|
||||
} else if (techName != "html5" && this.tag) {
|
||||
this.el.removeChild(this.tag);
|
||||
this.tag = false;
|
||||
}
|
||||
|
||||
this.techName = techName;
|
||||
|
||||
// Turn off API access because we're loading a new tech that might load asynchronously
|
||||
this.isReady = false;
|
||||
|
||||
var techReady = function(){
|
||||
this.player.triggerReady();
|
||||
|
||||
// Manually track progress in cases where the browser/flash player doesn't report it.
|
||||
if (!this.support.progressEvent) {
|
||||
this.player.manualProgressOn();
|
||||
}
|
||||
|
||||
// Manually track timeudpates in cases where the browser/flash player doesn't report it.
|
||||
if (!this.support.timeupdateEvent) {
|
||||
this.player.manualTimeUpdatesOn();
|
||||
}
|
||||
}
|
||||
|
||||
// Grab tech-specific options from player options and add source and parent element to use.
|
||||
var techOptions = _V_.merge({ source: source, parentEl: this.el }, this.options[techName])
|
||||
|
||||
if (source) {
|
||||
if (source.src == this.values.src && this.values.currentTime > 0) {
|
||||
techOptions.startTime = this.values.currentTime;
|
||||
}
|
||||
|
||||
this.values.src = source.src;
|
||||
}
|
||||
|
||||
// Initialize tech instance
|
||||
this.tech = new _V_[techName](this, techOptions);
|
||||
this.tech.ready(techReady);
|
||||
},
|
||||
|
||||
unloadTech: function(){
|
||||
this.tech.destroy();
|
||||
|
||||
// Turn off any manual progress or timeupdate tracking
|
||||
if (this.manualProgress) { this.manualProgressOff(); }
|
||||
|
||||
if (this.manualTimeUpdates) { this.manualTimeUpdatesOff(); }
|
||||
|
||||
this.tech = false;
|
||||
},
|
||||
|
||||
// There's many issues around changing the size of a Flash (or other plugin) object.
|
||||
// First is a plugin reload issue in Firefox that has been around for 11 years: https://bugzilla.mozilla.org/show_bug.cgi?id=90268
|
||||
// Then with the new fullscreen API, Mozilla and webkit browsers will reload the flash object after going to fullscreen.
|
||||
// To get around this, we're unloading the tech, caching source and currentTime values, and reloading the tech once the plugin is resized.
|
||||
// reloadTech: function(betweenFn){
|
||||
// _V_.log("unloadingTech")
|
||||
// this.unloadTech();
|
||||
// _V_.log("unloadedTech")
|
||||
// if (betweenFn) { betweenFn.call(); }
|
||||
// _V_.log("LoadingTech")
|
||||
// this.loadTech(this.techName, { src: this.values.src })
|
||||
// _V_.log("loadedTech")
|
||||
// },
|
||||
|
||||
/* Fallbacks for unsupported event types
|
||||
================================================================================ */
|
||||
// Manually trigger progress events based on changes to the buffered amount
|
||||
// Many flash players and older HTML5 browsers don't send progress or progress-like events
|
||||
manualProgressOn: function(){
|
||||
this.manualProgress = true;
|
||||
|
||||
// Trigger progress watching when a source begins loading
|
||||
this.trackProgress();
|
||||
|
||||
// Watch for a native progress event call on the tech element
|
||||
// In HTML5, some older versions don't support the progress event
|
||||
// So we're assuming they don't, and turning off manual progress if they do.
|
||||
this.tech.on("progress", function(){
|
||||
|
||||
// Remove this listener from the element
|
||||
this.removeEvent("progress", arguments.callee);
|
||||
|
||||
// Update known progress support for this playback technology
|
||||
this.support.progressEvent = true;
|
||||
|
||||
// Turn off manual progress tracking
|
||||
this.player.manualProgressOff();
|
||||
});
|
||||
},
|
||||
|
||||
manualProgressOff: function(){
|
||||
this.manualProgress = false;
|
||||
this.stopTrackingProgress();
|
||||
},
|
||||
|
||||
trackProgress: function(){
|
||||
this.progressInterval = setInterval(_V_.proxy(this, function(){
|
||||
// Don't trigger unless buffered amount is greater than last time
|
||||
// log(this.values.bufferEnd, this.buffered().end(0), this.duration())
|
||||
/* TODO: update for multiple buffered regions */
|
||||
if (this.values.bufferEnd < this.buffered().end(0)) {
|
||||
this.trigger("progress");
|
||||
} else if (this.bufferedPercent() == 1) {
|
||||
this.stopTrackingProgress();
|
||||
this.trigger("progress"); // Last update
|
||||
}
|
||||
}), 500);
|
||||
},
|
||||
stopTrackingProgress: function(){ clearInterval(this.progressInterval); },
|
||||
|
||||
/* Time Tracking -------------------------------------------------------------- */
|
||||
manualTimeUpdatesOn: function(){
|
||||
this.manualTimeUpdates = true;
|
||||
|
||||
this.on("play", this.trackCurrentTime);
|
||||
this.on("pause", this.stopTrackingCurrentTime);
|
||||
// timeupdate is also called by .currentTime whenever current time is set
|
||||
|
||||
// Watch for native timeupdate event
|
||||
this.tech.on("timeupdate", function(){
|
||||
|
||||
// Remove this listener from the element
|
||||
this.removeEvent("timeupdate", arguments.callee);
|
||||
|
||||
// Update known progress support for this playback technology
|
||||
this.support.timeupdateEvent = true;
|
||||
|
||||
// Turn off manual progress tracking
|
||||
this.player.manualTimeUpdatesOff();
|
||||
});
|
||||
},
|
||||
|
||||
manualTimeUpdatesOff: function(){
|
||||
this.manualTimeUpdates = false;
|
||||
this.stopTrackingCurrentTime();
|
||||
this.removeEvent("play", this.trackCurrentTime);
|
||||
this.removeEvent("pause", this.stopTrackingCurrentTime);
|
||||
},
|
||||
|
||||
trackCurrentTime: function(){
|
||||
if (this.currentTimeInterval) { this.stopTrackingCurrentTime(); }
|
||||
this.currentTimeInterval = setInterval(_V_.proxy(this, function(){
|
||||
this.trigger("timeupdate");
|
||||
}), 250); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
|
||||
},
|
||||
|
||||
// Turn off play progress tracking (when paused or dragging)
|
||||
stopTrackingCurrentTime: function(){ clearInterval(this.currentTimeInterval); },
|
||||
|
||||
/* Player event handlers (how the player reacts to certain events)
|
||||
================================================================================ */
|
||||
onEnded: function(){
|
||||
if (this.options.loop) {
|
||||
this.currentTime(0);
|
||||
this.play();
|
||||
} else {
|
||||
this.pause();
|
||||
}
|
||||
},
|
||||
|
||||
onPlay: function(){
|
||||
_V_.removeClass(this.el, "vjs-paused");
|
||||
_V_.addClass(this.el, "vjs-playing");
|
||||
},
|
||||
|
||||
onPause: function(){
|
||||
_V_.removeClass(this.el, "vjs-playing");
|
||||
_V_.addClass(this.el, "vjs-paused");
|
||||
},
|
||||
|
||||
onProgress: function(){
|
||||
// Add custom event for when source is finished downloading.
|
||||
if (this.bufferedPercent() == 1) {
|
||||
this.trigger("loadedalldata");
|
||||
}
|
||||
},
|
||||
|
||||
// Update duration with durationchange event
|
||||
// Allows for cacheing value instead of asking player each time.
|
||||
onDurationChange: function(){
|
||||
this.duration(this.techGet("duration"));
|
||||
},
|
||||
|
||||
onError: function(e) {
|
||||
_V_.log("Video Error", e);
|
||||
},
|
||||
|
||||
/* Player API
|
||||
================================================================================ */
|
||||
|
||||
// Pass values to the playback tech
|
||||
techCall: function(method, arg){
|
||||
|
||||
// If it's not ready yet, call method when it is
|
||||
if (!this.tech.isReady) {
|
||||
this.tech.ready(function(){
|
||||
this[method](arg);
|
||||
});
|
||||
|
||||
// Otherwise call method now
|
||||
} else {
|
||||
try {
|
||||
this.tech[method](arg);
|
||||
} catch(e) {
|
||||
_V_.log(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Get calls can't wait for the tech, and sometimes don't need to.
|
||||
techGet: function(method){
|
||||
|
||||
// Make sure tech is ready
|
||||
if (this.tech.isReady) {
|
||||
|
||||
// Flash likes to die and reload when you hide or reposition it.
|
||||
// In these cases the object methods go away and we get errors.
|
||||
// When that happens we'll catch the errors and inform tech that it's not ready any more.
|
||||
try {
|
||||
return this.tech[method]();
|
||||
} catch(e) {
|
||||
|
||||
// When building additional tech libs, an expected method may not be defined yet
|
||||
if (this.tech[method] === undefined) {
|
||||
_V_.log("Video.js: " + method + " method not defined for "+this.techName+" playback technology.", e);
|
||||
|
||||
} else {
|
||||
|
||||
// When a method isn't available on the object it throws a TypeError
|
||||
if (e.name == "TypeError") {
|
||||
_V_.log("Video.js: " + method + " unavailable on "+this.techName+" playback technology element.", e);
|
||||
this.tech.isReady = false;
|
||||
|
||||
} else {
|
||||
_V_.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
// Method for calling methods on the current playback technology
|
||||
// techCall: function(method, arg){
|
||||
//
|
||||
// // if (this.isReady) {
|
||||
// //
|
||||
// // } else {
|
||||
// // _V_.log("The playback technology API is not ready yet. Use player.ready(myFunction)."+" ["+method+"]", arguments.callee.caller.arguments.callee.caller.arguments.callee.caller)
|
||||
// // return false;
|
||||
// // // throw new Error("The playback technology API is not ready yet. Use player.ready(myFunction)."+" ["+method+"]");
|
||||
// // }
|
||||
// },
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-play
|
||||
play: function(){
|
||||
this.techCall("play");
|
||||
return this;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-pause
|
||||
pause: function(){
|
||||
this.techCall("pause");
|
||||
return this;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-paused
|
||||
// The initial state of paused should be true (in Safari it's actually false)
|
||||
paused: function(){
|
||||
return (this.techGet("paused") === false) ? false : true;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-currenttime
|
||||
currentTime: function(seconds){
|
||||
if (seconds !== undefined) {
|
||||
|
||||
// Cache the last set value for smoother scrubbing.
|
||||
this.values.lastSetCurrentTime = seconds;
|
||||
|
||||
this.techCall("setCurrentTime", seconds);
|
||||
|
||||
// Improve the accuracy of manual timeupdates
|
||||
if (this.manualTimeUpdates) { this.trigger("timeupdate"); }
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// Cache last currentTime and return
|
||||
// Default to 0 seconds
|
||||
return this.values.currentTime = (this.techGet("currentTime") || 0);
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-duration
|
||||
// Duration should return NaN if not available. ParseFloat will turn false-ish values to NaN.
|
||||
duration: function(seconds){
|
||||
if (seconds !== undefined) {
|
||||
|
||||
// Cache the last set value for optimiized scrubbing (esp. Flash)
|
||||
this.values.duration = parseFloat(seconds);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
return this.values.duration;
|
||||
},
|
||||
|
||||
// Calculates how much time is left. Not in spec, but useful.
|
||||
remainingTime: function(){
|
||||
return this.duration() - this.currentTime();
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-buffered
|
||||
// Buffered returns a timerange object. Kind of like an array of portions of the video that have been downloaded.
|
||||
// So far no browsers return more than one range (portion)
|
||||
buffered: function(){
|
||||
var buffered = this.techGet("buffered"),
|
||||
start = 0,
|
||||
end = this.values.bufferEnd = this.values.bufferEnd || 0, // Default end to 0 and store in values
|
||||
timeRange;
|
||||
|
||||
if (buffered && buffered.length > 0 && buffered.end(0) !== end) {
|
||||
end = buffered.end(0);
|
||||
// Storing values allows them be overridden by setBufferedFromProgress
|
||||
this.values.bufferEnd = end;
|
||||
}
|
||||
|
||||
return _V_.createTimeRange(start, end);
|
||||
},
|
||||
|
||||
// Calculates amount of buffer is full. Not in spec but useful.
|
||||
bufferedPercent: function(){
|
||||
return (this.duration()) ? this.buffered().end(0) / this.duration() : 0;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-volume
|
||||
volume: function(percentAsDecimal){
|
||||
var vol;
|
||||
|
||||
if (percentAsDecimal !== undefined) {
|
||||
vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal))); // Force value to between 0 and 1
|
||||
this.values.volume = vol;
|
||||
this.techCall("setVolume", vol);
|
||||
_V_.setLocalStorage("volume", vol);
|
||||
return this;
|
||||
}
|
||||
|
||||
// Default to 1 when returning current volume.
|
||||
vol = parseFloat(this.techGet("volume"));
|
||||
return (isNaN(vol)) ? 1 : vol;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#attr-media-muted
|
||||
muted: function(muted){
|
||||
if (muted !== undefined) {
|
||||
this.techCall("setMuted", muted);
|
||||
return this;
|
||||
}
|
||||
return this.techGet("muted") || false; // Default to false
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/dimension-attributes.html#attr-dim-height
|
||||
// Video tag width/height only work in pixels. No percents.
|
||||
// But allowing limited percents use. e.g. width() will return number+%, not computed width
|
||||
width: function(num, skipListeners){
|
||||
return this.dimension("width", num, skipListeners);
|
||||
},
|
||||
height: function(num, skipListeners){
|
||||
return this.dimension("height", num, skipListeners);
|
||||
},
|
||||
// Set both width and height at the same time.
|
||||
size: function(width, height){
|
||||
// Skip resize listeners on width for optimization
|
||||
return this.width(width, true).height(height);
|
||||
},
|
||||
dimension: function(widthOrHeight, num, skipListeners){
|
||||
if (num !== undefined) {
|
||||
|
||||
// Cache on object to be returned. Shouldn't have any effect after CSS.
|
||||
this.values[widthOrHeight] = num;
|
||||
|
||||
// Check if using percent width/height and adjust
|
||||
if ((""+num).indexOf("%") !== -1) {
|
||||
this.el.style[widthOrHeight] = num;
|
||||
} else {
|
||||
this.el.style[widthOrHeight] = num+"px";
|
||||
}
|
||||
|
||||
// skipListeners allows us to avoid triggering the resize event when setting both width and height
|
||||
if (!skipListeners) { this.trigger("resize"); }
|
||||
return this;
|
||||
}
|
||||
|
||||
// Returns cached width/height in attribute.
|
||||
// Could make this return computed width and support %s. Not a small amount of work.
|
||||
return this.values[widthOrHeight];
|
||||
},
|
||||
|
||||
// Check if current tech can support native fullscreen (e.g. with built in controls lik iOS, so not our flash swf)
|
||||
supportsFullScreen: function(){ return this.techGet("supportsFullScreen") || false; },
|
||||
|
||||
// Turn on fullscreen (or window) mode
|
||||
requestFullScreen: function(){
|
||||
var requestFullScreen = _V_.support.requestFullScreen;
|
||||
|
||||
this.isFullScreen = true;
|
||||
|
||||
// Check for browser element fullscreen support
|
||||
if (requestFullScreen) {
|
||||
|
||||
// Trigger fullscreenchange event after change
|
||||
_V_.on(document, requestFullScreen.eventName, this.proxy(function(){
|
||||
this.isFullScreen = document[requestFullScreen.isFullScreen];
|
||||
|
||||
// If cancelling fullscreen, remove event listener.
|
||||
if (this.isFullScreen == false) {
|
||||
_V_.removeEvent(document, requestFullScreen.eventName, arguments.callee);
|
||||
}
|
||||
|
||||
this.trigger("fullscreenchange");
|
||||
}));
|
||||
|
||||
// Flash and other plugins get reloaded when you take their parent to fullscreen.
|
||||
// To fix that we'll remove the tech, and reload it after the resize has finished.
|
||||
if (this.tech.support.fullscreenResize === false && this.options.flash.iFrameMode != true) {
|
||||
|
||||
this.pause();
|
||||
this.unloadTech();
|
||||
|
||||
_V_.on(document, requestFullScreen.eventName, this.proxy(function(){
|
||||
_V_.removeEvent(document, requestFullScreen.eventName, arguments.callee);
|
||||
this.loadTech(this.techName, { src: this.values.src });
|
||||
}));
|
||||
|
||||
this.el[requestFullScreen.requestFn]();
|
||||
|
||||
} else {
|
||||
this.el[requestFullScreen.requestFn]();
|
||||
}
|
||||
|
||||
} else if (this.tech.supportsFullScreen()) {
|
||||
this.trigger("fullscreenchange");
|
||||
this.techCall("enterFullScreen");
|
||||
|
||||
} else {
|
||||
this.trigger("fullscreenchange");
|
||||
this.enterFullWindow();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
cancelFullScreen: function(){
|
||||
var requestFullScreen = _V_.support.requestFullScreen;
|
||||
|
||||
this.isFullScreen = false;
|
||||
|
||||
// Check for browser element fullscreen support
|
||||
if (requestFullScreen) {
|
||||
|
||||
// Flash and other plugins get reloaded when you take their parent to fullscreen.
|
||||
// To fix that we'll remove the tech, and reload it after the resize has finished.
|
||||
if (this.tech.support.fullscreenResize === false && this.options.flash.iFrameMode != true) {
|
||||
|
||||
this.pause();
|
||||
this.unloadTech();
|
||||
|
||||
_V_.on(document, requestFullScreen.eventName, this.proxy(function(){
|
||||
_V_.removeEvent(document, requestFullScreen.eventName, arguments.callee);
|
||||
this.loadTech(this.techName, { src: this.values.src })
|
||||
}));
|
||||
|
||||
document[requestFullScreen.cancelFn]();
|
||||
|
||||
} else {
|
||||
document[requestFullScreen.cancelFn]();
|
||||
}
|
||||
|
||||
} else if (this.tech.supportsFullScreen()) {
|
||||
this.techCall("exitFullScreen");
|
||||
this.trigger("fullscreenchange");
|
||||
|
||||
} else {
|
||||
this.exitFullWindow();
|
||||
this.trigger("fullscreenchange");
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.
|
||||
enterFullWindow: function(){
|
||||
this.isFullWindow = true;
|
||||
|
||||
// Storing original doc overflow value to return to when fullscreen is off
|
||||
this.docOrigOverflow = document.documentElement.style.overflow;
|
||||
|
||||
// Add listener for esc key to exit fullscreen
|
||||
_V_.on(document, "keydown", _V_.proxy(this, this.fullWindowOnEscKey));
|
||||
|
||||
// Hide any scroll bars
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
|
||||
// Apply fullscreen styles
|
||||
_V_.addClass(document.body, "vjs-full-window");
|
||||
_V_.addClass(this.el, "vjs-fullscreen");
|
||||
|
||||
this.trigger("enterFullWindow");
|
||||
},
|
||||
fullWindowOnEscKey: function(event){
|
||||
if (event.keyCode == 27) {
|
||||
if (this.isFullScreen == true) {
|
||||
this.cancelFullScreen();
|
||||
} else {
|
||||
this.exitFullWindow();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
exitFullWindow: function(){
|
||||
this.isFullWindow = false;
|
||||
_V_.removeEvent(document, "keydown", this.fullWindowOnEscKey);
|
||||
|
||||
// Unhide scroll bars.
|
||||
document.documentElement.style.overflow = this.docOrigOverflow;
|
||||
|
||||
// Remove fullscreen styles
|
||||
_V_.removeClass(document.body, "vjs-full-window");
|
||||
_V_.removeClass(this.el, "vjs-fullscreen");
|
||||
|
||||
// Resize the box, controller, and poster to original sizes
|
||||
// this.positionAll();
|
||||
this.trigger("exitFullWindow");
|
||||
},
|
||||
|
||||
selectSource: function(sources){
|
||||
|
||||
// Loop through each playback technology in the options order
|
||||
for (var i=0,j=this.options.techOrder;i<j.length;i++) {
|
||||
var techName = j[i],
|
||||
tech = _V_[techName];
|
||||
// tech = _V_.tech[techName];
|
||||
|
||||
// Check if the browser supports this technology
|
||||
if (tech.isSupported()) {
|
||||
|
||||
// Loop through each source object
|
||||
for (var a=0,b=sources;a<b.length;a++) {
|
||||
var source = b[a];
|
||||
|
||||
// Check if source can be played with this technology
|
||||
if (tech.canPlaySource.call(this, source)) {
|
||||
|
||||
return { source: source, tech: techName };
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
// src is a pretty powerful function
|
||||
// If you pass it an array of source objects, it will find the best source to play and use that object.src
|
||||
// If the new source requires a new playback technology, it will switch to that.
|
||||
// If you pass it an object, it will set the source to object.src
|
||||
// If you pass it anything else (url string) it will set the video source to that
|
||||
src: function(source){
|
||||
// Case: Array of source objects to choose from and pick the best to play
|
||||
if (source instanceof Array) {
|
||||
|
||||
var sourceTech = this.selectSource(source),
|
||||
source,
|
||||
techName;
|
||||
|
||||
if (sourceTech) {
|
||||
source = sourceTech.source;
|
||||
techName = sourceTech.tech;
|
||||
|
||||
// If this technology is already loaded, set source
|
||||
if (techName == this.techName) {
|
||||
this.src(source); // Passing the source object
|
||||
|
||||
// Otherwise load this technology with chosen source
|
||||
} else {
|
||||
this.loadTech(techName, source);
|
||||
}
|
||||
} else {
|
||||
_V_.log("No compatible source and playback technology were found.");
|
||||
var fallbackInfo = _V_.createElement("div", {
|
||||
innerHTML: "Sorry, no compatible source and playback technology were found for this video. Try using another browser like <a href='http://www.google.com/chrome'>Google Chrome</a> or download the latest <a href='http://get.adobe.com/flashplayer/'>Adobe Flash Player</a>."
|
||||
});
|
||||
fallbackInfo.style.cssText = "color:#ffffff;font-size:13px;";
|
||||
this.el.appendChild(fallbackInfo);
|
||||
}
|
||||
|
||||
// Case: Source object { src: "", type: "" ... }
|
||||
} else if (source instanceof Object) {
|
||||
|
||||
if (_V_[this.techName].canPlaySource(source)) {
|
||||
this.src(source.src);
|
||||
} else {
|
||||
// Send through tech loop to check for a compatible technology.
|
||||
this.src([source]);
|
||||
}
|
||||
|
||||
// Case: URL String (http://myvideo...)
|
||||
} else {
|
||||
// Cache for getting last set source
|
||||
this.values.src = source;
|
||||
|
||||
if (!this.isReady) {
|
||||
this.ready(function(){
|
||||
this.src(source);
|
||||
});
|
||||
} else {
|
||||
this.techCall("src", source);
|
||||
if (this.options.preload == "auto") {
|
||||
this.load();
|
||||
}
|
||||
if (this.options.autoplay) {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// Begin loading the src data
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-load
|
||||
load: function(){
|
||||
this.techCall("load");
|
||||
return this;
|
||||
},
|
||||
|
||||
// http://dev.w3.org/html5/spec/video.html#dom-media-currentsrc
|
||||
currentSrc: function(){
|
||||
return this.techGet("currentSrc") || this.values.src || "";
|
||||
},
|
||||
|
||||
// Attributes/Options
|
||||
preload: function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall("setPreload", value);
|
||||
this.options.preload = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet("preload");
|
||||
},
|
||||
autoplay: function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall("setAutoplay", value);
|
||||
this.options.autoplay = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet("autoplay", value);
|
||||
},
|
||||
loop: function(value){
|
||||
if (value !== undefined) {
|
||||
this.techCall("setLoop", value);
|
||||
this.options.loop = value;
|
||||
return this;
|
||||
}
|
||||
return this.techGet("loop");
|
||||
},
|
||||
|
||||
controls: function(){ return this.options.controls; },
|
||||
poster: function(){ return this.techGet("poster"); },
|
||||
error: function(){ return this.techGet("error"); },
|
||||
ended: function(){ return this.techGet("ended"); }
|
||||
|
||||
// Methods to add support for
|
||||
// networkState: function(){ return this.techCall("networkState"); },
|
||||
// readyState: function(){ return this.techCall("readyState"); },
|
||||
// seeking: function(){ return this.techCall("seeking"); },
|
||||
// initialTime: function(){ return this.techCall("initialTime"); },
|
||||
// startOffsetTime: function(){ return this.techCall("startOffsetTime"); },
|
||||
// played: function(){ return this.techCall("played"); },
|
||||
// seekable: function(){ return this.techCall("seekable"); },
|
||||
// videoTracks: function(){ return this.techCall("videoTracks"); },
|
||||
// audioTracks: function(){ return this.techCall("audioTracks"); },
|
||||
// videoWidth: function(){ return this.techCall("videoWidth"); },
|
||||
// videoHeight: function(){ return this.techCall("videoHeight"); },
|
||||
// defaultPlaybackRate: function(){ return this.techCall("defaultPlaybackRate"); },
|
||||
// playbackRate: function(){ return this.techCall("playbackRate"); },
|
||||
// mediaGroup: function(){ return this.techCall("mediaGroup"); },
|
||||
// controller: function(){ return this.techCall("controller"); },
|
||||
// defaultMuted: function(){ return this.techCall("defaultMuted"); }
|
||||
});
|
||||
|
||||
// RequestFullscreen API
|
||||
(function(){
|
||||
var requestFn,
|
||||
cancelFn,
|
||||
eventName,
|
||||
isFullScreen,
|
||||
playerProto = _V_.Player.prototype;
|
||||
|
||||
// Current W3C Spec
|
||||
// http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html#api
|
||||
// Mozilla Draft: https://wiki.mozilla.org/Gecko:FullScreenAPI#fullscreenchange_event
|
||||
if (document.cancelFullscreen !== undefined) {
|
||||
requestFn = "requestFullscreen";
|
||||
cancelFn = "exitFullscreen";
|
||||
eventName = "fullscreenchange";
|
||||
isFullScreen = "fullScreen";
|
||||
|
||||
// Webkit (Chrome/Safari) and Mozilla (Firefox) have working implementaitons
|
||||
// that use prefixes and vary slightly from the new W3C spec. Specifically, using 'exit' instead of 'cancel',
|
||||
// and lowercasing the 'S' in Fullscreen.
|
||||
// Other browsers don't have any hints of which version they might follow yet, so not going to try to predict by loopeing through all prefixes.
|
||||
} else {
|
||||
|
||||
_V_.each(["moz", "webkit"], function(prefix){
|
||||
|
||||
// https://github.com/zencoder/video-js/pull/128
|
||||
if ((prefix != "moz" || document.mozFullScreenEnabled) && document[prefix + "CancelFullScreen"] !== undefined) {
|
||||
requestFn = prefix + "RequestFullScreen";
|
||||
cancelFn = prefix + "CancelFullScreen";
|
||||
eventName = prefix + "fullscreenchange";
|
||||
|
||||
if (prefix == "webkit") {
|
||||
isFullScreen = prefix + "IsFullScreen";
|
||||
} else {
|
||||
isFullScreen = prefix + "FullScreen";
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (requestFn) {
|
||||
_V_.support.requestFullScreen = {
|
||||
requestFn: requestFn,
|
||||
cancelFn: cancelFn,
|
||||
eventName: eventName,
|
||||
isFullScreen: isFullScreen
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
29
src/tech.js
29
src/tech.js
@ -1,29 +0,0 @@
|
||||
/* Playback Technology - Base class for playback technologies
|
||||
================================================================================ */
|
||||
_V_.PlaybackTech = _V_.Component.extend({
|
||||
init: function(player, options){
|
||||
// this._super(player, options);
|
||||
|
||||
// Make playback element clickable
|
||||
// _V_.addEvent(this.el, "click", _V_.proxy(this, _V_.PlayToggle.prototype.onClick));
|
||||
|
||||
// this.addEvent("click", this.proxy(this.onClick));
|
||||
|
||||
// player.triggerEvent("techready");
|
||||
},
|
||||
// destroy: function(){},
|
||||
// createElement: function(){},
|
||||
onClick: function(){
|
||||
if (this.player.options.controls) {
|
||||
_V_.PlayToggle.prototype.onClick.call(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create placeholder methods for each that warn when a method isn't supported by the current playback technology
|
||||
_V_.apiMethods = "play,pause,paused,currentTime,setCurrentTime,duration,buffered,volume,setVolume,muted,setMuted,width,height,supportsFullScreen,enterFullScreen,src,load,currentSrc,preload,setPreload,autoplay,setAutoplay,loop,setLoop,error,networkState,readyState,seeking,initialTime,startOffsetTime,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks,defaultPlaybackRate,playbackRate,mediaGroup,controller,controls,defaultMuted".split(",");
|
||||
_V_.each(_V_.apiMethods, function(methodName){
|
||||
_V_.PlaybackTech.prototype[methodName] = function(){
|
||||
throw new Error("The '"+methodName+"' method is not available on the playback technology's API");
|
||||
};
|
||||
});
|
780
src/tracks.js
780
src/tracks.js
@ -1,780 +0,0 @@
|
||||
// TEXT TRACKS
|
||||
// Text tracks are tracks of timed text events.
|
||||
// Captions - text displayed over the video for the hearing impared
|
||||
// Subtitles - text displayed over the video for those who don't understand langauge in the video
|
||||
// Chapters - text displayed in a menu allowing the user to jump to particular points (chapters) in the video
|
||||
// Descriptions (not supported yet) - audio descriptions that are read back to the user by a screen reading device
|
||||
|
||||
// Player Track Functions - Functions add to the player object for easier access to tracks
|
||||
_V_.merge(_V_.Player.prototype, {
|
||||
|
||||
// Add an array of text tracks. captions, subtitles, chapters, descriptions
|
||||
// Track objects will be stored in the player.textTracks array
|
||||
addTextTracks: function(trackObjects){
|
||||
var tracks = this.textTracks = (this.textTracks) ? this.textTracks : [],
|
||||
i = 0, j = trackObjects.length, track, Kind;
|
||||
|
||||
for (;i<j;i++) {
|
||||
// HTML5 Spec says default to subtitles.
|
||||
// Uppercase (uc) first letter to match class names
|
||||
Kind = _V_.uc(trackObjects[i].kind || "subtitles");
|
||||
|
||||
// Create correct texttrack class. CaptionsTrack, etc.
|
||||
track = new _V_[Kind + "Track"](this, trackObjects[i]);
|
||||
|
||||
tracks.push(track);
|
||||
|
||||
// If track.default is set, start showing immediately
|
||||
// TODO: Add a process to deterime the best track to show for the specific kind
|
||||
// Incase there are mulitple defaulted tracks of the same kind
|
||||
// Or the user has a set preference of a specific language that should override the default
|
||||
if (track['default']) {
|
||||
this.ready(_V_.proxy(track, track.show));
|
||||
}
|
||||
}
|
||||
|
||||
// Return the track so it can be appended to the display component
|
||||
return this;
|
||||
},
|
||||
|
||||
// Show a text track
|
||||
// disableSameKind: disable all other tracks of the same kind. Value should be a track kind (captions, etc.)
|
||||
showTextTrack: function(id, disableSameKind){
|
||||
var tracks = this.textTracks,
|
||||
i = 0,
|
||||
j = tracks.length,
|
||||
track, showTrack, kind;
|
||||
|
||||
// Find Track with same ID
|
||||
for (;i<j;i++) {
|
||||
track = tracks[i];
|
||||
if (track.id === id) {
|
||||
track.show();
|
||||
showTrack = track;
|
||||
|
||||
// Disable tracks of the same kind
|
||||
} else if (disableSameKind && track.kind == disableSameKind && track.mode > 0) {
|
||||
track.disable();
|
||||
}
|
||||
}
|
||||
|
||||
// Get track kind from shown track or disableSameKind
|
||||
kind = (showTrack) ? showTrack.kind : ((disableSameKind) ? disableSameKind : false);
|
||||
|
||||
// Trigger trackchange event, captionstrackchange, subtitlestrackchange, etc.
|
||||
if (kind) {
|
||||
this.trigger(kind+"trackchange");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Track Class
|
||||
// Contains track methods for loading, showing, parsing cues of tracks
|
||||
_V_.Track = _V_.Component.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
// Apply track info to track object
|
||||
// Options will often be a track element
|
||||
_V_.merge(this, {
|
||||
// Build ID if one doesn't exist
|
||||
id: options.id || ("vjs_" + options.kind + "_" + options.language + "_" + _V_.guid++),
|
||||
|
||||
src: options.src,
|
||||
|
||||
// If default is used, subtitles/captions to start showing
|
||||
"default": options["default"], // 'default' is reserved-ish
|
||||
title: options.title,
|
||||
|
||||
// Language - two letter string to represent track language, e.g. "en" for English
|
||||
// readonly attribute DOMString language;
|
||||
language: options.srclang,
|
||||
|
||||
// Track label e.g. "English"
|
||||
// readonly attribute DOMString label;
|
||||
label: options.label,
|
||||
|
||||
// All cues of the track. Cues have a startTime, endTime, text, and other properties.
|
||||
// readonly attribute TextTrackCueList cues;
|
||||
cues: [],
|
||||
|
||||
// ActiveCues is all cues that are currently showing
|
||||
// readonly attribute TextTrackCueList activeCues;
|
||||
activeCues: [],
|
||||
|
||||
// ReadyState describes if the text file has been loaded
|
||||
// const unsigned short NONE = 0;
|
||||
// const unsigned short LOADING = 1;
|
||||
// const unsigned short LOADED = 2;
|
||||
// const unsigned short ERROR = 3;
|
||||
// readonly attribute unsigned short readyState;
|
||||
readyState: 0,
|
||||
|
||||
// Mode describes if the track is showing, hidden, or disabled
|
||||
// const unsigned short OFF = 0;
|
||||
// const unsigned short HIDDEN = 1; (still triggering cuechange events, but not visible)
|
||||
// const unsigned short SHOWING = 2;
|
||||
// attribute unsigned short mode;
|
||||
mode: 0
|
||||
});
|
||||
},
|
||||
|
||||
// Create basic div to hold cue text
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-" + this.kind + " vjs-text-track"
|
||||
});
|
||||
},
|
||||
|
||||
// Show: Mode Showing (2)
|
||||
// Indicates that the text track is active. If no attempt has yet been made to obtain the track's cues, the user agent will perform such an attempt momentarily.
|
||||
// The user agent is maintaining a list of which cues are active, and events are being fired accordingly.
|
||||
// In addition, for text tracks whose kind is subtitles or captions, the cues are being displayed over the video as appropriate;
|
||||
// for text tracks whose kind is descriptions, the user agent is making the cues available to the user in a non-visual fashion;
|
||||
// and for text tracks whose kind is chapters, the user agent is making available to the user a mechanism by which the user can navigate to any point in the media resource by selecting a cue.
|
||||
// The showing by default state is used in conjunction with the default attribute on track elements to indicate that the text track was enabled due to that attribute.
|
||||
// This allows the user agent to override the state if a later track is discovered that is more appropriate per the user's preferences.
|
||||
show: function(){
|
||||
this.activate();
|
||||
|
||||
this.mode = 2;
|
||||
|
||||
// Show element.
|
||||
this._super();
|
||||
},
|
||||
|
||||
// Hide: Mode Hidden (1)
|
||||
// Indicates that the text track is active, but that the user agent is not actively displaying the cues.
|
||||
// If no attempt has yet been made to obtain the track's cues, the user agent will perform such an attempt momentarily.
|
||||
// The user agent is maintaining a list of which cues are active, and events are being fired accordingly.
|
||||
hide: function(){
|
||||
// When hidden, cues are still triggered. Disable to stop triggering.
|
||||
this.activate();
|
||||
|
||||
this.mode = 1;
|
||||
|
||||
// Hide element.
|
||||
this._super();
|
||||
},
|
||||
|
||||
// Disable: Mode Off/Disable (0)
|
||||
// Indicates that the text track is not active. Other than for the purposes of exposing the track in the DOM, the user agent is ignoring the text track.
|
||||
// No cues are active, no events are fired, and the user agent will not attempt to obtain the track's cues.
|
||||
disable: function(){
|
||||
// If showing, hide.
|
||||
if (this.mode == 2) { this.hide(); }
|
||||
|
||||
// Stop triggering cues
|
||||
this.deactivate();
|
||||
|
||||
// Switch Mode to Off
|
||||
this.mode = 0;
|
||||
},
|
||||
|
||||
// Turn on cue tracking. Tracks that are showing OR hidden are active.
|
||||
activate: function(){
|
||||
// Load text file if it hasn't been yet.
|
||||
if (this.readyState == 0) { this.load(); }
|
||||
|
||||
// Only activate if not already active.
|
||||
if (this.mode == 0) {
|
||||
// Update current cue on timeupdate
|
||||
// Using unique ID for proxy function so other tracks don't remove listener
|
||||
this.player.on("timeupdate", this.proxy(this.update, this.id));
|
||||
|
||||
// Reset cue time on media end
|
||||
this.player.on("ended", this.proxy(this.reset, this.id));
|
||||
|
||||
// Add to display
|
||||
if (this.kind == "captions" || this.kind == "subtitles") {
|
||||
this.player.textTrackDisplay.addComponent(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Turn off cue tracking.
|
||||
deactivate: function(){
|
||||
// Using unique ID for proxy function so other tracks don't remove listener
|
||||
this.player.off("timeupdate", this.proxy(this.update, this.id));
|
||||
this.player.off("ended", this.proxy(this.reset, this.id));
|
||||
this.reset(); // Reset
|
||||
|
||||
// Remove from display
|
||||
this.player.textTrackDisplay.removeComponent(this);
|
||||
},
|
||||
|
||||
// A readiness state
|
||||
// One of the following:
|
||||
//
|
||||
// Not loaded
|
||||
// Indicates that the text track is known to exist (e.g. it has been declared with a track element), but its cues have not been obtained.
|
||||
//
|
||||
// Loading
|
||||
// Indicates that the text track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track.
|
||||
//
|
||||
// Loaded
|
||||
// Indicates that the text track has been loaded with no fatal errors. No new cues will be added to the track except if the text track corresponds to a MutableTextTrack object.
|
||||
//
|
||||
// Failed to load
|
||||
// Indicates that the text track was enabled, but when the user agent attempted to obtain it, this failed in some way (e.g. URL could not be resolved, network error, unknown text track format). Some or all of the cues are likely missing and will not be obtained.
|
||||
load: function(){
|
||||
|
||||
// Only load if not loaded yet.
|
||||
if (this.readyState == 0) {
|
||||
this.readyState = 1;
|
||||
_V_.get(this.src, this.proxy(this.parseCues), this.proxy(this.onError));
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
onError: function(err){
|
||||
this.error = err;
|
||||
this.readyState = 3;
|
||||
this.trigger("error");
|
||||
},
|
||||
|
||||
// Parse the WebVTT text format for cue times.
|
||||
// TODO: Separate parser into own class so alternative timed text formats can be used. (TTML, DFXP)
|
||||
parseCues: function(srcContent) {
|
||||
var cue, time, text,
|
||||
lines = srcContent.split("\n"),
|
||||
line = "", id;
|
||||
|
||||
for (var i=1, j=lines.length; i<j; i++) {
|
||||
// Line 0 should be 'WEBVTT', so skipping i=0
|
||||
|
||||
line = _V_.trim(lines[i]); // Trim whitespace and linebreaks
|
||||
|
||||
if (line) { // Loop until a line with content
|
||||
|
||||
// First line could be an optional cue ID
|
||||
// Check if line has the time separator
|
||||
if (line.indexOf("-->") == -1) {
|
||||
id = line;
|
||||
// Advance to next line for timing.
|
||||
line = _V_.trim(lines[++i]);
|
||||
} else {
|
||||
id = this.cues.length;
|
||||
}
|
||||
|
||||
// First line - Number
|
||||
cue = {
|
||||
id: id, // Cue Number
|
||||
index: this.cues.length // Position in Array
|
||||
};
|
||||
|
||||
// Timing line
|
||||
time = line.split(" --> ");
|
||||
cue.startTime = this.parseCueTime(time[0]);
|
||||
cue.endTime = this.parseCueTime(time[1]);
|
||||
|
||||
// Additional lines - Cue Text
|
||||
text = [];
|
||||
|
||||
// Loop until a blank line or end of lines
|
||||
// Assumeing trim("") returns false for blank lines
|
||||
while (lines[++i] && (line = _V_.trim(lines[i]))) {
|
||||
text.push(line);
|
||||
}
|
||||
|
||||
cue.text = text.join('<br/>');
|
||||
|
||||
// Add this cue
|
||||
this.cues.push(cue);
|
||||
}
|
||||
}
|
||||
|
||||
this.readyState = 2;
|
||||
this.trigger("loaded");
|
||||
},
|
||||
|
||||
parseCueTime: function(timeText) {
|
||||
var parts = timeText.split(':'),
|
||||
time = 0,
|
||||
hours, minutes, other, seconds, ms, flags;
|
||||
|
||||
// Check if optional hours place is included
|
||||
// 00:00:00.000 vs. 00:00.000
|
||||
if (parts.length == 3) {
|
||||
hours = parts[0];
|
||||
minutes = parts[1];
|
||||
other = parts[2];
|
||||
} else {
|
||||
hours = 0;
|
||||
minutes = parts[0];
|
||||
other = parts[1];
|
||||
}
|
||||
|
||||
// Break other (seconds, milliseconds, and flags) by spaces
|
||||
// TODO: Make additional cue layout settings work with flags
|
||||
other = other.split(/\s+/)
|
||||
// Remove seconds. Seconds is the first part before any spaces.
|
||||
seconds = other.splice(0,1)[0];
|
||||
// Could use either . or , for decimal
|
||||
seconds = seconds.split(/\.|,/);
|
||||
// Get milliseconds
|
||||
ms = parseFloat(seconds[1]);
|
||||
seconds = seconds[0];
|
||||
|
||||
// hours => seconds
|
||||
time += parseFloat(hours) * 3600;
|
||||
// minutes => seconds
|
||||
time += parseFloat(minutes) * 60;
|
||||
// Add seconds
|
||||
time += parseFloat(seconds);
|
||||
// Add milliseconds
|
||||
if (ms) { time += ms/1000; }
|
||||
|
||||
return time;
|
||||
},
|
||||
|
||||
// Update active cues whenever timeupdate events are triggered on the player.
|
||||
update: function(){
|
||||
if (this.cues.length > 0) {
|
||||
|
||||
// Get curent player time
|
||||
var time = this.player.currentTime();
|
||||
|
||||
// Check if the new time is outside the time box created by the the last update.
|
||||
if (this.prevChange === undefined || time < this.prevChange || this.nextChange <= time) {
|
||||
var cues = this.cues,
|
||||
|
||||
// Create a new time box for this state.
|
||||
newNextChange = this.player.duration(), // Start at beginning of the timeline
|
||||
newPrevChange = 0, // Start at end
|
||||
|
||||
reverse = false, // Set the direction of the loop through the cues. Optimized the cue check.
|
||||
newCues = [], // Store new active cues.
|
||||
|
||||
// Store where in the loop the current active cues are, to provide a smart starting point for the next loop.
|
||||
firstActiveIndex, lastActiveIndex,
|
||||
|
||||
html = "", // Create cue text HTML to add to the display
|
||||
cue, i, j; // Loop vars
|
||||
|
||||
// Check if time is going forwards or backwards (scrubbing/rewinding)
|
||||
// If we know the direction we can optimize the starting position and direction of the loop through the cues array.
|
||||
if (time >= this.nextChange || this.nextChange === undefined) { // NextChange should happen
|
||||
// Forwards, so start at the index of the first active cue and loop forward
|
||||
i = (this.firstActiveIndex !== undefined) ? this.firstActiveIndex : 0;
|
||||
} else {
|
||||
// Backwards, so start at the index of the last active cue and loop backward
|
||||
reverse = true;
|
||||
i = (this.lastActiveIndex !== undefined) ? this.lastActiveIndex : cues.length - 1;
|
||||
}
|
||||
|
||||
while (true) { // Loop until broken
|
||||
cue = cues[i];
|
||||
|
||||
// Cue ended at this point
|
||||
if (cue.endTime <= time) {
|
||||
newPrevChange = Math.max(newPrevChange, cue.endTime);
|
||||
|
||||
if (cue.active) {
|
||||
cue.active = false;
|
||||
}
|
||||
|
||||
// No earlier cues should have an active start time.
|
||||
// Nevermind. Assume first cue could have a duration the same as the video.
|
||||
// In that case we need to loop all the way back to the beginning.
|
||||
// if (reverse && cue.startTime) { break; }
|
||||
|
||||
// Cue hasn't started
|
||||
} else if (time < cue.startTime) {
|
||||
newNextChange = Math.min(newNextChange, cue.startTime);
|
||||
|
||||
if (cue.active) {
|
||||
cue.active = false;
|
||||
}
|
||||
|
||||
// No later cues should have an active start time.
|
||||
if (!reverse) { break; }
|
||||
|
||||
// Cue is current
|
||||
} else {
|
||||
|
||||
if (reverse) {
|
||||
// Add cue to front of array to keep in time order
|
||||
newCues.splice(0,0,cue);
|
||||
|
||||
// If in reverse, the first current cue is our lastActiveCue
|
||||
if (lastActiveIndex === undefined) { lastActiveIndex = i; }
|
||||
firstActiveIndex = i;
|
||||
} else {
|
||||
// Add cue to end of array
|
||||
newCues.push(cue);
|
||||
|
||||
// If forward, the first current cue is our firstActiveIndex
|
||||
if (firstActiveIndex === undefined) { firstActiveIndex = i; }
|
||||
lastActiveIndex = i;
|
||||
}
|
||||
|
||||
newNextChange = Math.min(newNextChange, cue.endTime);
|
||||
newPrevChange = Math.max(newPrevChange, cue.startTime);
|
||||
|
||||
cue.active = true;
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
// Reverse down the array of cues, break if at first
|
||||
if (i === 0) { break; } else { i--; }
|
||||
} else {
|
||||
// Walk up the array fo cues, break if at last
|
||||
if (i === cues.length - 1) { break; } else { i++; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.activeCues = newCues;
|
||||
this.nextChange = newNextChange;
|
||||
this.prevChange = newPrevChange;
|
||||
this.firstActiveIndex = firstActiveIndex;
|
||||
this.lastActiveIndex = lastActiveIndex;
|
||||
|
||||
this.updateDisplay();
|
||||
|
||||
this.trigger("cuechange");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Add cue HTML to display
|
||||
updateDisplay: function(){
|
||||
var cues = this.activeCues,
|
||||
html = "",
|
||||
i=0,j=cues.length;
|
||||
|
||||
for (;i<j;i++) {
|
||||
html += "<span class='vjs-tt-cue'>"+cues[i].text+"</span>";
|
||||
}
|
||||
|
||||
this.el.innerHTML = html;
|
||||
},
|
||||
|
||||
// Set all loop helper values back
|
||||
reset: function(){
|
||||
this.nextChange = 0;
|
||||
this.prevChange = this.player.duration();
|
||||
this.firstActiveIndex = 0;
|
||||
this.lastActiveIndex = 0;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Create specific track types
|
||||
_V_.CaptionsTrack = _V_.Track.extend({
|
||||
kind: "captions"
|
||||
});
|
||||
|
||||
_V_.SubtitlesTrack = _V_.Track.extend({
|
||||
kind: "subtitles"
|
||||
});
|
||||
|
||||
_V_.ChaptersTrack = _V_.Track.extend({
|
||||
kind: "chapters"
|
||||
});
|
||||
|
||||
|
||||
/* Text Track Display
|
||||
================================================================================ */
|
||||
// Global container for both subtitle and captions text. Simple div container.
|
||||
_V_.TextTrackDisplay = _V_.Component.extend({
|
||||
|
||||
createElement: function(){
|
||||
return this._super("div", {
|
||||
className: "vjs-text-track-display"
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Text Track Menu Items
|
||||
================================================================================ */
|
||||
_V_.TextTrackMenuItem = _V_.MenuItem.extend({
|
||||
|
||||
init: function(player, options){
|
||||
var track = this.track = options.track;
|
||||
|
||||
// Modify options for parent MenuItem class's init.
|
||||
options.label = track.label;
|
||||
options.selected = track["default"];
|
||||
this._super(player, options);
|
||||
|
||||
this.player.on(track.kind + "trackchange", _V_.proxy(this, this.update));
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this._super();
|
||||
this.player.showTextTrack(this.track.id, this.track.kind);
|
||||
},
|
||||
|
||||
update: function(){
|
||||
if (this.track.mode == 2) {
|
||||
this.selected(true);
|
||||
} else {
|
||||
this.selected(false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.OffTextTrackMenuItem = _V_.TextTrackMenuItem.extend({
|
||||
|
||||
init: function(player, options){
|
||||
// Create pseudo track info
|
||||
// Requires options.kind
|
||||
options.track = { kind: options.kind, player: player, label: "Off" }
|
||||
this._super(player, options);
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this._super();
|
||||
this.player.showTextTrack(this.track.id, this.track.kind);
|
||||
},
|
||||
|
||||
update: function(){
|
||||
var tracks = this.player.textTracks,
|
||||
i=0, j=tracks.length, track,
|
||||
off = true;
|
||||
|
||||
for (;i<j;i++) {
|
||||
track = tracks[i];
|
||||
if (track.kind == this.track.kind && track.mode == 2) {
|
||||
off = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (off) {
|
||||
this.selected(true);
|
||||
} else {
|
||||
this.selected(false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* Captions Button
|
||||
================================================================================ */
|
||||
_V_.TextTrackButton = _V_.Button.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this._super(player, options);
|
||||
|
||||
this.menu = this.createMenu();
|
||||
|
||||
if (this.items.length === 0) {
|
||||
this.hide();
|
||||
}
|
||||
},
|
||||
|
||||
createMenu: function(){
|
||||
var menu = new _V_.Menu(this.player);
|
||||
|
||||
// Add a title list item to the top
|
||||
menu.el.appendChild(_V_.createElement("li", {
|
||||
className: "vjs-menu-title",
|
||||
innerHTML: _V_.uc(this.kind)
|
||||
}));
|
||||
|
||||
// Add an OFF menu item to turn all tracks off
|
||||
menu.addItem(new _V_.OffTextTrackMenuItem(this.player, { kind: this.kind }))
|
||||
|
||||
this.items = this.createItems();
|
||||
|
||||
// Add menu items to the menu
|
||||
this.each(this.items, function(item){
|
||||
menu.addItem(item);
|
||||
});
|
||||
|
||||
// Add list to element
|
||||
this.addComponent(menu);
|
||||
|
||||
return menu;
|
||||
},
|
||||
|
||||
// Create a menu item for each text track
|
||||
createItems: function(){
|
||||
var items = [];
|
||||
this.each(this.player.textTracks, function(track){
|
||||
if (track.kind === this.kind) {
|
||||
items.push(new _V_.TextTrackMenuItem(this.player, {
|
||||
track: track
|
||||
}));
|
||||
}
|
||||
});
|
||||
return items;
|
||||
},
|
||||
|
||||
buildCSSClass: function(){
|
||||
return this.className + " vjs-menu-button " + this._super();
|
||||
},
|
||||
|
||||
// Focus - Add keyboard functionality to element
|
||||
onFocus: function(){
|
||||
// Show the menu, and keep showing when the menu items are in focus
|
||||
this.menu.lockShowing();
|
||||
// this.menu.el.style.display = "block";
|
||||
|
||||
// When tabbing through, the menu should hide when focus goes from the last menu item to the next tabbed element.
|
||||
_V_.one(this.menu.el.childNodes[this.menu.el.childNodes.length - 1], "blur", this.proxy(function(){
|
||||
this.menu.unlockShowing();
|
||||
}));
|
||||
},
|
||||
// Can't turn off list display that we turned on with focus, because list would go away.
|
||||
onBlur: function(){},
|
||||
|
||||
onClick: function(){
|
||||
// When you click the button it adds focus, which will show the menu indefinitely.
|
||||
// So we'll remove focus when the mouse leaves the button.
|
||||
// Focus is needed for tab navigation.
|
||||
this.one("mouseout", this.proxy(function(){
|
||||
this.menu.unlockShowing();
|
||||
this.el.blur();
|
||||
}));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.CaptionsButton = _V_.TextTrackButton.extend({
|
||||
kind: "captions",
|
||||
buttonText: "Captions",
|
||||
className: "vjs-captions-button"
|
||||
});
|
||||
|
||||
_V_.SubtitlesButton = _V_.TextTrackButton.extend({
|
||||
kind: "subtitles",
|
||||
buttonText: "Subtitles",
|
||||
className: "vjs-subtitles-button"
|
||||
});
|
||||
|
||||
// Chapters act much differently than other text tracks
|
||||
// Cues are navigation vs. other tracks of alternative languages
|
||||
_V_.ChaptersButton = _V_.TextTrackButton.extend({
|
||||
kind: "chapters",
|
||||
buttonText: "Chapters",
|
||||
className: "vjs-chapters-button",
|
||||
|
||||
// Create a menu item for each text track
|
||||
createItems: function(chaptersTrack){
|
||||
var items = [];
|
||||
|
||||
this.each(this.player.textTracks, function(track){
|
||||
if (track.kind === this.kind) {
|
||||
items.push(new _V_.TextTrackMenuItem(this.player, {
|
||||
track: track
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
return items;
|
||||
},
|
||||
|
||||
createMenu: function(){
|
||||
var tracks = this.player.textTracks,
|
||||
i = 0,
|
||||
j = tracks.length,
|
||||
track, chaptersTrack,
|
||||
items = this.items = [];
|
||||
|
||||
for (;i<j;i++) {
|
||||
track = tracks[i];
|
||||
if (track.kind == this.kind && track["default"]) {
|
||||
if (track.readyState < 2) {
|
||||
this.chaptersTrack = track;
|
||||
track.on("loaded", this.proxy(this.createMenu));
|
||||
return;
|
||||
} else {
|
||||
chaptersTrack = track;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var menu = this.menu = new _V_.Menu(this.player);
|
||||
|
||||
menu.el.appendChild(_V_.createElement("li", {
|
||||
className: "vjs-menu-title",
|
||||
innerHTML: _V_.uc(this.kind)
|
||||
}));
|
||||
|
||||
if (chaptersTrack) {
|
||||
var cues = chaptersTrack.cues,
|
||||
i = 0, j = cues.length, cue, mi;
|
||||
|
||||
for (;i<j;i++) {
|
||||
cue = cues[i];
|
||||
|
||||
mi = new _V_.ChaptersTrackMenuItem(this.player, {
|
||||
track: chaptersTrack,
|
||||
cue: cue
|
||||
});
|
||||
|
||||
items.push(mi);
|
||||
|
||||
menu.addComponent(mi);
|
||||
}
|
||||
}
|
||||
|
||||
// Add list to element
|
||||
this.addComponent(menu);
|
||||
|
||||
if (this.items.length > 0) {
|
||||
this.show();
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
_V_.ChaptersTrackMenuItem = _V_.MenuItem.extend({
|
||||
|
||||
init: function(player, options){
|
||||
var track = this.track = options.track,
|
||||
cue = this.cue = options.cue,
|
||||
currentTime = player.currentTime();
|
||||
|
||||
// Modify options for parent MenuItem class's init.
|
||||
options.label = cue.text;
|
||||
options.selected = (cue.startTime <= currentTime && currentTime < cue.endTime);
|
||||
this._super(player, options);
|
||||
|
||||
track.on("cuechange", _V_.proxy(this, this.update));
|
||||
},
|
||||
|
||||
onClick: function(){
|
||||
this._super();
|
||||
this.player.currentTime(this.cue.startTime);
|
||||
this.update(this.cue.startTime);
|
||||
},
|
||||
|
||||
update: function(time){
|
||||
var cue = this.cue,
|
||||
currentTime = this.player.currentTime();
|
||||
|
||||
// _V_.log(currentTime, cue.startTime);
|
||||
if (cue.startTime <= currentTime && currentTime < cue.endTime) {
|
||||
this.selected(true);
|
||||
} else {
|
||||
this.selected(false);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Add Buttons to controlBar
|
||||
_V_.merge(_V_.ControlBar.prototype.options.components, {
|
||||
"subtitlesButton": {},
|
||||
"captionsButton": {},
|
||||
"chaptersButton": {}
|
||||
});
|
||||
|
||||
// _V_.Cue = _V_.Component.extend({
|
||||
// init: function(player, options){
|
||||
// this._super(player, options);
|
||||
// }
|
||||
// });
|
@ -1,444 +0,0 @@
|
||||
/* VideoJS-SWF - Custom Flash Player with HTML5-ish API - https://github.com/zencoder/video-js-swf
|
||||
================================================================================ */
|
||||
_V_.flash = _V_.PlaybackTech.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this.player = player;
|
||||
|
||||
var source = options.source,
|
||||
|
||||
// Which element to embed in
|
||||
parentEl = options.parentEl,
|
||||
|
||||
// Create a temporary element to be replaced by swf object
|
||||
placeHolder = this.el = _V_.createElement("div", { id: parentEl.id + "_temp_flash" }),
|
||||
|
||||
// Generate ID for swf object
|
||||
objId = player.el.id+"_flash_api",
|
||||
|
||||
// Store player options in local var for optimization
|
||||
playerOptions = player.options,
|
||||
|
||||
// Merge default flashvars with ones passed in to init
|
||||
flashVars = _V_.merge({
|
||||
|
||||
// SWF Callback Functions
|
||||
readyFunction: "_V_.flash.onReady",
|
||||
eventProxyFunction: "_V_.flash.onEvent",
|
||||
errorEventProxyFunction: "_V_.flash.onError",
|
||||
|
||||
// Player Settings
|
||||
autoplay: playerOptions.autoplay,
|
||||
preload: playerOptions.preload,
|
||||
loop: playerOptions.loop,
|
||||
muted: playerOptions.muted
|
||||
|
||||
}, options.flashVars),
|
||||
|
||||
// Merge default parames with ones passed in
|
||||
params = _V_.merge({
|
||||
wmode: "opaque", // Opaque is needed to overlay controls, but can affect playback performance
|
||||
bgcolor: "#000000" // Using bgcolor prevents a white flash when the object is loading
|
||||
}, options.params),
|
||||
|
||||
// Merge default attributes with ones passed in
|
||||
attributes = _V_.merge({
|
||||
id: objId,
|
||||
name: objId, // Both ID and Name needed or swf to identifty itself
|
||||
'class': 'vjs-tech'
|
||||
}, options.attributes)
|
||||
;
|
||||
|
||||
// If source was supplied pass as a flash var.
|
||||
if (source) {
|
||||
flashVars.src = encodeURIComponent(_V_.getAbsoluteURL(source.src));
|
||||
}
|
||||
|
||||
// Add placeholder to player div
|
||||
_V_.insertFirst(placeHolder, parentEl);
|
||||
|
||||
// Having issues with Flash reloading on certain page actions (hide/resize/fullscreen) in certain browsers
|
||||
// This allows resetting the playhead when we catch the reload
|
||||
if (options.startTime) {
|
||||
this.ready(function(){
|
||||
this.load();
|
||||
this.play();
|
||||
this.currentTime(options.startTime);
|
||||
});
|
||||
}
|
||||
|
||||
// Flash iFrame Mode
|
||||
// In web browsers there are multiple instances where changing the parent element or visibility of a plugin causes the plugin to reload.
|
||||
// - Firefox just about always. https://bugzilla.mozilla.org/show_bug.cgi?id=90268 (might be fixed by version 13)
|
||||
// - Webkit when hiding the plugin
|
||||
// - Webkit and Firefox when using requestFullScreen on a parent element
|
||||
// Loading the flash plugin into a dynamically generated iFrame gets around most of these issues.
|
||||
// Issues that remain include hiding the element and requestFullScreen in Firefox specifically
|
||||
|
||||
// There's on particularly annoying issue with this method which is that Firefox throws a security error on an offsite Flash object loaded into a dynamically created iFrame.
|
||||
// Even though the iframe was inserted into a page on the web, Firefox + Flash considers it a local app trying to access an internet file.
|
||||
// I tried mulitple ways of setting the iframe src attribute but couldn't find a src that worked well. Tried a real/fake source, in/out of domain.
|
||||
// Also tried a method from stackoverflow that caused a security error in all browsers. http://stackoverflow.com/questions/2486901/how-to-set-document-domain-for-a-dynamically-generated-iframe
|
||||
// In the end the solution I found to work was setting the iframe window.location.href right before doing a document.write of the Flash object.
|
||||
// The only downside of this it seems to trigger another http request to the original page (no matter what's put in the href). Not sure why that is.
|
||||
|
||||
// NOTE (2012-01-29): Cannot get Firefox to load the remote hosted SWF into a dynamically created iFrame
|
||||
// Firefox 9 throws a security error, unleess you call location.href right before doc.write.
|
||||
// Not sure why that even works, but it causes the browser to look like it's continuously trying to load the page.
|
||||
// Firefox 3.6 keeps calling the iframe onload function anytime I write to it, causing an endless loop.
|
||||
|
||||
if (options.iFrameMode === true && !_V_.isFF) {
|
||||
|
||||
// Create iFrame with vjs-tech class so it's 100% width/height
|
||||
var iFrm = _V_.createElement("iframe", {
|
||||
id: objId + "_iframe",
|
||||
name: objId + "_iframe",
|
||||
className: "vjs-tech",
|
||||
scrolling: "no",
|
||||
marginWidth: 0,
|
||||
marginHeight: 0,
|
||||
frameBorder: 0
|
||||
});
|
||||
|
||||
// Update ready function names in flash vars for iframe window
|
||||
flashVars.readyFunction = "ready";
|
||||
flashVars.eventProxyFunction = "events";
|
||||
flashVars.errorEventProxyFunction = "errors";
|
||||
|
||||
// Tried multiple methods to get this to work in all browsers
|
||||
|
||||
// Tried embedding the flash object in the page first, and then adding a place holder to the iframe, then replacing the placeholder with the page object.
|
||||
// The goal here was to try to load the swf URL in the parent page first and hope that got around the firefox security error
|
||||
// var newObj = _V_.flash.embed(options.swf, placeHolder, flashVars, params, attributes);
|
||||
// (in onload)
|
||||
// var temp = _V_.createElement("a", { id:"asdf", innerHTML: "asdf" } );
|
||||
// iDoc.body.appendChild(temp);
|
||||
|
||||
// Tried embedding the flash object through javascript in the iframe source.
|
||||
// This works in webkit but still triggers the firefox security error
|
||||
// iFrm.src = "javascript: document.write('"+_V_.flash.getEmbedCode(options.swf, flashVars, params, attributes)+"');";
|
||||
|
||||
// Tried an actual local iframe just to make sure that works, but it kills the easiness of the CDN version if you require the user to host an iframe
|
||||
// We should add an option to host the iframe locally though, because it could help a lot of issues.
|
||||
// iFrm.src = "iframe.html";
|
||||
|
||||
// Wait until iFrame has loaded to write into it.
|
||||
_V_.addEvent(iFrm, "load", _V_.proxy(this, function(){
|
||||
|
||||
var iDoc, objTag, swfLoc,
|
||||
iWin = iFrm.contentWindow,
|
||||
varString = "";
|
||||
|
||||
|
||||
// The one working method I found was to use the iframe's document.write() to create the swf object
|
||||
// This got around the security issue in all browsers except firefox.
|
||||
// I did find a hack where if I call the iframe's window.location.href="", it would get around the security error
|
||||
// However, the main page would look like it was loading indefinitely (URL bar loading spinner would never stop)
|
||||
// Plus Firefox 3.6 didn't work no matter what I tried.
|
||||
// if (_V_.ua.match("Firefox")) {
|
||||
// iWin.location.href = "";
|
||||
// }
|
||||
|
||||
// Get the iFrame's document depending on what the browser supports
|
||||
iDoc = iFrm.contentDocument ? iFrm.contentDocument : iFrm.contentWindow.document;
|
||||
|
||||
// Tried ensuring both document domains were the same, but they already were, so that wasn't the issue.
|
||||
// Even tried adding /. that was mentioned in a browser security writeup
|
||||
// document.domain = document.domain+"/.";
|
||||
// iDoc.domain = document.domain+"/.";
|
||||
|
||||
// Tried adding the object to the iframe doc's innerHTML. Security error in all browsers.
|
||||
// iDoc.body.innerHTML = swfObjectHTML;
|
||||
|
||||
// Tried appending the object to the iframe doc's body. Security error in all browsers.
|
||||
// iDoc.body.appendChild(swfObject);
|
||||
|
||||
// Using document.write actually got around the security error that browsers were throwing.
|
||||
// Again, it's a dynamically generated (same domain) iframe, loading an external Flash swf.
|
||||
// Not sure why that's a security issue, but apparently it is.
|
||||
iDoc.write(_V_.flash.getEmbedCode(options.swf, flashVars, params, attributes));
|
||||
|
||||
// Setting variables on the window needs to come after the doc write because otherwise they can get reset in some browsers
|
||||
// So far no issues with swf ready event being called before it's set on the window.
|
||||
iWin.player = this.player;
|
||||
|
||||
// Create swf ready function for iFrame window
|
||||
iWin.ready = _V_.proxy(this.player, function(currSwf){
|
||||
var el = iDoc.getElementById(currSwf),
|
||||
player = this,
|
||||
tech = player.tech;
|
||||
|
||||
// Update reference to playback technology element
|
||||
tech.el = el;
|
||||
|
||||
// Now that the element is ready, make a click on the swf play the video
|
||||
_V_.addEvent(el, "click", tech.proxy(tech.onClick));
|
||||
|
||||
// Make sure swf is actually ready. Sometimes the API isn't actually yet.
|
||||
_V_.flash.checkReady(tech);
|
||||
});
|
||||
|
||||
// Create event listener for all swf events
|
||||
iWin.events = _V_.proxy(this.player, function(swfID, eventName, other){
|
||||
var player = this;
|
||||
if (player && player.techName == "flash") {
|
||||
player.triggerEvent(eventName);
|
||||
}
|
||||
});
|
||||
|
||||
// Create error listener for all swf errors
|
||||
iWin.errors = _V_.proxy(this.player, function(swfID, eventName){
|
||||
_V_.log("Flash Error", eventName);
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
// Replace placeholder with iFrame (it will load now)
|
||||
placeHolder.parentNode.replaceChild(iFrm, placeHolder);
|
||||
|
||||
// If not using iFrame mode, embed as normal object
|
||||
} else {
|
||||
_V_.flash.embed(options.swf, placeHolder, flashVars, params, attributes);
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function(){
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
},
|
||||
|
||||
// setupTriggers: function(){}, // Using global onEvent func to distribute events
|
||||
|
||||
play: function(){ this.el.vjs_play(); },
|
||||
pause: function(){ this.el.vjs_pause(); },
|
||||
src: function(src){
|
||||
// Make sure source URL is abosolute.
|
||||
src = _V_.getAbsoluteURL(src);
|
||||
|
||||
this.el.vjs_src(src);
|
||||
|
||||
// Currently the SWF doesn't autoplay if you load a source later.
|
||||
// e.g. Load player w/ no source, wait 2s, set src.
|
||||
if (this.player.autoplay()) {
|
||||
var tech = this;
|
||||
setTimeout(function(){ tech.play(); }, 0);
|
||||
}
|
||||
},
|
||||
load: function(){ this.el.vjs_load(); },
|
||||
poster: function(){ this.el.vjs_getProperty("poster"); },
|
||||
|
||||
buffered: function(){
|
||||
return _V_.createTimeRange(0, this.el.vjs_getProperty("buffered"));
|
||||
},
|
||||
|
||||
supportsFullScreen: function(){
|
||||
return false; // Flash does not allow fullscreen through javascript
|
||||
},
|
||||
enterFullScreen: function(){
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Create setters and getters for attributes
|
||||
(function(){
|
||||
|
||||
var api = _V_.flash.prototype,
|
||||
readWrite = "preload,currentTime,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted".split(","),
|
||||
readOnly = "error,currentSrc,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks".split(","),
|
||||
callOnly = "load,play,pause".split(",");
|
||||
// Overridden: buffered
|
||||
|
||||
createSetter = function(attr){
|
||||
var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
|
||||
api["set"+attrUpper] = function(val){ return this.el.vjs_setProperty(attr, val); };
|
||||
},
|
||||
|
||||
createGetter = function(attr){
|
||||
api[attr] = function(){ return this.el.vjs_getProperty(attr); };
|
||||
}
|
||||
;
|
||||
|
||||
// Create getter and setters for all read/write attributes
|
||||
_V_.each(readWrite, function(attr){
|
||||
createGetter(attr);
|
||||
createSetter(attr);
|
||||
});
|
||||
|
||||
// Create getters for read-only attributes
|
||||
_V_.each(readOnly, function(attr){
|
||||
createGetter(attr);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
/* Flash Support Testing -------------------------------------------------------- */
|
||||
|
||||
_V_.flash.isSupported = function(){
|
||||
return _V_.flash.version()[0] >= 10;
|
||||
// return swfobject.hasFlashPlayerVersion("10");
|
||||
};
|
||||
|
||||
_V_.flash.canPlaySource = function(srcObj){
|
||||
if (srcObj.type in _V_.flash.prototype.support.formats) { return "maybe"; }
|
||||
};
|
||||
|
||||
_V_.flash.prototype.support = {
|
||||
formats: {
|
||||
"video/flv": "FLV",
|
||||
"video/x-flv": "FLV",
|
||||
"video/mp4": "MP4",
|
||||
"video/m4v": "MP4"
|
||||
},
|
||||
|
||||
// Optional events that we can manually mimic with timers
|
||||
progressEvent: false,
|
||||
timeupdateEvent: false,
|
||||
|
||||
// Resizing plugins using request fullscreen reloads the plugin
|
||||
fullscreenResize: false,
|
||||
|
||||
// Resizing plugins in Firefox always reloads the plugin (e.g. full window mode)
|
||||
parentResize: !(_V_.ua.match("Firefox"))
|
||||
};
|
||||
|
||||
_V_.flash.onReady = function(currSwf){
|
||||
|
||||
var el = _V_.el(currSwf);
|
||||
|
||||
// Get player from box
|
||||
// On firefox reloads, el might already have a player
|
||||
var player = el.player || el.parentNode.player,
|
||||
tech = player.tech;
|
||||
|
||||
// Reference player on tech element
|
||||
el.player = player;
|
||||
|
||||
// Update reference to playback technology element
|
||||
tech.el = el;
|
||||
|
||||
// Now that the element is ready, make a click on the swf play the video
|
||||
tech.addEvent("click", tech.onClick);
|
||||
|
||||
_V_.flash.checkReady(tech);
|
||||
};
|
||||
|
||||
// The SWF isn't alwasy ready when it says it is. Sometimes the API functions still need to be added to the object.
|
||||
// If it's not ready, we set a timeout to check again shortly.
|
||||
_V_.flash.checkReady = function(tech){
|
||||
|
||||
// Check if API property exists
|
||||
if (tech.el.vjs_getProperty) {
|
||||
|
||||
// If so, tell tech it's ready
|
||||
tech.triggerReady();
|
||||
|
||||
// Otherwise wait longer.
|
||||
} else {
|
||||
|
||||
setTimeout(function(){
|
||||
_V_.flash.checkReady(tech);
|
||||
}, 50);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger events from the swf on the player
|
||||
_V_.flash.onEvent = function(swfID, eventName){
|
||||
var player = _V_.el(swfID).player;
|
||||
player.triggerEvent(eventName);
|
||||
};
|
||||
|
||||
// Log errors from the swf
|
||||
_V_.flash.onError = function(swfID, err){
|
||||
var player = _V_.el(swfID).player;
|
||||
player.triggerEvent("error");
|
||||
_V_.log("Flash Error", err, swfID);
|
||||
};
|
||||
|
||||
// Flash Version Check
|
||||
_V_.flash.version = function(){
|
||||
var version = '0,0,0';
|
||||
|
||||
// IE
|
||||
try {
|
||||
version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
|
||||
|
||||
// other browsers
|
||||
} catch(e) {
|
||||
try {
|
||||
if (navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
|
||||
version = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
|
||||
}
|
||||
} catch(e) {}
|
||||
}
|
||||
return version.split(",");
|
||||
};
|
||||
|
||||
// Flash embedding method. Only used in non-iframe mode
|
||||
_V_.flash.embed = function(swf, placeHolder, flashVars, params, attributes){
|
||||
var code = _V_.flash.getEmbedCode(swf, flashVars, params, attributes),
|
||||
|
||||
// Get element by embedding code and retrieving created element
|
||||
obj = _V_.createElement("div", { innerHTML: code }).childNodes[0],
|
||||
|
||||
par = placeHolder.parentNode
|
||||
;
|
||||
|
||||
placeHolder.parentNode.replaceChild(obj, placeHolder);
|
||||
|
||||
// IE6 seems to have an issue where it won't initialize the swf object after injecting it.
|
||||
// This is a dumb temporary fix
|
||||
if (_V_.isIE()) {
|
||||
var newObj = par.childNodes[0];
|
||||
setTimeout(function(){
|
||||
newObj.style.display = "block";
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
};
|
||||
|
||||
_V_.flash.getEmbedCode = function(swf, flashVars, params, attributes){
|
||||
|
||||
var objTag = '<object type="application/x-shockwave-flash"',
|
||||
flashVarsString = '',
|
||||
paramsString = '',
|
||||
attrsString = '';
|
||||
|
||||
// Convert flash vars to string
|
||||
if (flashVars) {
|
||||
_V_.eachProp(flashVars, function(key, val){
|
||||
flashVarsString += (key + "=" + val + "&");
|
||||
});
|
||||
}
|
||||
|
||||
// Add swf, flashVars, and other default params
|
||||
params = _V_.merge({
|
||||
movie: swf,
|
||||
flashvars: flashVarsString,
|
||||
allowScriptAccess: "always", // Required to talk to swf
|
||||
allowNetworking: "all" // All should be default, but having security issues.
|
||||
}, params);
|
||||
|
||||
// Create param tags string
|
||||
_V_.eachProp(params, function(key, val){
|
||||
paramsString += '<param name="'+key+'" value="'+val+'" />';
|
||||
});
|
||||
|
||||
attributes = _V_.merge({
|
||||
// Add swf to attributes (need both for IE and Others to work)
|
||||
data: swf,
|
||||
|
||||
// Default to 100% width/height
|
||||
width: "100%",
|
||||
height: "100%"
|
||||
|
||||
}, attributes);
|
||||
|
||||
// Create Attributes string
|
||||
_V_.eachProp(attributes, function(key, val){
|
||||
attrsString += (key + '="' + val + '" ');
|
||||
});
|
||||
|
||||
return objTag + attrsString + '>' + paramsString + '</object>';
|
||||
};
|
File diff suppressed because one or more lines are too long
@ -1,228 +0,0 @@
|
||||
/* HTML5 Playback Technology - Wrapper for HTML5 Media API
|
||||
================================================================================ */
|
||||
_V_.html5 = _V_.PlaybackTech.extend({
|
||||
|
||||
init: function(player, options, ready){
|
||||
this.player = player;
|
||||
this.el = this.createElement();
|
||||
this.ready(ready);
|
||||
|
||||
this.addEvent("click", this.proxy(this.onClick));
|
||||
|
||||
var source = options.source;
|
||||
|
||||
// If the element source is already set, we may have missed the loadstart event, and want to trigger it.
|
||||
// We don't want to set the source again and interrupt playback.
|
||||
if (source && this.el.currentSrc == source.src) {
|
||||
player.triggerEvent("loadstart");
|
||||
|
||||
// Otherwise set the source if one was provided.
|
||||
} else if (source) {
|
||||
this.el.src = source.src;
|
||||
}
|
||||
|
||||
// Chrome and Safari both have issues with autoplay.
|
||||
// In Safari (5.1.1), when we move the video element into the container div, autoplay doesn't work.
|
||||
// In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
|
||||
// This fixes both issues. Need to wait for API, so it updates displays correctly
|
||||
player.ready(function(){
|
||||
if (this.options.autoplay && this.paused()) {
|
||||
this.tag.poster = null; // Chrome Fix. Fixed in Chrome v16.
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.setupTriggers();
|
||||
|
||||
this.triggerReady();
|
||||
},
|
||||
|
||||
destroy: function(){
|
||||
this.player.tag = false;
|
||||
this.removeTriggers();
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
},
|
||||
|
||||
createElement: function(){
|
||||
var html5 = _V_.html5,
|
||||
player = this.player,
|
||||
|
||||
// If possible, reuse original tag for HTML5 playback technology element
|
||||
el = player.tag,
|
||||
newEl;
|
||||
|
||||
// Check if this browser supports moving the element into the box.
|
||||
// On the iPhone video will break if you move the element,
|
||||
// So we have to create a brand new element.
|
||||
if (!el || this.support.movingElementInDOM === false) {
|
||||
|
||||
// If the original tag is still there, remove it.
|
||||
if (el) {
|
||||
player.el.removeChild(el);
|
||||
}
|
||||
|
||||
newEl = _V_.createElement("video", {
|
||||
id: el.id || player.el.id + "_html5_api",
|
||||
className: el.className || "vjs-tech"
|
||||
});
|
||||
|
||||
el = newEl;
|
||||
_V_.insertFirst(el, player.el);
|
||||
}
|
||||
|
||||
// Update tag settings, in case they were overridden
|
||||
_V_.each(["autoplay","preload","loop","muted"], function(attr){ // ,"poster"
|
||||
if (player.options[attr] !== null) {
|
||||
el[attr] = player.options[attr];
|
||||
}
|
||||
}, this);
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
// Make video events trigger player events
|
||||
// May seem verbose here, but makes other APIs possible.
|
||||
setupTriggers: function(){
|
||||
_V_.each.call(this, _V_.html5.events, function(type){
|
||||
_V_.addEvent(this.el, type, _V_.proxy(this.player, this.eventHandler));
|
||||
});
|
||||
},
|
||||
removeTriggers: function(){
|
||||
_V_.each.call(this, _V_.html5.events, function(type){
|
||||
_V_.removeEvent(this.el, type, _V_.proxy(this.player, this.eventHandler));
|
||||
});
|
||||
},
|
||||
eventHandler: function(e){
|
||||
e.stopPropagation();
|
||||
this.triggerEvent(e);
|
||||
},
|
||||
|
||||
play: function(){ this.el.play(); },
|
||||
pause: function(){ this.el.pause(); },
|
||||
paused: function(){ return this.el.paused; },
|
||||
|
||||
currentTime: function(){ return this.el.currentTime; },
|
||||
setCurrentTime: function(seconds){
|
||||
try {
|
||||
this.el.currentTime = seconds;
|
||||
} catch(e) {
|
||||
_V_.log(e, "Video isn't ready. (VideoJS)");
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
}
|
||||
},
|
||||
|
||||
duration: function(){ return this.el.duration || 0; },
|
||||
buffered: function(){ return this.el.buffered; },
|
||||
|
||||
volume: function(){ return this.el.volume; },
|
||||
setVolume: function(percentAsDecimal){ this.el.volume = percentAsDecimal; },
|
||||
muted: function(){ return this.el.muted; },
|
||||
setMuted: function(muted){ this.el.muted = muted; },
|
||||
|
||||
width: function(){ return this.el.offsetWidth; },
|
||||
height: function(){ return this.el.offsetHeight; },
|
||||
|
||||
supportsFullScreen: function(){
|
||||
if (typeof this.el.webkitEnterFullScreen == 'function') {
|
||||
|
||||
// Seems to be broken in Chromium/Chrome && Safari in Leopard
|
||||
if (!navigator.userAgent.match("Chrome") && !navigator.userAgent.match("Mac OS X 10.5")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
enterFullScreen: function(){
|
||||
try {
|
||||
this.el.webkitEnterFullScreen();
|
||||
} catch (e) {
|
||||
if (e.code == 11) {
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
_V_.log("VideoJS: Video not ready.");
|
||||
}
|
||||
}
|
||||
},
|
||||
exitFullScreen: function(){
|
||||
try {
|
||||
this.el.webkitExitFullScreen();
|
||||
} catch (e) {
|
||||
if (e.code == 11) {
|
||||
// this.warning(VideoJS.warnings.videoNotReady);
|
||||
_V_.log("VideoJS: Video not ready.");
|
||||
}
|
||||
}
|
||||
},
|
||||
src: function(src){ this.el.src = src; },
|
||||
load: function(){ this.el.load(); },
|
||||
currentSrc: function(){ return this.el.currentSrc; },
|
||||
|
||||
preload: function(){ return this.el.preload; },
|
||||
setPreload: function(val){ this.el.preload = val; },
|
||||
autoplay: function(){ return this.el.autoplay; },
|
||||
setAutoplay: function(val){ this.el.autoplay = val; },
|
||||
loop: function(){ return this.el.loop; },
|
||||
setLoop: function(val){ this.el.loop = val; },
|
||||
|
||||
error: function(){ return this.el.error; },
|
||||
// networkState: function(){ return this.el.networkState; },
|
||||
// readyState: function(){ return this.el.readyState; },
|
||||
seeking: function(){ return this.el.seeking; },
|
||||
// initialTime: function(){ return this.el.initialTime; },
|
||||
// startOffsetTime: function(){ return this.el.startOffsetTime; },
|
||||
// played: function(){ return this.el.played; },
|
||||
// seekable: function(){ return this.el.seekable; },
|
||||
ended: function(){ return this.el.ended; },
|
||||
// videoTracks: function(){ return this.el.videoTracks; },
|
||||
// audioTracks: function(){ return this.el.audioTracks; },
|
||||
// videoWidth: function(){ return this.el.videoWidth; },
|
||||
// videoHeight: function(){ return this.el.videoHeight; },
|
||||
// textTracks: function(){ return this.el.textTracks; },
|
||||
// defaultPlaybackRate: function(){ return this.el.defaultPlaybackRate; },
|
||||
// playbackRate: function(){ return this.el.playbackRate; },
|
||||
// mediaGroup: function(){ return this.el.mediaGroup; },
|
||||
// controller: function(){ return this.el.controller; },
|
||||
controls: function(){ return this.player.options.controls; },
|
||||
defaultMuted: function(){ return this.el.defaultMuted; }
|
||||
});
|
||||
|
||||
/* HTML5 Support Testing -------------------------------------------------------- */
|
||||
|
||||
_V_.html5.isSupported = function(){
|
||||
return !!document.createElement("video").canPlayType;
|
||||
};
|
||||
|
||||
_V_.html5.canPlaySource = function(srcObj){
|
||||
return !!document.createElement("video").canPlayType(srcObj.type);
|
||||
// TODO: Check Type
|
||||
// If no Type, check ext
|
||||
// Check Media Type
|
||||
};
|
||||
|
||||
// List of all HTML5 events (various uses).
|
||||
_V_.html5.events = "loadstart,suspend,abort,error,emptied,stalled,loadedmetadata,loadeddata,canplay,canplaythrough,playing,waiting,seeking,seeked,ended,durationchange,timeupdate,progress,play,pause,ratechange,volumechange".split(",");
|
||||
|
||||
/* HTML5 Device Fixes ---------------------------------------------------------- */
|
||||
|
||||
_V_.html5.prototype.support = {
|
||||
|
||||
// Support for tech specific full screen. (webkitEnterFullScreen, not requestFullscreen)
|
||||
// http://developer.apple.com/library/safari/#documentation/AudioVideo/Reference/HTMLVideoElementClassReference/HTMLVideoElement/HTMLVideoElement.html
|
||||
// Seems to be broken in Chromium/Chrome && Safari in Leopard
|
||||
fullscreen: (typeof _V_.testVid.webkitEnterFullScreen !== undefined) ? (!_V_.ua.match("Chrome") && !_V_.ua.match("Mac OS X 10.5") ? true : false) : false,
|
||||
|
||||
// In iOS, if you move a video element in the DOM, it breaks video playback.
|
||||
movingElementInDOM: !_V_.isIOS()
|
||||
|
||||
};
|
||||
|
||||
// Android
|
||||
if (_V_.isAndroid()) {
|
||||
|
||||
// Override Android 2.2 and less canPlayType method which is broken
|
||||
if (_V_.androidVersion() < 3) {
|
||||
document.createElement("video").constructor.prototype.canPlayType = function(type){
|
||||
return (type && type.toLowerCase().indexOf("video/mp4") != -1) ? "maybe" : "";
|
||||
};
|
||||
}
|
||||
}
|
@ -1,603 +0,0 @@
|
||||
|
||||
var VimeoState = {
|
||||
UNSTARTED: -1,
|
||||
ENDED: 0,
|
||||
PLAYING: 1,
|
||||
PAUSED: 2,
|
||||
BUFFERING: 3
|
||||
};
|
||||
|
||||
/* VideoJS-Vimeo - Vimeo iFrame Wrapper
|
||||
================================================================================ */
|
||||
_V_.vimeo = _V_.PlaybackTech.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this.player = player;
|
||||
|
||||
var source = options.source;
|
||||
|
||||
// Extract the Vimeo videoID from the source
|
||||
var videoId = this.getVideoId(source.src);
|
||||
|
||||
// Which element to embed in
|
||||
var parentEl = options.parentEl;
|
||||
|
||||
// Generate ID for iFrame
|
||||
var objId = player.el.id+"_vimeo_api";
|
||||
|
||||
// Create an iFrame for the Vimeo player
|
||||
var iFrm = this.el = _V_.createElement("iframe", {
|
||||
id: objId + "_iframe",
|
||||
name: objId + "_iframe",
|
||||
className: "vjs-tech",
|
||||
scrolling: "no",
|
||||
marginWidth: 0,
|
||||
marginHeight: 0,
|
||||
frameBorder: 0,
|
||||
webkitAllowFullScreen: "",
|
||||
mozallowfullscreen: "",
|
||||
allowFullScreen: ""
|
||||
});
|
||||
|
||||
var playerOptions = player.options;
|
||||
var optionsParams = options.params || {};
|
||||
|
||||
// Setup player parameters
|
||||
this.player.apiArgs = {
|
||||
api: 1,
|
||||
byline: 0,
|
||||
portrait: 0,
|
||||
show_title: 0,
|
||||
show_byline: 0,
|
||||
show_portrait: 0,
|
||||
fullscreen: 1,
|
||||
player_id: objId + "_iframe",
|
||||
color: optionsParams.color || playerOptions.color || 'ffffff',
|
||||
autoplay: this.toBoolInt(optionsParams.autoplay || playerOptions.autoplay),
|
||||
loop: this.toBoolInt(optionsParams.loop || playerOptions.loop)
|
||||
};
|
||||
|
||||
// Create a dummy object to hold Vimeo state in case any info is requested
|
||||
// before the iFrame loads
|
||||
this.player.vimeoInfo = {};
|
||||
|
||||
// Add iFrame to player div
|
||||
_V_.insertFirst(iFrm, parentEl);
|
||||
|
||||
this.loadPlayer(videoId);
|
||||
},
|
||||
|
||||
loadPlayer: function(videoId){
|
||||
var baseUrl = (document.location.protocol == 'https:') ?
|
||||
'https://secure.vimeo.com/video/' :
|
||||
'http://player.vimeo.com/video/';
|
||||
|
||||
// Wait until iFrame has loaded to initialize the API
|
||||
_V_.addEvent(this.el, "load", _V_.proxy(this, function(){
|
||||
// Initialize the Vimeo Player object
|
||||
this.vimeo = $f(this.el);
|
||||
|
||||
// Create an object to track the state of the Vimeo player, since we can
|
||||
// only fetch information from the iFrame asynchronously
|
||||
this.player.vimeoInfo = {
|
||||
state: VimeoState.UNSTARTED,
|
||||
volume: 1,
|
||||
muted: false,
|
||||
muteVolume: 1,
|
||||
time: 0,
|
||||
duration: 0,
|
||||
buffered: 0,
|
||||
url: baseUrl + videoId,
|
||||
error: null
|
||||
};
|
||||
|
||||
// Register Vimeo event handlers
|
||||
this.vimeo.addEvent('ready', _V_.vimeo.onReady);
|
||||
this.vimeo.addEvent('loadProgress', _V_.vimeo.onLoadProgress);
|
||||
this.vimeo.addEvent('playProgress', _V_.vimeo.onPlayProgress);
|
||||
this.vimeo.addEvent('play', _V_.vimeo.onPlay);
|
||||
this.vimeo.addEvent('pause', _V_.vimeo.onPause);
|
||||
this.vimeo.addEvent('finish', _V_.vimeo.onFinish);
|
||||
this.vimeo.addEvent('seek', _V_.vimeo.onSeek);
|
||||
}));
|
||||
|
||||
// Set the iFrame URL to start loading the video
|
||||
this.el.src = baseUrl + videoId + "?" + this.makeQueryString(this.player.apiArgs);
|
||||
},
|
||||
|
||||
destroy: function(){
|
||||
this.vimeo.api("unload");
|
||||
delete this.vimeo;
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
},
|
||||
|
||||
play: function(){ this.vimeo.api("play"); },
|
||||
pause: function(){ this.vimeo.api("pause"); },
|
||||
paused: function(){
|
||||
var state = this.player.vimeoInfo.state;
|
||||
return state !== VimeoState.PLAYING &&
|
||||
state !== VimeoState.BUFFERING;
|
||||
},
|
||||
|
||||
src: function(src){
|
||||
var videoId = this.getVideoId(src);
|
||||
this.loadPlayer(videoId);
|
||||
},
|
||||
load: function(){ },
|
||||
poster: function(){
|
||||
// We could fetch the poster image using JSONP, but it would need to be
|
||||
// done ahead of time (and probably enabled only through a player param)
|
||||
return null;
|
||||
},
|
||||
|
||||
currentTime: function(){ return this.player.vimeoInfo.time || 0; },
|
||||
setCurrentTime: function(seconds){ this.vimeo.api("seekTo", seconds); },
|
||||
|
||||
duration: function(){ return this.player.vimeoInfo.duration || 0; },
|
||||
buffered: function(){
|
||||
return _V_.createTimeRange(0, this.player.vimeoInfo.buffered || 0);
|
||||
},
|
||||
|
||||
volume: function(){
|
||||
return (this.player.vimeoInfo.muted) ?
|
||||
this.player.vimeoInfo.muteVolume :
|
||||
this.player.vimeoInfo.volume;
|
||||
},
|
||||
setVolume: function(percentAsDecimal){
|
||||
this.vimeo.api("setVolume", percentAsDecimal);
|
||||
this.player.vimeoInfo.volume = percentAsDecimal;
|
||||
this.player.triggerEvent("volumechange");
|
||||
},
|
||||
muted: function(){ return this.player.vimeoInfo.muted || false; },
|
||||
setMuted: function(muted){
|
||||
if (muted) {
|
||||
this.player.vimeoInfo.muteVolume = this.player.vimeoInfo.volume;
|
||||
this.setVolume(0);
|
||||
} else {
|
||||
this.setVolume(this.player.vimeoInfo.muteVolume);
|
||||
}
|
||||
this.player.vimeoInfo.muted = muted;
|
||||
this.player.triggerEvent("volumechange");
|
||||
},
|
||||
|
||||
width: function(){ return this.el.offsetWidth; },
|
||||
height: function(){ return this.el.offsetHeight; },
|
||||
|
||||
currentSrc: function(){ return this.player.vimeoInfo.url; },
|
||||
|
||||
preload: function(){ return false; },
|
||||
setPreload: function(val){ },
|
||||
autoplay: function(){ return !!this.player.apiArgs.autoplay; },
|
||||
setAutoplay: function(val){ },
|
||||
loop: function(){ return !!this.player.apiArgs.loop; },
|
||||
setLoop: function(val){
|
||||
this.player.apiArgs.loop = (val ? 1 : 0);
|
||||
// We handle looping manually
|
||||
//this.vimeo.api("setLoop", val);
|
||||
},
|
||||
|
||||
supportsFullScreen: function(){ return false; },
|
||||
enterFullScreen: function(){ return false; },
|
||||
|
||||
error: function(){ return this.player.vimeoInfo.error; },
|
||||
seeking: function(){ return false; },
|
||||
ended: function(){ return this.player.vimeoInfo.state === VimeoState.ENDED; },
|
||||
videoWidth: function(){ return this.width(); },
|
||||
videoHeight: function(){ return this.height(); },
|
||||
controls: function(){ return this.player.options.controls; },
|
||||
defaultMuted: function(){ return false; },
|
||||
|
||||
// Helpers ------------------------------------------------------------------
|
||||
|
||||
makeQueryString: function(args) {
|
||||
var array = [];
|
||||
for (var key in args) {
|
||||
if (args.hasOwnProperty(key))
|
||||
array.push(encodeURIComponent(key) + "=" + encodeURIComponent(args[key]));
|
||||
}
|
||||
return array.join("&");
|
||||
},
|
||||
|
||||
getVideoId: function(url) {
|
||||
return url.match(/vimeo\.com\/(?:.*#|.*\/videos\/)?([0-9]+)/)[1];
|
||||
},
|
||||
|
||||
toBoolInt: function(val) {
|
||||
return val ? 1 : 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Event callbacks ------------------------------------------------------------
|
||||
|
||||
_V_.vimeo.onReady = function(id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.tech.triggerReady();
|
||||
player.triggerReady();
|
||||
player.triggerEvent("canplay");
|
||||
_V_.vimeo.hideOverlay(player);
|
||||
|
||||
// Hide our playback controls since we have no good way of hiding the Vimeo
|
||||
// controls
|
||||
player.controlBar.hide();
|
||||
};
|
||||
|
||||
_V_.vimeo.onLoadProgress = function(data, id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
var durationUpdate = !player.vimeoInfo.duration;
|
||||
player.vimeoInfo.duration = data.duration;
|
||||
player.vimeoInfo.buffered = data.percent;
|
||||
player.triggerEvent("progress");
|
||||
if (durationUpdate) player.triggerEvent("durationchange");
|
||||
};
|
||||
|
||||
_V_.vimeo.onPlayProgress = function(data, id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.vimeoInfo.time = data.seconds;
|
||||
player.triggerEvent("timeupdate");
|
||||
};
|
||||
|
||||
_V_.vimeo.onPlay = function(id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.vimeoInfo.state = VimeoState.PLAYING;
|
||||
player.triggerEvent("play");
|
||||
};
|
||||
|
||||
_V_.vimeo.onPause = function(id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.vimeoInfo.state = VimeoState.PAUSED;
|
||||
player.triggerEvent("pause");
|
||||
};
|
||||
|
||||
_V_.vimeo.onFinish = function(id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.vimeoInfo.state = VimeoState.ENDED;
|
||||
player.triggerEvent("ended");
|
||||
_V_.vimeo.hideOverlay(player);
|
||||
|
||||
// Vimeo looping doesn't seem to play well with VideoJS, so we need to
|
||||
// implement it manually here
|
||||
if (player.apiArgs.loop) {
|
||||
//player.tech.vimeo.api("seekTo", 0);
|
||||
player.tech.vimeo.api("play");
|
||||
} else {
|
||||
// Reset the video
|
||||
player.tech.vimeo.api("seekTo", 0);
|
||||
player.tech.vimeo.api("play");
|
||||
player.tech.vimeo.api("pause");
|
||||
}
|
||||
};
|
||||
|
||||
_V_.vimeo.onSeek = function(data, id) {
|
||||
var player = _V_.el(id).parentNode.player;
|
||||
player.vimeoInfo.time = data.seconds;
|
||||
player.triggerEvent("timeupdate");
|
||||
player.triggerEvent("seeked");
|
||||
};
|
||||
|
||||
// Helpers --------------------------------------------------------------------
|
||||
|
||||
_V_.vimeo.hideOverlay = function(player) {
|
||||
// Hide the big play button and poster since Vimeo provides these. Using
|
||||
// our own prevents the video from playing on the first click in mobile
|
||||
// devices
|
||||
player.bigPlayButton.hide();
|
||||
player.posterImage.hide();
|
||||
};
|
||||
|
||||
// Support testing ------------------------------------------------------------
|
||||
|
||||
_V_.vimeo.isSupported = function(){
|
||||
return true;
|
||||
};
|
||||
|
||||
_V_.vimeo.canPlaySource = function(srcObj){
|
||||
return srcObj.type == "video/vimeo";
|
||||
};
|
||||
|
||||
_V_.vimeo.prototype.support = {
|
||||
formats: {
|
||||
"video/vimeo": "VIM"
|
||||
},
|
||||
|
||||
// Optional events that we can manually mimic with timers
|
||||
progressEvent: true,
|
||||
timeupdateEvent: true,
|
||||
|
||||
//fullscreen: true,
|
||||
// In iOS, if you move a video element in the DOM, it breaks video playback.
|
||||
movingElementInDOM: !_V_.isIOS(),
|
||||
|
||||
fullscreenResize: true,
|
||||
parentResize: true
|
||||
};
|
||||
|
||||
// Froogaloop API -------------------------------------------------------------
|
||||
|
||||
// From https://github.com/vimeo/player-api/blob/master/javascript/froogaloop.js
|
||||
var Froogaloop = (function(){
|
||||
// Define a local copy of Froogaloop
|
||||
function Froogaloop(iframe) {
|
||||
// The Froogaloop object is actually just the init constructor
|
||||
return new Froogaloop.fn.init(iframe);
|
||||
}
|
||||
|
||||
var eventCallbacks = {},
|
||||
hasWindowEvent = false,
|
||||
isReady = false,
|
||||
slice = Array.prototype.slice,
|
||||
playerDomain = '';
|
||||
|
||||
Froogaloop.fn = Froogaloop.prototype = {
|
||||
element: null,
|
||||
|
||||
init: function(iframe) {
|
||||
if (typeof iframe === "string") {
|
||||
iframe = document.getElementById(iframe);
|
||||
}
|
||||
|
||||
this.element = iframe;
|
||||
|
||||
// Register message event listeners
|
||||
playerDomain = getDomainFromUrl(this.element.getAttribute('src'));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/*
|
||||
* Calls a function to act upon the player.
|
||||
*
|
||||
* @param {string} method The name of the Javascript API method to call. Eg: 'play'.
|
||||
* @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method
|
||||
* or callback function when the method returns a value.
|
||||
*/
|
||||
api: function(method, valueOrCallback) {
|
||||
if (!this.element || !method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
element = self.element,
|
||||
target_id = element.id !== '' ? element.id : null,
|
||||
params = !isFunction(valueOrCallback) ? valueOrCallback : null,
|
||||
callback = isFunction(valueOrCallback) ? valueOrCallback : null;
|
||||
|
||||
// Store the callback for get functions
|
||||
if (callback) {
|
||||
storeCallback(method, callback, target_id);
|
||||
}
|
||||
|
||||
postMessage(method, params, element);
|
||||
return self;
|
||||
},
|
||||
|
||||
/*
|
||||
* Registers an event listener and a callback function that gets called when the event fires.
|
||||
*
|
||||
* @param eventName (String): Name of the event to listen for.
|
||||
* @param callback (Function): Function that should be called when the event fires.
|
||||
*/
|
||||
addEvent: function(eventName, callback) {
|
||||
if (!this.element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
element = self.element,
|
||||
target_id = element.id !== '' ? element.id : null;
|
||||
|
||||
|
||||
storeCallback(eventName, callback, target_id);
|
||||
|
||||
// The ready event is not registered via postMessage. It fires regardless.
|
||||
if (eventName != 'ready') {
|
||||
postMessage('addEventListener', eventName, element);
|
||||
}
|
||||
else if (eventName == 'ready' && isReady) {
|
||||
callback.call(null, target_id);
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
|
||||
/*
|
||||
* Unregisters an event listener that gets called when the event fires.
|
||||
*
|
||||
* @param eventName (String): Name of the event to stop listening for.
|
||||
*/
|
||||
removeEvent: function(eventName) {
|
||||
if (!this.element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var self = this,
|
||||
element = self.element,
|
||||
target_id = element.id !== '' ? element.id : null,
|
||||
removed = removeCallback(eventName, target_id);
|
||||
|
||||
// The ready event is not registered
|
||||
if (eventName != 'ready' && removed) {
|
||||
postMessage('removeEventListener', eventName, element);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles posting a message to the parent window.
|
||||
*
|
||||
* @param method (String): name of the method to call inside the player. For api calls
|
||||
* this is the name of the api method (api_play or api_pause) while for events this method
|
||||
* is api_addEventListener.
|
||||
* @param params (Object or Array): List of parameters to submit to the method. Can be either
|
||||
* a single param or an array list of parameters.
|
||||
* @param target (HTMLElement): Target iframe to post the message to.
|
||||
*/
|
||||
function postMessage(method, params, target) {
|
||||
if (!target.contentWindow.postMessage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = target.getAttribute('src').split('?')[0],
|
||||
data = JSON.stringify({
|
||||
method: method,
|
||||
value: params
|
||||
});
|
||||
|
||||
if (url.substr(0, 2) === '//') {
|
||||
url = window.location.protocol + url;
|
||||
}
|
||||
|
||||
target.contentWindow.postMessage(data, url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event that fires whenever the window receives a message from its parent
|
||||
* via window.postMessage.
|
||||
*/
|
||||
function onMessageReceived(event) {
|
||||
var data, method;
|
||||
|
||||
try {
|
||||
data = JSON.parse(event.data);
|
||||
method = data.event || data.method;
|
||||
}
|
||||
catch(e) {
|
||||
//fail silently... like a ninja!
|
||||
}
|
||||
|
||||
if (method == 'ready' && !isReady) {
|
||||
isReady = true;
|
||||
}
|
||||
|
||||
// Handles messages from moogaloop only
|
||||
if (event.origin != playerDomain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = data.value,
|
||||
eventData = data.data,
|
||||
target_id = target_id === '' ? null : data.player_id,
|
||||
|
||||
callback = getCallback(method, target_id),
|
||||
params = [];
|
||||
|
||||
if (!callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value !== undefined) {
|
||||
params.push(value);
|
||||
}
|
||||
|
||||
if (eventData) {
|
||||
params.push(eventData);
|
||||
}
|
||||
|
||||
if (target_id) {
|
||||
params.push(target_id);
|
||||
}
|
||||
|
||||
return params.length > 0 ? callback.apply(null, params) : callback.call();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stores submitted callbacks for each iframe being tracked and each
|
||||
* event for that iframe.
|
||||
*
|
||||
* @param eventName (String): Name of the event. Eg. api_onPlay
|
||||
* @param callback (Function): Function that should get executed when the
|
||||
* event is fired.
|
||||
* @param target_id (String) [Optional]: If handling more than one iframe then
|
||||
* it stores the different callbacks for different iframes based on the iframe's
|
||||
* id.
|
||||
*/
|
||||
function storeCallback(eventName, callback, target_id) {
|
||||
if (target_id) {
|
||||
if (!eventCallbacks[target_id]) {
|
||||
eventCallbacks[target_id] = {};
|
||||
}
|
||||
eventCallbacks[target_id][eventName] = callback;
|
||||
}
|
||||
else {
|
||||
eventCallbacks[eventName] = callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves stored callbacks.
|
||||
*/
|
||||
function getCallback(eventName, target_id) {
|
||||
if (target_id) {
|
||||
return eventCallbacks[target_id][eventName];
|
||||
}
|
||||
else {
|
||||
return eventCallbacks[eventName];
|
||||
}
|
||||
}
|
||||
|
||||
function removeCallback(eventName, target_id) {
|
||||
if (target_id && eventCallbacks[target_id]) {
|
||||
if (!eventCallbacks[target_id][eventName]) {
|
||||
return false;
|
||||
}
|
||||
eventCallbacks[target_id][eventName] = null;
|
||||
}
|
||||
else {
|
||||
if (!eventCallbacks[eventName]) {
|
||||
return false;
|
||||
}
|
||||
eventCallbacks[eventName] = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a domain's root domain.
|
||||
* Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted
|
||||
*
|
||||
* @param url (String): Url to test against.
|
||||
* @return url (String): Root domain of submitted url
|
||||
*/
|
||||
function getDomainFromUrl(url) {
|
||||
if (url.substr(0, 2) === '//') {
|
||||
url = window.location.protocol + url;
|
||||
}
|
||||
|
||||
var url_pieces = url.split('/'),
|
||||
domain_str = '';
|
||||
|
||||
for(var i = 0, length = url_pieces.length; i < length; i++) {
|
||||
if(i<3) {domain_str += url_pieces[i];}
|
||||
else {break;}
|
||||
if(i<2) {domain_str += '/';}
|
||||
}
|
||||
|
||||
return domain_str;
|
||||
}
|
||||
|
||||
function isFunction(obj) {
|
||||
return !!(obj && obj.constructor && obj.call && obj.apply);
|
||||
}
|
||||
|
||||
function isArray(obj) {
|
||||
return toString.call(obj) === '[object Array]';
|
||||
}
|
||||
|
||||
// Give the init function the Froogaloop prototype for later instantiation
|
||||
Froogaloop.fn.init.prototype = Froogaloop.fn;
|
||||
|
||||
// Listens for the message event.
|
||||
// W3C
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener('message', onMessageReceived, false);
|
||||
}
|
||||
// IE
|
||||
else {
|
||||
window.attachEvent('onmessage', onMessageReceived);
|
||||
}
|
||||
|
||||
// Expose froogaloop to the global object
|
||||
return (window.Froogaloop = window.$f = Froogaloop);
|
||||
|
||||
})();
|
@ -1,39 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>YouTube Test</title>
|
||||
|
||||
<link href="../../design/video-js.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<!--[if IE]>
|
||||
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
|
||||
<!--<![endif]-->
|
||||
|
||||
<script src="../../src/core.js"></script>
|
||||
<script src="../../src/lib.js"></script>
|
||||
<script src="../../src/json.js"></script>
|
||||
|
||||
<script src="../../src/component.js"></script>
|
||||
<script src="../../src/player.js"></script>
|
||||
<script src="../../src/tech.js"></script>
|
||||
<script src="../../src/controls.js"></script>
|
||||
<script src="../../src/events.js"></script>
|
||||
<script src="../../src/tracks.js"></script>
|
||||
|
||||
<script src="../../tech/html5/html5.js"></script>
|
||||
<script src="../../tech/flash/flash.js"></script>
|
||||
|
||||
<script src="../../tech/youtube/youtube.js"></script>
|
||||
|
||||
<script src="../../src/setup.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<video id="example_video_1" class="video-js vjs-default-skin" controls width="640" height="264" data-setup='{"techOrder":["youtube","html5"]}'>
|
||||
<source src="http://www.youtube.com/watch?v=9bZkp7q19f0" type='video/youtube'>
|
||||
</video>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,369 +0,0 @@
|
||||
|
||||
/* VideoJS-YouTube - YouTube iFrame Wrapper
|
||||
================================================================================ */
|
||||
_V_.youtube = _V_.PlaybackTech.extend({
|
||||
|
||||
init: function(player, options){
|
||||
this.player = player;
|
||||
|
||||
var source = options.source;
|
||||
|
||||
// Extract the YouTube videoID from the source
|
||||
var videoId = this.getVideoId(source.src);
|
||||
|
||||
// Which element to embed in
|
||||
var parentEl = options.parentEl;
|
||||
|
||||
// Generate ID for iFrame
|
||||
var objId = player.el.id+"_youtube_api";
|
||||
|
||||
// Create an iFrame for the YouTube player
|
||||
var iFrm = this.el = _V_.createElement("iframe", {
|
||||
id: objId + "_iframe",
|
||||
name: objId + "_iframe",
|
||||
className: "vjs-tech",
|
||||
scrolling: "no",
|
||||
marginWidth: 0,
|
||||
marginHeight: 0,
|
||||
frameBorder: 0,
|
||||
webkitAllowFullScreen: "",
|
||||
mozallowfullscreen: "",
|
||||
allowFullScreen: ""
|
||||
});
|
||||
|
||||
// Store a global list of currently loading players
|
||||
_V_.youtube.loadingEls = _V_.youtube.loadingEls || [];
|
||||
_V_.youtube.loadingEls.push(parentEl);
|
||||
|
||||
var playerOptions = player.options;
|
||||
var optionsParams = options.params || {};
|
||||
|
||||
// Setup player parameters
|
||||
var params = {
|
||||
disablekb: 1,
|
||||
enablejsapi: 1,
|
||||
iv_load_policy: 3,
|
||||
modestbranding: 1,
|
||||
playerapiid: objId,
|
||||
wmode: "opaque", // Opaque is needed to overlay controls, but can affect playback performance (Flash only)
|
||||
rel: 0,
|
||||
showinfo: 0,
|
||||
showsearch: 0,
|
||||
controls: this.toBoolInt(optionsParams.ytcontrols || playerOptions.ytcontrols),
|
||||
autoplay: this.toBoolInt(optionsParams.autoplay || playerOptions.autoplay),
|
||||
loop: this.toBoolInt(optionsParams.loop || playerOptions.loop),
|
||||
hd: this.toBoolInt(optionsParams.hd || playerOptions.hd)
|
||||
};
|
||||
|
||||
var p = (document.location.protocol == 'https:') ? 'https:' : 'http:';
|
||||
|
||||
if (document.domain != 'localhost' && document.location.protocol != 'file:')
|
||||
params.origin = p + "//" + document.domain;
|
||||
|
||||
this.player.apiArgs = {
|
||||
videoId: videoId,
|
||||
playerVars: params,
|
||||
events: {
|
||||
"onReady": _V_.youtube.onReady,
|
||||
"onStateChange": _V_.youtube.onStateChange,
|
||||
"onPlaybackQualityChange": _V_.youtube.onPlaybackQualityChange,
|
||||
"onError": _V_.youtube.onError
|
||||
}
|
||||
};
|
||||
|
||||
_V_.addEvent(parentEl, "techready", _V_.proxy(this, function(){
|
||||
// YouTube JS API is ready, load the player
|
||||
iFrm.src = p + "//www.youtube.com/embed/" + videoId + "?" +
|
||||
this.makeQueryString(params);
|
||||
// Initialize the YouTube Player object. Only pass events as arguments,
|
||||
// since all of our other parameters went into the iFrame URL
|
||||
this.youtube = new YT.Player(iFrm, { events: this.player.apiArgs.events });
|
||||
}));
|
||||
|
||||
// Add iFrame to player div
|
||||
_V_.insertFirst(iFrm, parentEl);
|
||||
|
||||
_V_.youtube.updateVideoQuality(this.player, null);
|
||||
|
||||
this.loadApi();
|
||||
},
|
||||
|
||||
destroy: function(){
|
||||
this.el.parentNode.removeChild(this.el);
|
||||
this.youtube.destroy();
|
||||
delete this.youtube;
|
||||
},
|
||||
|
||||
play: function(){ this.youtube.playVideo(); },
|
||||
pause: function(){ this.youtube.pauseVideo(); },
|
||||
paused: function(){
|
||||
var state = this.youtube.getPlayerState();
|
||||
return state !== YT.PlayerState.PLAYING &&
|
||||
state !== YT.PlayerState.BUFFERING;
|
||||
},
|
||||
|
||||
src: function(src){
|
||||
delete this.player.error;
|
||||
|
||||
// FIXME: Does this work or do we have to set the iFrame src again?
|
||||
var videoId = this.getVideoId(src);
|
||||
this.youtube.loadVideoById(videoId);
|
||||
},
|
||||
load: function(){ },
|
||||
poster: function(){
|
||||
var videoId = this.getVideoId(this.youtube.getVideoUrl());
|
||||
return "http://img.youtube.com/vi/" + videoId + "/0.jpg";
|
||||
},
|
||||
|
||||
currentTime: function(){ return this.youtube.getCurrentTime() || 0; },
|
||||
setCurrentTime: function(seconds){
|
||||
this.youtube.seekTo(seconds, true);
|
||||
this.player.triggerEvent("timeupdate");
|
||||
},
|
||||
|
||||
duration: function(){ return this.youtube.getDuration() || 0; },
|
||||
buffered: function(){
|
||||
var loadedBytes = this.youtube.getVideoBytesLoaded();
|
||||
var totalBytes = this.youtube.getVideoBytesTotal();
|
||||
if (!loadedBytes || !totalBytes) return 0;
|
||||
|
||||
var duration = this.youtube.getDuration();
|
||||
var secondsBuffered = (loadedBytes / totalBytes) * duration;
|
||||
var secondsOffset = (this.youtube.getVideoStartBytes() / totalBytes) * duration;
|
||||
return _V_.createTimeRange(secondsOffset, secondsOffset + secondsBuffered);
|
||||
},
|
||||
|
||||
volume: function(){
|
||||
if (isNaN(this.youtube.volumeVal))
|
||||
this.youtube.volumeVal = this.youtube.getVolume() / 100.0;
|
||||
return this.youtube.volumeVal;
|
||||
},
|
||||
setVolume: function(percentAsDecimal){
|
||||
if (percentAsDecimal != this.youtube.volumeVal) {
|
||||
this.youtube.volumeVal = percentAsDecimal;
|
||||
this.youtube.setVolume(percentAsDecimal * 100.0);
|
||||
this.player.triggerEvent("volumechange");
|
||||
}
|
||||
},
|
||||
muted: function(){ return this.youtube.isMuted(); },
|
||||
setMuted: function(muted){
|
||||
if (muted)
|
||||
this.youtube.mute();
|
||||
else
|
||||
this.youtube.unMute();
|
||||
|
||||
// Volume changes do not show up in the API immediately, so we need
|
||||
// to wait for a moment
|
||||
var self = this;
|
||||
setTimeout(function() { self.player.triggerEvent("volumechange"); }, 50);
|
||||
},
|
||||
|
||||
width: function(){ return this.el.offsetWidth; },
|
||||
height: function(){ return this.el.offsetHeight; },
|
||||
|
||||
currentSrc: function(){ return this.youtube.getVideoUrl(); },
|
||||
|
||||
preload: function(){ return false; },
|
||||
setPreload: function(val){ },
|
||||
autoplay: function(){ return !!this.player.apiArgs.playerVars.autoplay; },
|
||||
setAutoplay: function(val){ },
|
||||
loop: function(){ return !!this.player.apiArgs.playerVars.loop; },
|
||||
setLoop: function(val){
|
||||
this.player.apiArgs.playerVars.loop = (val ? 1 : 0);
|
||||
// We handle looping manually
|
||||
//this.youtube.setLoop(val);
|
||||
},
|
||||
|
||||
supportsFullScreen: function(){ return false; },
|
||||
enterFullScreen: function(){ return false; },
|
||||
|
||||
error: function(){ return this.player.error; },
|
||||
seeking: function(){ return false; },
|
||||
ended: function(){ return this.youtube.getPlayerState() === YT.PlayerState.ENDED; },
|
||||
videoWidth: function(){ return this.player.videoWidth; },
|
||||
videoHeight: function(){ return this.player.videoHeight; },
|
||||
controls: function(){ return this.player.options.controls; },
|
||||
defaultMuted: function(){ return false; },
|
||||
|
||||
// Helpers ------------------------------------------------------------------
|
||||
|
||||
makeQueryString: function(args) {
|
||||
var array = [];
|
||||
for (var key in args) {
|
||||
if (args.hasOwnProperty(key))
|
||||
array.push(encodeURIComponent(key) + "=" + encodeURIComponent(args[key]));
|
||||
}
|
||||
return array.join("&");
|
||||
},
|
||||
|
||||
getVideoId: function(url) {
|
||||
return url.match(/v=([^&]+)/)[1];
|
||||
},
|
||||
|
||||
toBoolInt: function(val) {
|
||||
return val ? 1 : 0;
|
||||
},
|
||||
|
||||
loadApi: function() {
|
||||
// Check if the YouTube JS API has already been loaded
|
||||
var js, id = "youtube-jssdk", ref = document.getElementsByTagName("script")[0];
|
||||
if (_V_.el(id)) {
|
||||
window.onYouTubePlayerAPIReady();
|
||||
return;
|
||||
}
|
||||
|
||||
// Asynchronously load the YouTube JS API
|
||||
var p = (document.location.protocol == "https:") ? "https:" : "http:";
|
||||
js = _V_.createElement("script", { id: id, async: true, src: p + "//www.youtube.com/player_api" });
|
||||
ref.parentNode.insertBefore(js, ref);
|
||||
}
|
||||
});
|
||||
|
||||
// Event callbacks ------------------------------------------------------------
|
||||
|
||||
_V_.youtube.onReady = function(e){
|
||||
var player = e.target.getIframe().parentNode.player;
|
||||
|
||||
player.tech.triggerReady();
|
||||
player.triggerReady();
|
||||
player.triggerEvent("durationchange");
|
||||
|
||||
_V_.youtube.hideOverlay(player);
|
||||
};
|
||||
|
||||
_V_.youtube.onStateChange = function(e){
|
||||
var player = e.target.getIframe().parentNode.player;
|
||||
|
||||
// Suppress any duplicate events from YouTube
|
||||
if (player.lastState === e.data)
|
||||
return;
|
||||
|
||||
switch (e.data) {
|
||||
case -1: // Unstarted
|
||||
player.triggerEvent("durationchange");
|
||||
break;
|
||||
case YT.PlayerState.CUED:
|
||||
break;
|
||||
case YT.PlayerState.ENDED:
|
||||
player.triggerEvent("ended");
|
||||
_V_.youtube.hideOverlay(player);
|
||||
|
||||
// YouTube looping doesn't seem to play well with VideoJS, so we need to
|
||||
// implement it manually here
|
||||
if (player.apiArgs.playerVars.loop) {
|
||||
player.tech.youtube.seekTo(0, true);
|
||||
player.tech.youtube.playVideo();
|
||||
} else {
|
||||
player.tech.youtube.stopVideo();
|
||||
}
|
||||
break;
|
||||
case YT.PlayerState.PLAYING:
|
||||
player.triggerEvent("timeupdate");
|
||||
player.triggerEvent("playing");
|
||||
player.triggerEvent("play");
|
||||
break;
|
||||
case YT.PlayerState.PAUSED:
|
||||
player.triggerEvent("pause");
|
||||
break;
|
||||
case YT.PlayerState.BUFFERING:
|
||||
player.triggerEvent("timeupdate");
|
||||
player.triggerEvent("waiting");
|
||||
// Hide the waiting spinner since YouTube has its own
|
||||
player.loadingSpinner.hide();
|
||||
break;
|
||||
}
|
||||
|
||||
player.lastState = e.data;
|
||||
};
|
||||
|
||||
_V_.youtube.onPlaybackQualityChange = function(e){
|
||||
var player = e.target.getIframe().parentNode.player;
|
||||
_V_.youtube.updateVideoQuality(player, e.data);
|
||||
player.triggerEvent("ratechange");
|
||||
};
|
||||
|
||||
_V_.youtube.onError = function(e){
|
||||
var player = e.target.getIframe().parentNode.player;
|
||||
player.error = e.data;
|
||||
player.triggerEvent("error");
|
||||
};
|
||||
|
||||
// Helpers --------------------------------------------------------------------
|
||||
|
||||
_V_.youtube.hideOverlay = function(player) {
|
||||
// Hide the big play button and poster since YouTube provides these. Using
|
||||
// our own prevents the video from playing on the first click in mobile
|
||||
// devices
|
||||
player.bigPlayButton.hide();
|
||||
player.posterImage.hide();
|
||||
};
|
||||
|
||||
_V_.youtube.updateVideoQuality = function(player, quality) {
|
||||
switch (quality) {
|
||||
case 'medium':
|
||||
player.videoWidth = 480;
|
||||
player.videoHeight = 360;
|
||||
break;
|
||||
case 'large':
|
||||
player.videoWidth = 640;
|
||||
player.videoHeight = 480;
|
||||
break;
|
||||
case 'hd720':
|
||||
player.videoWidth = 960;
|
||||
player.videoHeight = 720;
|
||||
break;
|
||||
case 'hd1080':
|
||||
player.videoWidth = 1440;
|
||||
player.videoHeight = 1080;
|
||||
break;
|
||||
case 'highres':
|
||||
player.videoWidth = 1920;
|
||||
player.videoHeight = 1080;
|
||||
break;
|
||||
case 'small':
|
||||
player.videoWidth = 320;
|
||||
player.videoHeight = 240;
|
||||
break;
|
||||
default:
|
||||
player.videoWidth = 0;
|
||||
player.videoHeight = 0;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// Support testing ------------------------------------------------------------
|
||||
|
||||
_V_.youtube.isSupported = function(){
|
||||
return true;
|
||||
};
|
||||
|
||||
_V_.youtube.canPlaySource = function(srcObj){
|
||||
return srcObj.type == "video/youtube";
|
||||
};
|
||||
|
||||
_V_.youtube.prototype.support = {
|
||||
formats: {
|
||||
"video/youtube": "YT"
|
||||
},
|
||||
|
||||
// Optional events that we can manually mimic with timers
|
||||
progressEvent: false,
|
||||
timeupdateEvent: false,
|
||||
|
||||
//fullscreen: true,
|
||||
// In iOS, if you move a video element in the DOM, it breaks video playback.
|
||||
movingElementInDOM: !_V_.isIOS(),
|
||||
|
||||
fullscreenResize: true,
|
||||
parentResize: true
|
||||
};
|
||||
|
||||
// YouTube JS API load callback -----------------------------------------------
|
||||
|
||||
window.onYouTubePlayerAPIReady = function() {
|
||||
// Fire a techready event for each loading player
|
||||
var loadingEl;
|
||||
while ((loadingEl = _V_.youtube.loadingEls.shift())) {
|
||||
loadingEl.player.triggerEvent("techready");
|
||||
}
|
||||
};
|
59
test/index.html
Normal file
59
test/index.html
Normal file
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video.js Test Suite</title>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="../test/qunit/qunit/qunit.css" />
|
||||
<script src="../test/qunit/qunit/qunit.js"></script>
|
||||
|
||||
<!-- Video.js CSS -->
|
||||
<link rel="stylesheet" href="../src/css/video-js.css" type="text/css">
|
||||
|
||||
<!-- GENERATED LIST OF SOURCE FILES -->
|
||||
<script src="../dist/sourcelist.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function(){
|
||||
var root = '../';
|
||||
// ADD NEW TEST FILES HERE
|
||||
var tests = [
|
||||
'test/unit/lib.js',
|
||||
'test/unit/events.js',
|
||||
'test/unit/component.js',
|
||||
'test/unit/player.js',
|
||||
'test/unit/core.js',
|
||||
'test/unit/media.html5.js'
|
||||
];
|
||||
var compiledTests = "test/video.test.js";
|
||||
var scripts = [];
|
||||
|
||||
// Choose either the raw source and tests
|
||||
// Or the compiled source + tests.
|
||||
// Use ?comiled to use the compiled tests
|
||||
if (QUnit.urlParams.min || QUnit.urlParams.compiled) {
|
||||
scripts.push(compiledTests);
|
||||
} else {
|
||||
// sourcelist is loaded by sourcelist.js
|
||||
// which is built by `grunt build` or `grunt watch`
|
||||
scripts = scripts.concat(sourcelist,tests);
|
||||
}
|
||||
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
document.write( "<script src='" + root + scripts[i] + "'><\/script>" );
|
||||
}
|
||||
|
||||
})()
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1 id="qunit-header">Video.js Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,42 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Video.js Test Suite</title>
|
||||
|
||||
<!-- QUnit -->
|
||||
<link rel="stylesheet" href="vendor/qunit/qunit/qunit.css" />
|
||||
<script src="vendor/qunit/qunit/qunit.js"></script>
|
||||
|
||||
<!-- Video.js CSS -->
|
||||
<link rel="stylesheet" href="../design/video-js.css" type="text/css">
|
||||
|
||||
<!-- Video.js JavaScript -->
|
||||
<script src='../src/core.js'></script>
|
||||
<script src='../src/lib.js'></script>
|
||||
<script src='../src/component.js'></script>
|
||||
<script src='../src/controls.js'></script>
|
||||
<script src='../src/events.js'></script>
|
||||
<script src='../src/json.js'></script>
|
||||
<script src='../src/player.js'></script>
|
||||
<script src='../src/tech.js'></script>
|
||||
<script src='../src/tracks.js'></script>
|
||||
|
||||
<script src='../tech/html5/html5.js'></script>
|
||||
<script src='../tech/flash/flash.js'></script>
|
||||
|
||||
<script src='../src/setup.js'></script>
|
||||
|
||||
<!-- Integration Tests -->
|
||||
<script src="integration/test.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<h1 id="qunit-header">Bootstrap Plugin Test Suite</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
<ol id="qunit-tests"></ol>
|
||||
<div id="qunit-fixture"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,304 +0,0 @@
|
||||
|
||||
// Potential Future automation
|
||||
// https://github.com/mcrmfc/qunit_sauce_runner
|
||||
// http://saucelabs.com/blog/index.php/2011/06/javascript-unit-testing-with-jellyfish-and-ondemand/
|
||||
// https://github.com/admc/jellyfish/blob/master/test/fun/jfqunit.js
|
||||
|
||||
function createVideoTag(id){
|
||||
var tagCode, tag, attrs;
|
||||
|
||||
tagCode = '<video id="vid1" controls class="video-js vjs-default-skin" preload="none" width="640" height="264" data-setup=\'{}\' poster="http://video-js.zencoder.com/oceans-clip.png">';
|
||||
tagCode+= '<source src="http://video-js.zencoder.com/oceans-clip.mp4" type="video/mp4">';
|
||||
tagCode+= '<source src="http://video-js.zencoder.com/oceans-clip.webm" type="video/webm">';
|
||||
tagCode+= '<source src="http://video-js.zencoder.com/oceans-clip.ogv" type="video/ogg; codecs=\'theora, vorbis\'">';
|
||||
tagCode+= '</video>';
|
||||
|
||||
tag = document.createElement("video");
|
||||
|
||||
tag.id = "vid1";
|
||||
tag.controls = true;
|
||||
tag.className = "video-js vjs-default-skin";
|
||||
tag.preload = "auto";
|
||||
tag.width = "640";
|
||||
tag.height = "264";
|
||||
tag.poster = "http://video-js.zencoder.com/oceans-clip.png";
|
||||
|
||||
source1 = document.createElement("source");
|
||||
source1.src = "http://video-js.zencoder.com/oceans-clip.mp4";
|
||||
source1.type = "video/mp4";
|
||||
tag.appendChild(source1);
|
||||
|
||||
source2 = document.createElement("source");
|
||||
source2.src = "http://video-js.zencoder.com/oceans-clip.webm";
|
||||
source2.type = "video/webm";
|
||||
tag.appendChild(source2);
|
||||
|
||||
source3 = document.createElement("source");
|
||||
source3.src = "http://video-js.zencoder.com/oceans-clip.ogv";
|
||||
source3.type = "video/ogg";
|
||||
tag.appendChild(source3);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
function playerSetup(){
|
||||
|
||||
_V_.el("qunit-fixture").appendChild(createVideoTag())
|
||||
|
||||
var vid = document.getElementById("vid1");
|
||||
this.player = _V_(vid);
|
||||
|
||||
stop();
|
||||
|
||||
this.player.ready(_V_.proxy(this, function(){
|
||||
start();
|
||||
}));
|
||||
}
|
||||
|
||||
function playerTeardown(){
|
||||
stop();
|
||||
_V_("vid1").destroy();
|
||||
// document.body.removeChild(document.getElementById("vid1"));
|
||||
delete this.player;
|
||||
setTimeout(function(){
|
||||
start();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
module("Video.js setup", {
|
||||
setup: playerSetup,
|
||||
teardown: playerTeardown
|
||||
});
|
||||
|
||||
test("Player Set Up", function() {
|
||||
ok(this.player);
|
||||
});
|
||||
|
||||
/* Methods
|
||||
================================================================================ */
|
||||
module("API Methods", {
|
||||
setup: playerSetup,
|
||||
teardown: playerTeardown
|
||||
});
|
||||
|
||||
function failOnEnded() {
|
||||
this.player.one("ended", _V_.proxy(this, function(){
|
||||
start();
|
||||
}));
|
||||
}
|
||||
|
||||
// Play Method
|
||||
test("Play", 1, function() {
|
||||
stop();
|
||||
|
||||
this.player.one("playing", _V_.proxy(this, function(){
|
||||
ok(true);
|
||||
start();
|
||||
}));
|
||||
|
||||
this.player.play();
|
||||
|
||||
failOnEnded.call(this);
|
||||
});
|
||||
|
||||
// Pause Method
|
||||
test("Pause", 1, function() {
|
||||
stop();
|
||||
|
||||
// Flash doesn't currently like calling pause immediately after 'playing'.
|
||||
this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
|
||||
this.player.pause();
|
||||
|
||||
}));
|
||||
|
||||
this.player.addEvent("pause", _V_.proxy(this, function(){
|
||||
ok(true);
|
||||
start();
|
||||
}));
|
||||
|
||||
this.player.play();
|
||||
});
|
||||
|
||||
// Paused Method
|
||||
test("Paused", 2, function() {
|
||||
stop();
|
||||
|
||||
this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
equal(this.player.paused(), false);
|
||||
this.player.pause();
|
||||
}));
|
||||
|
||||
this.player.addEvent("pause", _V_.proxy(this, function(){
|
||||
equal(this.player.paused(), true);
|
||||
start();
|
||||
}));
|
||||
|
||||
this.player.play();
|
||||
});
|
||||
|
||||
// test("currentTime()", 1, function() {
|
||||
// stop();
|
||||
|
||||
// // Try for 3 time updates, sometimes it updates at 0 seconds.
|
||||
// // var tries = 0;
|
||||
|
||||
// // Can't rely on just time update because it's faked for Flash.
|
||||
// this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
|
||||
// this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
|
||||
// if (this.player.currentTime() > 0) {
|
||||
// ok(true, "Time is greater than 0.");
|
||||
// start();
|
||||
// } else {
|
||||
// // tries++;
|
||||
// }
|
||||
|
||||
// // if (tries >= 3) {
|
||||
// // start();
|
||||
// // }
|
||||
// }));
|
||||
|
||||
// }));
|
||||
|
||||
// this.player.play();
|
||||
// });
|
||||
|
||||
|
||||
// test("currentTime(seconds)", 2, function() {
|
||||
// stop();
|
||||
|
||||
// // var afterPlayback = _V_.proxy(this, function(){
|
||||
// // this.player.currentTime(this.player.duration() / 2);
|
||||
// //
|
||||
// // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
// //
|
||||
// // this.player.pause();
|
||||
// //
|
||||
// // this.player.addEvent("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// // start();
|
||||
// // }));
|
||||
// //
|
||||
// // this.player.currentTime(0);
|
||||
// // }));
|
||||
// // });
|
||||
|
||||
// // Wait for Source to be ready.
|
||||
// this.player.one("loadeddata", _V_.proxy(this, function(){
|
||||
|
||||
// _V_.log("loadeddata", this.player);
|
||||
// this.player.currentTime(this.player.duration() - 1);
|
||||
|
||||
// }));
|
||||
|
||||
// this.player.one("seeked", _V_.proxy(this, function(){
|
||||
|
||||
// _V_.log("seeked", this.player.currentTime())
|
||||
// ok(this.player.currentTime() > 1, "Time is greater than 1.");
|
||||
|
||||
// this.player.one("seeked", _V_.proxy(this, function(){
|
||||
|
||||
// _V_.log("seeked2", this.player.currentTime())
|
||||
|
||||
// ok(this.player.currentTime() <= 1, "Time is less than 1.");
|
||||
// start();
|
||||
|
||||
// }));
|
||||
|
||||
// this.player.currentTime(0);
|
||||
|
||||
// }));
|
||||
|
||||
|
||||
// this.player.play();
|
||||
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// //
|
||||
// // this.player.currentTime(this.player.duration() / 2);
|
||||
// //
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// // ok(this.player.currentTime() > 0, "Time is greater than 0.");
|
||||
// //
|
||||
// // this.player.pause();
|
||||
// // this.player.currentTime(0);
|
||||
// //
|
||||
// // this.player.one("timeupdate", _V_.proxy(this, function(){
|
||||
// //
|
||||
// // ok(this.player.currentTime() == 0, "Time is 0.");
|
||||
// // start();
|
||||
// //
|
||||
// // }));
|
||||
// //
|
||||
// // }));
|
||||
// //
|
||||
// //
|
||||
// // }));
|
||||
|
||||
// });
|
||||
|
||||
/* Events
|
||||
================================================================================ */
|
||||
module("API Events", {
|
||||
setup: playerSetup,
|
||||
teardown: playerTeardown
|
||||
});
|
||||
|
||||
var playEventList = []
|
||||
|
||||
// Test all playback events
|
||||
test("Initial Events", 12, function() {
|
||||
stop(); // Give 30 seconds to run then fail.
|
||||
|
||||
var events = [
|
||||
// "loadstart" // Called during setup
|
||||
"play",
|
||||
"playing",
|
||||
|
||||
"durationchange",
|
||||
"loadedmetadata",
|
||||
"loadeddata",
|
||||
"loadedalldata",
|
||||
|
||||
"progress",
|
||||
"timeupdate",
|
||||
|
||||
"canplay",
|
||||
"canplaythrough",
|
||||
|
||||
"pause",
|
||||
"ended"
|
||||
];
|
||||
|
||||
// Add an event listener for each event type.
|
||||
for (var i=0, l=events.length; i<l; i++) {
|
||||
var evt = events[i];
|
||||
|
||||
// Bind player and event name to function so event name value doesn't get overwritten.
|
||||
this.player.one(evt, _V_.proxy({ player: this.player, evt: evt }, function(){
|
||||
ok(true, this.evt);
|
||||
|
||||
// Once we reach canplaythrough, pause the video and wait for 'paused'.
|
||||
if (this.evt == "loadedalldata") {
|
||||
this.player.pause();
|
||||
|
||||
// After we've paused, go to the end of the video and wait for 'ended'.
|
||||
} else if (this.evt == "pause") {
|
||||
this.player.currentTime(this.player.duration() - 1);
|
||||
|
||||
// Flash has an issue calling play too quickly after currentTime. Hopefully we'll fix this.
|
||||
setTimeout(this.player.proxy(function(){
|
||||
this.play();
|
||||
}), 250);
|
||||
|
||||
// When we reach ended, we're done. Continue with the test suite.
|
||||
} else if (this.evt == "ended") {
|
||||
start();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
this.player.play();
|
||||
});
|
@ -1,63 +0,0 @@
|
||||
// Simple phantom.js integration script
|
||||
// Adapted from Modernizr & Bootstrap
|
||||
|
||||
function waitFor(testFx, onReady, timeOutMillis) {
|
||||
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 5001 //< Default Max Timout is 5s
|
||||
, start = new Date().getTime()
|
||||
, condition = false
|
||||
, interval = setInterval(function () {
|
||||
if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) {
|
||||
// If not time-out yet and condition not yet fulfilled
|
||||
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()) //< defensive code
|
||||
} else {
|
||||
if (!condition) {
|
||||
// If condition still not fulfilled (timeout but condition is 'false')
|
||||
console.log("'waitFor()' timeout")
|
||||
phantom.exit(1)
|
||||
} else {
|
||||
// Condition fulfilled (timeout and/or condition is 'true')
|
||||
typeof(onReady) === "string" ? eval(onReady) : onReady() //< Do what it's supposed to do once the condition is fulfilled
|
||||
clearInterval(interval) //< Stop this interval
|
||||
}
|
||||
}
|
||||
}, 100) //< repeat check every 100ms
|
||||
}
|
||||
|
||||
|
||||
if (phantom.args.length === 0 || phantom.args.length > 2) {
|
||||
console.log('Usage: phantom.js URL')
|
||||
phantom.exit()
|
||||
}
|
||||
|
||||
var page = new WebPage()
|
||||
|
||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||
page.onConsoleMessage = function(msg) {
|
||||
console.log(msg)
|
||||
};
|
||||
|
||||
page.open(phantom.args[0], function(status){
|
||||
if (status !== "success") {
|
||||
console.log("Unable to access network")
|
||||
phantom.exit()
|
||||
} else {
|
||||
waitFor(function(){
|
||||
return page.evaluate(function(){
|
||||
var el = document.getElementById('qunit-testresult')
|
||||
if (el && el.innerText.match('completed')) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}, function(){
|
||||
var failedNum = page.evaluate(function(){
|
||||
var el = document.getElementById('qunit-testresult')
|
||||
try {
|
||||
return el.getElementsByClassName('failed')[0].innerHTML
|
||||
} catch (e) { }
|
||||
return 10000
|
||||
});
|
||||
phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0)
|
||||
})
|
||||
}
|
||||
})
|
84
test/qunit/qunit-externs.js
Normal file
84
test/qunit/qunit-externs.js
Normal file
@ -0,0 +1,84 @@
|
||||
// https://github.com/lukeasrodgers/qunit-js-externs/blob/master/qunit-externs.js
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Object=} lifecycle
|
||||
*/
|
||||
function module(name, lifecycle) {}
|
||||
|
||||
/**
|
||||
* @param {string} title
|
||||
* @param {number|Function} expected
|
||||
* @param {Function=} test_func
|
||||
*/
|
||||
function test(title, expected, test_func){}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {number|Function} expected
|
||||
* @param {Function=} test_func
|
||||
*/
|
||||
function asyncTest(name, expected, test_func){}
|
||||
|
||||
/**
|
||||
* @param {number} amount
|
||||
*/
|
||||
function expect(amount){}
|
||||
|
||||
/**
|
||||
* @param {*} state
|
||||
* @param {string=} message
|
||||
*/
|
||||
function ok(state, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function equal(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function notEqual(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function deepEqual(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function notDeepEqual(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function strictEqual(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {*} actual
|
||||
* @param {*} expected
|
||||
* @param {string=} message
|
||||
*/
|
||||
function notStrictEqual(actual, expected, message){}
|
||||
|
||||
/**
|
||||
* @param {number=} increment
|
||||
*/
|
||||
function start(increment){}
|
||||
|
||||
/**
|
||||
* @param {number=} increment
|
||||
*/
|
||||
function stop(increment){}
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Simple connect server for phantom.js
|
||||
* Adapted from Modernizr & Bootstrap
|
||||
*/
|
||||
|
||||
var connect = require('connect')
|
||||
, http = require('http')
|
||||
, fs = require('fs')
|
||||
, app = connect()
|
||||
.use(connect.static(__dirname + '/../'));
|
||||
|
||||
http.createServer(app).listen(3000);
|
||||
|
||||
fs.writeFileSync(__dirname + '/pid.txt', process.pid, 'utf-8')
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user