mirror of
https://github.com/sismics/docs.git
synced 2024-11-29 08:54:58 +01:00
Support audio mime (#574)
This commit is contained in:
parent
721410c7d0
commit
ee56cfe2b4
@ -5,7 +5,8 @@ import org.apache.commons.compress.utils.IOUtils;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.net.URLConnection;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
@ -26,11 +27,13 @@ public class MimeTypeUtil {
|
|||||||
* @throws IOException e
|
* @throws IOException e
|
||||||
*/
|
*/
|
||||||
public static String guessMimeType(Path file, String name) throws IOException {
|
public static String guessMimeType(Path file, String name) throws IOException {
|
||||||
String mimeType;
|
String mimeType = URLConnection.getFileNameMap().getContentTypeFor(name);
|
||||||
try (InputStream is = Files.newInputStream(file)) {
|
if (mimeType == null) {
|
||||||
byte[] headerBytes = new byte[64];
|
try (InputStream is = Files.newInputStream(file)) {
|
||||||
is.read(headerBytes);
|
final byte[] headerBytes = new byte[64];
|
||||||
mimeType = guessMimeType(headerBytes, name);
|
is.read(headerBytes);
|
||||||
|
mimeType = guessMimeType(headerBytes, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return guessOpenDocumentFormat(mimeType, file);
|
return guessOpenDocumentFormat(mimeType, file);
|
||||||
@ -42,10 +45,9 @@ public class MimeTypeUtil {
|
|||||||
* @param headerBytes File header (first bytes)
|
* @param headerBytes File header (first bytes)
|
||||||
* @param name File name
|
* @param name File name
|
||||||
* @return MIME type
|
* @return MIME type
|
||||||
* @throws UnsupportedEncodingException e
|
|
||||||
*/
|
*/
|
||||||
public static String guessMimeType(byte[] headerBytes, String name) throws UnsupportedEncodingException {
|
public static String guessMimeType(byte[] headerBytes, String name) {
|
||||||
String header = new String(headerBytes, "US-ASCII");
|
String header = new String(headerBytes, StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
// Detect by header bytes
|
// Detect by header bytes
|
||||||
if (header.startsWith("PK")) {
|
if (header.startsWith("PK")) {
|
||||||
|
@ -41,8 +41,8 @@
|
|||||||
img-error="error = true"
|
img-error="error = true"
|
||||||
ng-show="!error && canDisplayPreview()" />
|
ng-show="!error && canDisplayPreview()" />
|
||||||
|
|
||||||
<!-- Video player -->
|
<!-- Media player -->
|
||||||
<a href class="video-overlay" ng-if="!error && file.mimetype.substring(0, 6) == 'video/'"
|
<a href class="video-overlay" ng-if="!error && (file.mimetype.substring(0, 6) == 'video/' || file.mimetype.substring(0, 6) == 'audio/')"
|
||||||
ng-init="videoPlayer = false" ng-click="videoPlayer = true">
|
ng-init="videoPlayer = false" ng-click="videoPlayer = true">
|
||||||
<span class="fas fa-play-circle" ng-if="!videoPlayer"></span>
|
<span class="fas fa-play-circle" ng-if="!videoPlayer"></span>
|
||||||
<video ng-if="videoPlayer" autoplay="autoplay" loop="loop"
|
<video ng-if="videoPlayer" autoplay="autoplay" loop="loop"
|
||||||
|
Loading…
Reference in New Issue
Block a user