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?

i tried as this documentation , but it didnt work. it is still downloading not streaming.
i am using dspace 1.5.2 with fedora
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.
Hi i had tried this in Fedora-9 ,but it didn’t work also not embedded the video files in dspace interface.
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
It worked perfectly… Could you help me how to integrate into xmlui. I am using dspace 1.5.2
Hi. Take a look at http://wiki.dspace.org/DSpace_1.5_XMLUI_FLV_Video_Progressive_Download/ Thanks, Stuart
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.
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
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.
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
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.
What value are you getting for bitstream.getFormat().getMIMEType()? It sounds like your video hasn’t got the correct MIME type set.
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?
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.
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.
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
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
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.
Hi Hardik,
If you search for that error message in Google, there is a lot of helpful articles.
Thanks,
Stuart
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?
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
it´s easier with Greenstone http://greenstone.org
; )
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”.
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”
—————————————————————-
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.
How to possible in xmlui interface?
Thank you for your contribution, it is very useful
Hola Stuart, me puede ayudar por favor a resolver si el metodo usado por usted para lograr video streaming es posible hacerlo para XMLUI ??
Muchas gracias
Felipe Vera
Hola Felipe
Prueba: https://wiki.duraspace.org/display/DSPACE/DSpace+1.5+XMLUI+FLV+Video+Progressive+Download
Gracias,
Stuart
Hi Stuart,
I have embedded the above code in Dspace 1.7.0 and now FLV and MP4 videos works fine.
Thanks for your post.
Baskar
Hello Sir,
thanks for providing this valuable information of video streaming i tried all that in my dspace jspui bt when i click on view open a new window opens which asks for save or open with flv player…
so plz guide me where i m mistaking..
thanks
Hi,
Does a new video player screen open on the page? If you have installed it correctly, then the video will load on the page itself, and you won’t have to press the download link.
Thanks,
Stuart
Hello Stuart,
Thanks for the video steaming post it’s working fine for flv,mp4 and mp3 on my dspace 1.6.0.
Recently i uploaded an item with multiple flv files.
But only the first file gets streamed in the player, is there any way to stream them all..
Thanks,
Hi Nikhil,
This was just a demonstration example to show that pseudo-streaming can be performed using DSpace. As you noticed, it only streams the first file. You will need to undertake further development work to make it play other files.
Thanks,
Stuart
Hi, Permalink
I have error
Submit: Error Uploading File
There was a problem uploading your file. Either the filename you entered was incorrect, there was a network problem which prevented the file from reaching us correctly, or you have attempted to upload a file format marked for internal system use only. Please try again.
Can you help this error?
Thank you!
Van Luot
Hi, Permalink
I’m working on the open source DSpace, the problem here is “How to display the word file or pdf file on the website.”
Can you help me?
Thank you.
Van Luot
hi Stuart i follow this link http://wiki.dspace.org/DSpace_1.5_XMLUI_FLV_Video_Progressive_Download/
for embedding video player but its not working, it seems they are using bundle called FILMSTRIPTHUMB so i changed it to ORIGINAL still its not working can u help me to solve dis problem
Hi Stuart
I am using the DSpace 1.5.2, I can not find the atchivo I have to change, could help me.
thanks
Hola
Yo estoy usando dspace 1.5.2, y no encuentro ni las rutas ni el archivo Itemtag.java. Como haria para poder reproducir los videos con mi versión de dspace (1.5.2)
Gracias
Hi,
ItemTag.java should be in your downloaded source, at [dspace-src]/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/jsptag/Itemtag.java
Thanks,
Stuart
Dear professionals
I am Niranjana K, presently working at polytechnic college in India, I installed d space software in my institute, we have LAN connection along with 20 systems. please do let me know how to customize dspace and how to utilize it for my institute.
i want sow a flv file in my Dspace i get a mimi type is video/x-flv and statues is true and first of all i download a flv player but i can not found swfobject.js file in this download than i try do code in Iteamteg.java and also Enter a new format with the mime type video/x-flv and the file extension flv i can not shaw flv this in my Dspace so plz help me
hi
i could not find the file “swfobject.js” there is jwplayer.js..
what should i do
Unzip the download, and copy player.swf and swfobject.js into [dspace-src]/dspace/modules/jspui/src/main/webapp/
Yo uso dspace 1.8.2 y modifico el Itemtag.java y recompilo usando mvn package y ant update y no refleja ningun cambio, lo hago en dspace 1.7.2 y funciona perfecto. que debo hacer adicionalmente a recompilar completamente dspace ?