<%
	import java.util.List;
	import java.util.ArrayList;
	import javax.jcr.Node;
	import javax.jcr.NodeIterator;
	import org.exoplatform.webui.core.UIComponent;
  import org.exoplatform.services.jcr.util.Text;
  import org.exoplatform.container.PortalContainer;
  import org.exoplatform.services.jcr.RepositoryService;

	UIComponent uiParent = uicomponent.getParent();

  public Node getFileLangNode(Node currentNode) throws Exception {
    if(currentNode.isNodeType("nt:unstructured")) {
      if(currentNode.getNodes().getSize() > 0) {
        NodeIterator nodeIter = currentNode.getNodes() ;
        while(nodeIter.hasNext()) {
          Node ntFile = nodeIter.nextNode() ;
          if(ntFile.getPrimaryNodeType().getName().equals("nt:file")) {
            return ntFile ;
          }
        }
        return currentNode ;
      }
    }
    return currentNode ;
  }
	
  def originalNode = uiParent.getOriginalNode();
  def currentNode = getFileLangNode(uiParent.getNode()) ;
  def contentNode = currentNode.getNode("jcr:content") ;
  def mimeType = contentNode.getProperty("jcr:mimeType").getString() ;
  
  RepositoryService rService = uicomponent.getApplicationComponent(RepositoryService.class) ;
  String repository = rService.getCurrentRepository().getConfiguration().getName();

  def binarySrc = "/" + PortalContainer.getCurrentPortalContainerName() + "/" + PortalContainer.getCurrentRestContextName() + "/jcr/" + repository + "/" + uiParent.getWorkspaceName() + currentNode.getPath();
  
%>

<object id="MediaPlayer1" CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
standby="Loading Microsoft Windows® Media Player components..." type="application/x-oleobject" width="400" height="300">
<param name="fileName" value="$binarySrc">
<param name="animationatStart" value="true">
<param name="transparentatStart" value="true">
<param name="autoStart" value="true">
<param name="showControls" value="true">
<param name="Volume" value="100">
<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="$binarySrc" name="MediaPlayer1" width=400 height=300 autostart=1 showcontrols=1 volume=100>
</object>
