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:

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();

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?

Posted on May 27, 2009 at 8:06 am by Stuart · Permalink
In: Uncategorized · Tagged with: , ,

40 Responses

Subscribe to comments via RSS

  1. Written by Mallikarjun
    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

  2. Written by stuart
    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.

  3. Written by Mallikarjun
    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.

  4. Written by stuart
    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

  5. Written by Yureshwar
    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

  6. Written by stuart
    on June 8, 2009 at 7:26 pm
    Permalink
  7. Written by Yureshwar
    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.

  8. Written by stuart
    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

  9. Written by Jason
    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.

  10. Written by stuart
    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

  11. Written by Hardik Mishra
    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.

  12. Written by stuart
    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.

  13. Written by Jason
    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?

  14. Written by stuart
    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.

  15. Written by Montserrat
    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.

  16. Written by stuart
    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

  17. Written by Montserrat
    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

  18. Written by Hardik
    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.

  19. Written by Stuart
    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

  20. Written by mars
    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?

  21. Written by Stuart
    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

  22. Written by jmcollado
    on September 18, 2009 at 9:24 pm
    Permalink

    it´s easier with Greenstone http://greenstone.org

    ; )

  23. Written by Stuart
    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”.

  24. Written by Nishad T R
    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 video element.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”

    —————————————————————-

  25. Written by Peter Dietz
    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.

  26. Written by Suresh Cherian
    on April 22, 2010 at 5:20 pm
    Permalink

    How to possible in xmlui interface?

  27. Written by Jose Luis
    on June 1, 2010 at 12:39 pm
    Permalink

    Thank you for your contribution, it is very useful

  28. Written by Felipe
    on August 1, 2010 at 10:03 am
    Permalink

    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

  29. Written by Stuart
    on August 2, 2010 at 2:07 pm
    Permalink
  30. Written by Baskar
    on December 24, 2010 at 10:01 pm
    Permalink

    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

  31. Written by Anil
    on January 30, 2011 at 2:02 am
    Permalink

    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

  32. Written by Stuart
    on January 30, 2011 at 7:27 am
    Permalink

    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

  33. Written by Nikhil George
    on February 1, 2011 at 6:13 pm
    Permalink

    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,

  34. Written by Stuart
    on February 1, 2011 at 7:17 pm
    Permalink

    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

  35. Written by Van Luot
    on February 25, 2011 at 4:58 am
    Permalink

    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

  36. Written by Van Luot
    on February 25, 2011 at 5:04 am
    Permalink

    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

  37. Written by james
    on June 4, 2011 at 10:15 am
    Permalink

    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

  38. Written by yuri
    on August 2, 2011 at 9:31 am
    Permalink

    Hi Stuart
    I am using the DSpace 1.5.2, I can not find the atchivo I have to change, could help me.

    thanks

  39. Written by yuri
    on August 9, 2011 at 5:45 am
    Permalink

    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

  40. Written by Stuart
    on August 9, 2011 at 7:30 am
    Permalink

    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

Subscribe to comments via RSS

Leave a Reply