Search in sources :

Example 1 with MCRMediaSourceProvider

use of org.mycore.media.video.MCRMediaSourceProvider in project mycore by MyCoRe-Org.

the class MCRXMLFunctions method getSources.

public static NodeList getSources(String derivateId, String path, String userAgent) throws IOException, ParserConfigurationException, URISyntaxException {
    MCRMediaSourceProvider provider = new MCRMediaSourceProvider(derivateId, path, Optional.ofNullable(userAgent), () -> EMPTY_ARRAY);
    List<MCRMediaSource> sources = provider.getSources();
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    return new NodeList() {

        @Override
        public Node item(int index) {
            Element source = document.createElement("source");
            source.setAttribute("src", sources.get(index).getUri());
            source.setAttribute("type", sources.get(index).getType().getMimeType());
            return source;
        }

        @Override
        public int getLength() {
            return sources.size();
        }
    };
}
Also used : MCRMediaSource(org.mycore.media.video.MCRMediaSource) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) MCRMediaSourceProvider(org.mycore.media.video.MCRMediaSourceProvider) Document(org.w3c.dom.Document)

Example 2 with MCRMediaSourceProvider

use of org.mycore.media.video.MCRMediaSourceProvider in project mycore by MyCoRe-Org.

the class MCRJWPlayerResource method getSources.

@GET
@Path("{derivateId}/{path: .+}/sources.json")
@Produces({ "application/javascript" })
public String getSources(@PathParam("derivateId") String derivateId, @PathParam("path") String path) throws URISyntaxException, IOException {
    MCRObjectID derivate = MCRJerseyUtil.getID(derivateId);
    MCRJerseyUtil.checkDerivateReadPermission(derivate);
    try {
        MCRMediaSourceProvider formatter = new MCRMediaSourceProvider(derivateId, path, Optional.ofNullable(request.getHeader("User-Agent")), () -> Arrays.stream(Optional.ofNullable(request.getQueryString()).orElse("").split("&")).filter(p -> !p.startsWith("callback=")).toArray(String[]::new));
        return toJson(formatter.getSources());
    } catch (NoSuchFileException e) {
        LogManager.getLogger().warn("Could not find video file.", e);
        throw new WebApplicationException(Status.NOT_FOUND);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MCRMediaSourceProvider(org.mycore.media.video.MCRMediaSourceProvider) NoSuchFileException(java.nio.file.NoSuchFileException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MCRMediaSourceProvider (org.mycore.media.video.MCRMediaSourceProvider)2 NoSuchFileException (java.nio.file.NoSuchFileException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCRMediaSource (org.mycore.media.video.MCRMediaSource)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1