Skip to content

Writes a properly formatted <video> tag into a web page, with a minimum of fuss and with usable defaults.

Notifications You must be signed in to change notification settings

cschoenfeld/HTML5-Video

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

HTML5 Video Class

Writes a properly formatted <video> tag into a web page, 
with a minimum of fuss and with usable defaults.

ASSUMPTIONS:
If these assumptions are not met, there are function calls you can use to override them.
However, having things set up this way will mean you spend less time and write less code.

1. Constant: BASE_URL exists, with trailing slash.
Example: http://www.mysite.com/

2. Constant: BASEPATH exists, with trailing slash.
Example: /var/htdocs/mysite/

3. Your video files and poster image are located in a /media/ directory, at the BASEPATH.

4. A Flash-based MP4 player called "flvplayer.swf" is located at the BASE_URL.


INSTALLATION:
To install via Composer, put the following in your composer.json file:
{
	"require": {
		"cschoenfeld/html5video": "dev-master"
	}
}

Then, just run "composer install" from the command line.


USAGE:

First, prepare your video files and poster image. 
You will need 3 video formats: .mp4, .webm, and .ogv. Example:
	myvideo.mp4
	myvideo.webm
	myvideo.ogv
	myvideo.jpg

Minimal sample code:
(3 lines of code to render a video.)

	require_once html5video.php;
	try {
		$video = new html5video('videlement', 'myvideo'); // ID of the <video> tag, filename of the video files.
		$video->setDimensions(640, 480); // Width, height
		$video->render();
	} catch (Exception $ex) {
		// Replace this code if you want to handle exceptions more gracefully.
		die('ERROR: ' . $ex->getMessage());
	}
	
Extended sample code:
(Overriding the class defaults, using additional features.)

	require_once html5video.php;
	try {
		$video = new html5video('videlement', 'myvideo');
		$video->setDimensions(640, 480);
		$video->setLocalDir('videos/people/charles'); // Specify an alternate local directory for the media files.
		$video->setBaseURL('http://www.mysite.com/'); // Needed if you don't have a BASE_URL constant defined.
		$video->setBasepath('/var/htdocs/mysite/'); // Needed if you don't have a BASEPATH constant defined.
		$vide->changeFilenames('myvideo-filename.mp4', 'thisvideo.ogv'); // Override the names of individual media files.
		$video->setFlashURL('assets/flash/vidplayer.swf'); // Override the default location of the Flash player.
		$video->use_amazon('https://s3.amazonaws.com/mybucket/'); // Pull videos from Amazon S3 storage.
		$video->useControls(false); // Don't show player controls.
		$video->setAutoplay(true); // Make the video start playing as soon as it loads.
		$video->render();
	} catch (Exception $ex) {
		// Replace this code if you want to handle exceptions more gracefully.
		die('ERROR: ' . $ex->getMessage());
	}

Note:
If you need to capture the HTML output to a variable, instead of writing it directly to the page, 
then replace the "render()" line of the example with this:

	$vid_HTML = $video->render(false);

About

Writes a properly formatted <video> tag into a web page, with a minimum of fuss and with usable defaults.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages