SERVER PROBLEM
Recently the server that was used for the videos used in tutorials 1-6 was changed. The newer server does not handle either .ogg or .mp4 files correctly at least when I tested it last. I am told the staff is trying figure out what the problem is but didn't estimate how long it make take to fix the problem. Tutorial 7, KISVid7 YouTube Videos, should still work just fine since it uses YouTube servers.
HTML5 has a new features that allow HTML5 aware browsers to play audio and video files without having to have an add-on. This is convenient for developers because they can add video to their pages without having to assume that the user has installed the required add-on. (Of course, the user must have an HTML5 aware browser.) This tutorial is concerned with showing videos in HTML5 pages using Processing.js.
HTML5 provides a Video API designed to be used by Javascript. This tutorial shows how Processing.js can use that API directly with no (or possibly minimal) Javascript. Those familiar with Javascript will quickly recognize that Processing.js programmers use nearly the same commands as would be used in Javascript.
To illustrate how this can be done, this tutorial will develop a simple video player in a series of steps. The type of coding used to communicate with the video API can be used in many types of applications.
The video tag and video API are a super set of the corresponding audio elements. In fact, the coding for tutorials 0 to 3 are direct translations of the corresponding KISA coding with "Audio" replaced by "Video", "audio" replaced by "video" and KISA replaced by "KISVid", adding the "width" attribute to the <video> tags, and just a few other minor changes. The first real difference is the audio constructor introduced in KISA Tutorial 4 has no equivalent video constructor. Hence, the <video> tag is always required. Tutorial 5 is once again a translation of the corresponding KISA code except the audio constructor in the pde file is replaced by <video> tag in the .html file. Tutorial 6 is distinctly different. It introduces some of the unique features of the video that are not applicable to audio.
Those who have already studied the audio tutorials can typically skip to Tutorial 4 and then skip to Tutorial 6. Tutorial 7 is a standalone tutorial looking at the YouTube API for handling their videos. It can be used even by those who have not used the previous tutorials.
There are three types of files that can be played with the <video> tag. They include WebM which uses the .webm file type, MPEG-4 (.mp4 file types) and Theora which is seen in both .ogg and .ogv file types. However, at the time this was written, only Chrome could play all three file types. Because the author has experienced difficulties with .webm and .ogv file not being served properly from his servers, the tutorial only uses .mp4 and .ogg files. The problem is some servers do not use the proper mime type and some browsers can't handle the type specified. This is particularly true for Internet Explorer 9 which seems to be extremely picky about the mime type.
Because it has been difficult to find simple and readable descriptions of the HTML5 video tag, a link to "HTML5 Video Javascript API and Demo" has been included at the end of this page. It includes a listing of the video attributes and events. The demo is written in Processing.js and is glorified extension of the KISVid sketch developed in this tutorial.
KISVid has been tested in HTML 5 aware versions of Firefox, Chrome, Opera, Safari 5.1, and Internet Explorer 9. Implimentations are not perfect. Safari 5.1 seems to have the most problems. It has a tendency to restart the video if it stalls because the lack data. Internet Explorer 9 seems to work well although it seems very picky about the mime type and seems somewhat slow about downloading. Download speed is a common problem with all the browsers. Chrome seems to work the best overall but one .ogg file caused an error even though the same file worked fine in Opera and Firefox. Another version of the same video ran great in Opera and Chrome but Firefox had strange problems with it. Hopefully implementations of video players will be improved as standards are clarified, browser bugs are worked out, internet download speeds improve and servers are updated to serve video files appropriately.
These are some things the author learned the hard way
The first part of the tutorial shows the video tag can be added to an HTML 5 page.
Next >
Updated 1/23/13
Two serious problems may happen when working with video.
1. Downloading videos may be very slow depending on one's internet service. As a result, the primary test file is very short.
Warning: The "first" time a video is downloaded, there can be a lengthy delay!