Tag Archives: youtube

Easy pseudo-video streaming for DSpace repositories

A few days ago someone posted an enquiry to the dspace-general email list asking how to embed a video player in DSpace web pages. This was followed up by a lot of replies along the lines of “it would be great if DSpace could do that!”.

I wrote a quick reply saying how I thought it had been implemented, and described the solution as “quick and easy”. I thought I’d better put my money where my mouth is, and prove that it really is quick and easy. So I spent the last hour of my working day making it work, and here is how to do it:

  • Download the JW FLV media player from http://www.longtailvideo.com/players/jw-flv-player/
  • Unzip the download, and copy player.swf and swfobject.js into [dspace-src]/dspace/modules/jspui/src/main/webapp/
  • Add the following code to the bottom of [dspace-src]/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/jsptag/Itemtag.java (before the final ‘}’):

[java]
private void showMediaPlayer() throws IOException
{
try
{
Bundle[] bundles = item.getBundles("ORIGINAL");
if (bundles.length > 0)
{
Bitstream[] bitstreams = bundles[0].getBitstreams();
boolean found = false;
for (Bitstream bitstream : bitstreams)
{
if (!found)
{
if ("video/x-flv".equals(bitstream.getFormat().getMIMEType()))
{
// We found one, don’t search for any more
found = true;

// Display the player
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
String url = request.getContextPath() +
"/bitstream/" + item.getHandle() + "/" +
bitstream.getSequenceID() + "/" +
UIUtil.encodeBitstreamName(bitstream.getName(), Constants.DEFAULT_ENCODING);
JspWriter out = pageContext.getOut();
out.println("<script type=\"text/javascript\" src=\"" + request.getContextPath() +
"/swfobject.js\"></script>\n" +
"<center><div id=\"player\">Video</div></center>" +
"<script type=\"text/javascript\">\nvar so = new SWFObject(‘" +
request.getContextPath() + "/player.swf’,’mpl’,’320′,’240′,’9′);\n" +
"so.addParam(‘allowscriptaccess’,’always’);\n" +
"so.addParam(‘allowfullscreen’,’true’);\n" +
"so.addParam(‘flashvars’,’&file=" + url + "&autostart=true’);\n" +
"so.write(‘player’);\n" +
"</script>");
}
}
}
}
}
catch (SQLException sqle)
{
// Do nothing
}
}
[/java]

In the same file, find the line that reads private void render() throws IOException” and straight after the opening brace ‘{‘  add a new line that reads:

[java]showMediaPlayer();[/java]

  • Rebuild and redeploy DSpace as you would normally (mvn package; ant update; etc)
  • Log in to your DSpace instance as an administrator and go to the bitstream format registry.
  • Enter a new format with the mime type video/x-flv and the file extension flv
  • Now grab yourself an flv video. A quick way of doing this is to use http://keepvid.com/ and to enter the URL of a YouTube video. It will then download this as an flv video.
  • Create a new item in DSpace, and upload this file. It should recognise it as a flash video file.
  • Now view the item, and if the code is working correctly, it will have detected a video exists and will bring up the video player.

vid

As I said, quick, and easy! Now I didn’t say the solution was beautiful, efficient, or written is the best way possible; this is just a proof of concept.

Whilst this solution doesn’t give you proper video streaming, it does give you a halfway house that integrates nicely with DSpace.

Perhaps we should make this is into a pluggable system for DSpace 1.6 where you can register classes that can render file types, and then make a configurable option to register viewers to filetypes? Thoughts?Play mobile games

Time-lapse turfing

In a change from my normal subjects of repositories and related systems, now for something completely different… My first YouTube video! I spent this afternoon turfing the back garden, and decided to take a time-lapse video of the process. 3 hours of turf laying compressed into less than a minute and a half of video.

The technical details:

  • Camera: Cheapo Sony DV video camera, connected via firewire to…
  • Computer: MacBook Pro, running…
  • Gawker open source time-lapse software
The software takes a screen shot from the camera every x seconds, and creates a pretty neat video file.

rpg online games