From 7f7b2a3d7578f013b3960769fdacb3a01bfd36ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Gn=C3=A4gi?= <gnaegi@frentix.com> Date: Wed, 27 Nov 2019 15:43:35 +0100 Subject: [PATCH] OO-4380 Supportfor Vimeo videos shared as "Private link", hide controls --- .../video/ui/VideoDisplayController.java | 24 +++++++++++++++++++ .../modules/video/ui/_content/video_run.html | 20 ++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java b/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java index a5c678e6c0e..acd83d6d2a7 100644 --- a/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java +++ b/src/main/java/org/olat/modules/video/ui/VideoDisplayController.java @@ -19,12 +19,14 @@ */ package org.olat.modules.video.ui; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.http.client.utils.URIBuilder; import org.olat.core.commons.services.commentAndRating.CommentAndRatingDefaultSecurityCallback; import org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback; import org.olat.core.commons.services.commentAndRating.ReadOnlyCommentsSecurityCallback; @@ -348,6 +350,28 @@ public class VideoDisplayController extends BasicController { } private void loadVideo(UserRequest ureq, String url, VideoFormat format) { + mainVC.contextPut("externalUrlOriginal", url); + URIBuilder uriBuilder; + try { + uriBuilder = new URIBuilder(url); + // Check if this is a vimeo video + if (uriBuilder.getHost().indexOf("vimeo") != -1) { + // Vimeo allows removing the controls when using the payed service. It ignores the parameter + // for the free service, so it is save to use it. We use the URIBuilder method in case the + // user already added that parameter or if he uses some other parameters + uriBuilder.setParameter("controls", "0"); + // Check if this is a Vimeo with the settings "Only people with the private link". In this case + // the second parameter needs to be removed for mediaelementjs to work properly. + // Example: https://vimeo.com/123922956/05ad0e2cbf + if (uriBuilder.getPathSegments().size() == 2) { + uriBuilder.setPath(uriBuilder.getPathSegments().get(0)); + } + url = uriBuilder.build().toString(); + } + } catch (URISyntaxException e) { + logWarn("Error while parsing URL from external video source URL::" + url, e); + } + mainVC.contextPut("externalUrl", url); mainVC.contextPut("sourceType", format.mimeType()); diff --git a/src/main/java/org/olat/modules/video/ui/_content/video_run.html b/src/main/java/org/olat/modules/video/ui/_content/video_run.html index 8dda123ca3f..f20dc2858f6 100644 --- a/src/main/java/org/olat/modules/video/ui/_content/video_run.html +++ b/src/main/java/org/olat/modules/video/ui/_content/video_run.html @@ -52,6 +52,16 @@ }, #end + ## Set JS callback to retreive user selected video url or fixed url for external services that can not be changed. + ## Triggers error for Vimeo private URLs otherwise + #if($r.isNotEmpty($externalUrlOriginal)) + #set($mediaSrc = "'$externalUrlOriginal'") + #else + #set($mediaSrc = "mediaElement.src") + #end + + + ## Callback to communicate with the server success: function (mediaElement, domObject, player) { jQuery('#$r.getId("o_vid")').data('player', player); @@ -60,19 +70,19 @@ ## listen to play events, fired when movie is finished mediaElement.addEventListener('play', function(e) { if (!o_info.linkbusy) { - $r.openNoResponseJavaScriptCommand("play"), 'currentTime', mediaElement.currentTime, 'src', mediaElement.src, 'duration', mediaElement.duration); + $r.openNoResponseJavaScriptCommand("play"), 'currentTime', mediaElement.currentTime, 'src', $mediaSrc, 'duration', mediaElement.duration); } }, false); ## listen to pause events, fired when movie is paused by user mediaElement.addEventListener('pause', function(e) { if (!o_info.linkbusy) { - $r.openNoResponseJavaScriptCommand("pause"), 'currentTime', mediaElement.currentTime, 'src', mediaElement.src, 'duration', mediaElement.duration); + $r.openNoResponseJavaScriptCommand("pause"), 'currentTime', mediaElement.currentTime, 'src', $mediaSrc, 'duration', mediaElement.duration); } }, false); ## listen to seeked events, fired when user uses the slider in the movie mediaElement.addEventListener('seeked', function(e) { if (!o_info.linkbusy) { - $r.openNoResponseJavaScriptCommand("seeked"), 'currentTime', mediaElement.currentTime, 'src', mediaElement.src, 'duration', mediaElement.duration); + $r.openNoResponseJavaScriptCommand("seeked"), 'currentTime', mediaElement.currentTime, 'src', $mediaSrc, 'duration', mediaElement.duration); } }, false); @@ -80,7 +90,7 @@ mediaElement.addEventListener('timeupdate', function(e) { #if($r.isTrue($listenTimeUpdate)) if (!o_info.linkbusy) { - $r.openNoResponseJavaScriptCommand("timeupdate"), 'currentTime', mediaElement.currentTime, 'src', mediaElement.src, 'duration', mediaElement.duration); + $r.openNoResponseJavaScriptCommand("timeupdate"), 'currentTime', mediaElement.currentTime, 'src', $mediaSrc, 'duration', mediaElement.duration); } #end if(jQuery('#$r.getId("o_vid")').length == 0) { @@ -96,7 +106,7 @@ ## listen to end events, fired when movie is finished mediaElement.addEventListener('ended', function(e) { if (!o_info.linkbusy) { - $r.openNoResponseJavaScriptCommand("ended"), 'currentTime', mediaElement.currentTime, 'src', mediaElement.src, 'duration', mediaElement.duration); + $r.openNoResponseJavaScriptCommand("ended"), 'currentTime', mediaElement.currentTime, 'src', $sourcesSrc, 'duration', mediaElement.duration); } }, false); -- GitLab