Simplified and unified video display code.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 14 Sep 2018 21:35:55 +0000 (00:35 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 14 Sep 2018 21:35:55 +0000 (00:35 +0300)
.gitignore
meviz.iml [deleted file]
src/main/java/eu/svjatoslav/meviz/htmlindexer/AbstractIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/Layout.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/layouts/MixedLayout.java

index 260935a..4de04cd 100755 (executable)
@@ -3,3 +3,4 @@
 /.project
 /target/
 /.idea/
+/meviz.iml
diff --git a/meviz.iml b/meviz.iml
deleted file mode 100644 (file)
index 7399dd5..0000000
--- a/meviz.iml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
-    <output url="file://$MODULE_DIR$/target/classes" />
-    <output-test url="file://$MODULE_DIR$/target/test-classes" />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
-      <excludeFolder url="file://$MODULE_DIR$/target" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" name="Maven: eu.svjatoslav:svjatoslavcommons:1.7" level="project" />
-    <orderEntry type="library" name="Maven: log4j:log4j:1.2.16" level="project" />
-  </component>
-</module>
\ No newline at end of file
index 5036721..4e3b6eb 100644 (file)
@@ -42,10 +42,8 @@ public abstract class AbstractIndexer {
             if (file instanceof GeneralFile) {
                 final String fileExtension = file.getFileExtension();
 
-                if ("ogv".equals(fileExtension))
-                    layout.enlistOgv(file, directory);
-                else if ("webm".equals(fileExtension))
-                    layout.enlistWebm(file, directory);
+                if (isVideo(fileExtension))
+                    layout.enlistVideo(file);
                 else
                     layout.enlistFile(file, directory);
 
@@ -64,4 +62,20 @@ public abstract class AbstractIndexer {
     public abstract String getThumbnailUrl(Picture picture,
                                            final Dimension desiredDimension, IndexingContext context);
 
+    public static String getVideoType(String fileExtension) {
+        switch (fileExtension){
+            case "ogv":
+                return "video/ogg";
+            case "webm":
+                return "video/webm";
+            case "mp4":
+                return "video/mp4";
+            default:
+                return null;
+        }
+    }
+
+    public boolean isVideo(String fileExtension){
+        return getVideoType(fileExtension) != null;
+    }
 }
index 25bfd4f..c1e6d23 100755 (executable)
@@ -14,7 +14,6 @@ import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.List;
 
 /**
@@ -45,13 +44,9 @@ public interface Layout {
                      DirectoryMetadata parentDirectoryMetadata);
 
     /**
-     * Enlist video in OGV format.
-     *
-     * @throws UnsupportedEncodingException
+     * Enlist video file.
      */
-    void enlistOgv(AbstractFile file,
-                   DirectoryMetadata parentDirectoryMetadata)
-    ;
+    void enlistVideo(AbstractFile file);
 
     /**
      * Return layout specific suffix that will be appended between
@@ -76,5 +71,4 @@ public interface Layout {
     void init(String galleryTitle, List<String> path,
               final AbstractIndexer indexer, IndexingContext context);
 
-    void enlistWebm(AbstractFile file, DirectoryMetadata directory);
 }
index acc3c4e..7963582 100755 (executable)
 package eu.svjatoslav.meviz.htmlindexer.layouts;
 
 import eu.svjatoslav.commons.file.FilePathParser;
-import eu.svjatoslav.meviz.htmlindexer.*;
+import eu.svjatoslav.meviz.htmlindexer.AbstractIndexer;
+import eu.svjatoslav.meviz.htmlindexer.Constants;
+import eu.svjatoslav.meviz.htmlindexer.IndexingContext;
+import eu.svjatoslav.meviz.htmlindexer.Layout;
 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.AbstractFile;
-import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.GeneralFile;
 import eu.svjatoslav.meviz.htmlindexer.metadata.fileTypes.Picture;
 import org.apache.log4j.Logger;
 
 import java.io.IOException;
 import java.util.List;
 
+import static eu.svjatoslav.commons.file.FilePathParser.getFileNameWithoutExtension;
+import static eu.svjatoslav.meviz.htmlindexer.AbstractIndexer.getVideoType;
+import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode;
+
 public class MixedLayout implements Layout {
 
     public static final String encoding = "UTF-8";
@@ -58,7 +64,7 @@ public class MixedLayout implements Layout {
 
         filesHtml.append("<div style=\"clear: both;\"><a href=\""
                 + indexingContext.getGlobalUrl()
-                + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
+                + urlEncode(indexingContext.getLocalUrl() + "/"
                 + fullFileName) + "\">" + fullFileName + "</a>\n");
         filesHtml.append("&nbsp;&nbsp;("
                 + FilePathParser.getFileSizeDescription(file.getFileLength())
@@ -109,7 +115,7 @@ public class MixedLayout implements Layout {
         // clickable image thumbnail
         filesHtml.append("<a href=\""
                 + indexingContext.getGlobalUrl()
-                + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
+                + urlEncode(indexingContext.getLocalUrl() + "/"
                 + picture.fileName) + "\">\n");
 
         filesHtml.append("<img border=\"0\" src=\""
@@ -117,7 +123,7 @@ public class MixedLayout implements Layout {
 
         // file name
         filesHtml.append("<b>"
-                + FilePathParser.getFileNameWithoutExtension(picture.fileName)
+                + getFileNameWithoutExtension(picture.fileName)
                 + "</b><br/>");
 
         // links to thumbnails of various sizes
@@ -126,48 +132,6 @@ public class MixedLayout implements Layout {
         filesHtml.append("</div>");
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void enlistOgv(final AbstractFile abstractFile,
-                          final DirectoryMetadata parentDirectoryMetadata) {
-
-        final GeneralFile file = (GeneralFile) abstractFile;
-
-        filesHtml.append("<div style=\"margin: 30px; clear: both;\">");
-
-        // watchable video
-        filesHtml
-                .append("<video preload=\"metadata\" controls=\"controls\" tabindex=\"0\">\n");
-        filesHtml
-                .append("<source type=\"video/ogg\" codecs=\"theora, vorbis\" src=\""
-                        + indexingContext.getGlobalUrl()
-                        + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
-                        + file.fileName) + "\">\n");
-        filesHtml.append("</source>\n");
-        filesHtml.append("</video>\n");
-        filesHtml.append("<br/>\n");
-
-        // video title
-        filesHtml
-                .append("Video: <b>"
-                        + FilePathParser
-                        .getFileNameWithoutExtension(file.fileName)
-                        + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
-
-        // video download link
-        filesHtml.append("<a href=\""
-                + indexingContext.getGlobalUrl()
-                + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
-                + file.fileName) + "\">download as OGV file</a>");
-
-        filesHtml.append("</div>\n");
-
-        filesHtml.append("\n");
-
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -278,39 +242,35 @@ public class MixedLayout implements Layout {
     }
 
     @Override
-    public void enlistWebm(AbstractFile abstractFile,
-                           DirectoryMetadata directory) {
-        final GeneralFile file = (GeneralFile) abstractFile;
+    public void enlistVideo(AbstractFile file) {
 
-        filesHtml.append("<div style=\"margin: 30px; clear: both;\">");
+        filesHtml.append("<div style=\"margin: 30px; clear: both;\">\n");
 
         // watchable video
+        filesHtml.append("  <video width=\"640\" controls>\n");
+        filesHtml.append("    <source src=\"" + getFileUrl(file) + "\" type=\""
+                + getVideoType(file.getFileExtension()) + "\"/>\n");
+        filesHtml.append("  </video>\n");
 
-        String fileUrl = indexingContext.getGlobalUrl()
-                + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
-                + file.fileName);
-
-        filesHtml.append("<video controls>\n");
-        filesHtml.append("  <source src=\"" + fileUrl
-                + "\" type='video/webm;codecs=\"vp8, opus\"'/>\n");
-        filesHtml.append("</video>\n");
-        filesHtml.append("<br/>\n");
+        filesHtml.append("  <br/>\n");
 
         // video title
-        filesHtml
-                .append("Video: <b>"
-                        + FilePathParser
-                        .getFileNameWithoutExtension(file.fileName)
+        filesHtml.append("  Video: <b>"
+                        + getFileNameWithoutExtension(file.fileName)
                         + "<b/>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
 
         // video download link
-        filesHtml.append("<a href=\""
-                + indexingContext.getGlobalUrl()
-                + Utils.urlEncode(indexingContext.getLocalUrl() + "/"
-                + file.fileName) + "\">download as WebM file</a>");
+        filesHtml.append("  <a href=\"" + getFileUrl(file) + "\">download</a>\n");
 
         filesHtml.append("</div>\n");
 
         filesHtml.append("\n");
     }
+
+
+    private String getFileUrl(AbstractFile file) {
+        return indexingContext.getGlobalUrl()
+                    + urlEncode(indexingContext.getLocalUrl() + "/"
+                    + file.fileName);
+    }
 }