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 ‘}’):
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
}
}
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:
showMediaPlayer();
- 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.

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?
In: Uncategorized · Tagged with: dspace, repositories, youtube



on May 29, 2009 at 10:22 am
Permalink
i tried as this documentation , but it didnt work. it is still downloading not streaming.
i am using dspace 1.5.2 with fedora
on May 29, 2009 at 7:00 pm
Permalink
Hi, The player doesn’t ’stream’ rather it just embeds a player in the DSpace user interface, which can give the impression of streaming (hence the blog title ‘pseudo-video streaming’). For a collection of small video files this probably be good enough. If you want to stream large, or protected files, then you would need a dedicated streaming server.I hope this was made clear in the post, but if not, then this comment should clear it up. Thanks.
on June 4, 2009 at 5:49 am
Permalink
Hi i had tried this in Fedora-9 ,but it didn’t work also not embedded the video files in dspace interface.
on June 4, 2009 at 8:37 pm
Permalink
Hi! In what way did it not work? Did it not compile, deploy, run, etc? What type of file have you uploaded, and does it have the MIME type set correctly in the bitstream registry? A few other people have tried the code and got it working, so hopefully it is just a problem with your file or bitstream registry settings. Thanks, Stuart
on June 8, 2009 at 7:07 pm
Permalink
It worked perfectly… Could you help me how to integrate into xmlui. I am using dspace 1.5.2
on June 8, 2009 at 7:26 pm
Permalink
Hi. Take a look at http://wiki.dspace.org/DSpace_1.5_XMLUI_FLV_Video_Progressive_Download/ Thanks, Stuart
on June 10, 2009 at 5:42 am
Permalink
Hi stuart,
The link which you have given describes the basic frame work. There are no proper instructions how to do and where to do. Can you give me those details how to do it.
on June 13, 2009 at 6:54 pm
Permalink
Hi,
Have you seen the theme that the page links to? https://dev.ohiolink.edu/svn/dspace-1_5/dspace/modules/xmlui/src/main/webapp/themes/Flash/
Thanks,
Stuart
on July 8, 2009 at 7:48 am
Permalink
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?
Stuart,
I think that’s a great idea. More and more, the expectation by users is that content be embedded. If DSpace is to remain relevant, the developers should probably make that adjustment in a hurry. Along the same lines, apps should probably be developed that will enable access to repositories from mobile devices.
on July 8, 2009 at 9:20 am
Permalink
Hi Jason,
Thanks for your feedback. Apparently someone has already written a more formal framework to support this for the jspui a year or two ago, so we’ll have to see if we could use that.
Thanks, Stuart
on July 8, 2009 at 6:55 pm
Permalink
Hi Stuart ,
I have used code the above code , but i am not getting any out put.
i have traced the code,
if (“video/x-flv”.equals(bitstream.getFormat().getMIMEType()))
I am getting false each time.
on July 9, 2009 at 6:59 am
Permalink
What value are you getting for bitstream.getFormat().getMIMEType()? It sounds like your video hasn’t got the correct MIME type set.
on July 11, 2009 at 8:15 am
Permalink
Stewart,
Thanks for responding. I’m glad to hear that. Do you think you’ll try to make it work for both jspui and xmlui?
on July 12, 2009 at 7:55 pm
Permalink
Hi Jason. Getting this included in DSpace will require effort to be found from within the community. If you know of anyone interested and with time to dedicate to this, that would be great.
on August 12, 2009 at 9:18 pm
Permalink
Buenos días.
Tengo instalado Dspace 1.4.2.
¿Cómo instalaría el código para ver vídeos en esta versión?
Gracias.
on August 13, 2009 at 9:13 am
Permalink
Buenos días,
Los pasos deben ser muy similares, no obstante cambio la trayectoria donde usted instala el código para estar:
Desabroche la transferencia directa, y la copia player.swf y swfobject.js en [dspace-src]/jsp/
Agregue el código siguiente a la parte inferior [dspace-src]/src/org/dspace/app/webui/jsptag/Itemtag.java (antes del ‘ final;}’):
Gracias, Stuart
on August 14, 2009 at 8:31 pm
Permalink
Gracias ya lo he conseguido
He guardado los archivos player.swf and swfobject.js en el directorio [dspace-source]/jsp/local.
He añadido el código en el directorio [dspace-source]/src/org/dspace/app/webui/jsptag/ItemTag.java tal como me ha indicado.
Gracias por su ayuda.
Saludos, Montse
on August 21, 2009 at 1:13 am
Permalink
Hi Sir,
I have followed your steps.
It is displaying “Video” as output in FF 3.0 and
Error in IE as “swfobject is undefined”.
I have checked
out.println(“\n”);
It shows /jspui/swfobject.js and at there file is located.
on August 21, 2009 at 9:32 am
Permalink
Hi Hardik,
If you search for that error message in Google, there is a lot of helpful articles.
Thanks,
Stuart
on September 6, 2009 at 7:13 pm
Permalink
Hi Stuart,
I have been scouring the web for a solution that will enable me to import multiple items in hierarchical file structure.
The hierarchical file structure needs to be maintained after the DSpace import process.
Do you know of any solutions that enables this?
on September 6, 2009 at 7:50 pm
Permalink
Hi Mars,
The structure builder might help you, alongside the importer. You could use the struct builder to make the structure, then the importer can be run multiple times – once for each hierarchical collection. See the manual (http://www.dspace.org/1_5_2Documentation/DSpace-Manual.pdf) section 9.3.
Stuart
on September 18, 2009 at 9:24 pm
Permalink
it´s easier with Greenstone http://greenstone.org
; )
on September 24, 2009 at 6:52 am
Permalink
It quite likely is, but on the other hand there will be a whole lot of things that DSpace does much better than Greenstone. That’s life I suppose. As they say, “You pays your money and you takes your choice”.
on December 2, 2009 at 8:28 am
Permalink
Dear Stuart,
Thanks for the idea, I just updated it for mp3, mp4 (require latest flash player = 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(“\n” +
“Video” +
“\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” +
“”);
}
if (“video/mp4″.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(“\n” +
“Video” +
“\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” +
“”);
}
if (“video/ogg”.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(“\n” +
“Your browser does not support the
videoelement.Please download Mozilla Firefox latest version.\n” +“”);
}
if (“audio/mpeg”.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(“\n” +
“Video” +
“\nvar so = new SWFObject(‘” +
request.getContextPath() + “/player.swf’,'mpl’,'320′,’20′,’9′);\n” +
“so.addParam(‘allowscriptaccess’,'always’);\n” +
“so.addParam(‘allowfullscreen’,'true’);\n” +
“so.addParam(‘flashvars’,'&file=” + url + “&autostart=true’);\n” +
“so.write(‘player’);\n” +
“”);
}
}
}
}
}
catch (SQLException sqle)
{
// Do nothing
}
}
/*
* Added for Embeded pseudo-video streaming
*/
// Add “showMediaPlayer();” straight after the opening brace ‘{’ of “void render() throws IOException”
—————————————————————-
on February 23, 2010 at 7:27 am
Permalink
Hey Stuart,
I’ve added a way to preview documents.
http://peterpants.blogspot.com/2010/02/document-preview-in-dspace-using-google.html
Generally, using a document viewer program, in my example Google Doc’s Viewer really makes viewing documents easier, and since I like bells and whistles, a bit more fun.