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.

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?

48 thoughts on “Easy pseudo-video streaming for DSpace repositories

  1. Mallikarjun

    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. stuart Post author

    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. Mallikarjun

    Hi i had tried this in Fedora-9 ,but it didn’t work also not embedded the video files in dspace interface.

  4. stuart Post author

    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. Yureshwar

    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.

  6. Jason

    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.

  7. stuart Post author

    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

  8. Hardik Mishra

    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.

  9. stuart Post author

    What value are you getting for bitstream.getFormat().getMIMEType()? It sounds like your video hasn’t got the correct MIME type set.

  10. Jason

    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?

  11. stuart Post author

    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.

  12. stuart Post author

    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

  13. Montserrat

    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

  14. Hardik

    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.

  15. mars

    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?

  16. Stuart Post author

    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”.

  17. Nishad T R

    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”

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

  18. Felipe

    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

  19. Baskar

    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

  20. Anil

    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

  21. Stuart Post author

    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

  22. Nikhil George

    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,

  23. Stuart Post author

    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

  24. Van Luot

    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

  25. 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

  26. yuri

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

    thanks

  27. yuri

    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

  28. Stuart Post author

    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

  29. Niranjana K

    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.

  30. vipul

    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

  31. Rubas

    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/

  32. Jaime

    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 ?

  33. Bhavesh Patel

    Hi Stuart,

    Thank you for Sharing.. but I am facing some issue that the flv video is not display on the item detail page.

    I have added that MIMETYPE also but it’s download.. I am using DSpace 3.2 and JSPUI Interface.

    One thing I have notice that….When I download the “jwplayer” then there is no swfobject.js .. It is having following files : 1) jwplayer.flash.swf 2) jwplayer.html5 3) jwplayer into “jwplayer-6.6″

    So Please help me what I have to do .. Also one more thing when I rebuild the DSpace then all the customization deleted.. and Discovery search also deleted.. It’s look like default DSpace installation.

    Please help me on that issue..

    Thanks,
    Bhavesh Patel

  34. Bhavesh Patel

    Hi Stuart,

    I debug the code that I have integrate from your post. Below are sample code that I used into DSpace3.2 JSPUI Interface.

    into [dspace-src]\dspace-jspui\src\main\java\org\dspace\app\webui\jsptag\ItemTag.java the function
    private void showMediaPlayer() throws IOException is not call.

    I am calling this function from following code :

    /**
    * Render an item in the given style
    */
    private void render() throws IOException, SQLException, DCInputsReaderException
    {
    showMediaPlayer(); // Added for Video Player
    JspWriter out = pageContext.getOut();
    HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
    Context context = UIUtil.obtainContext(request);
    Locale sessionLocale = UIUtil.getSessionLocale(request);
    String configLine = styleSelection.getConfigurationForStyle(style);

    But It’s not calling that function..

    Below is the sample code for that video function..

    private void showMediaPlayer() throws IOException
    {
    try
    {
    out.println(“alert(\”Play Video\”)”);
    out.println(“Into showMediaPlayer Function…. Testing Over..!”);

    }
    catch (SQLException sqle)
    {
    // Do nothing
    }
    }

    But it’s not giving any output… Please help me on this..

    Thanks,
    Bhavesh

  35. Matheus Otoni

    Very Nice! Could you help me how to integrate into xmlui. I am using dspace 3.2.0

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>