use of org.olat.modules.video.manager.VideoMediaMapper in project OpenOLAT by OpenOLAT.
the class VideoDisplayController method loadVideo.
/**
* Internal helper to do the actual video loading, checking for transcoded versions and captions
* @param ureq
* @param video
*/
private void loadVideo(UserRequest ureq, VFSLeaf video) {
mainVC.contextPut("title", entry.getDisplayname());
String desc = (descriptionText != null ? descriptionText : entry.getDescription());
setText(desc, "description");
String authors = entry.getAuthors();
mainVC.contextPut("authors", (StringHelper.containsNonWhitespace(authors) ? authors : null));
if (video != null) {
// get resolution of master video resource
Size masterResolution = videoManager.getVideoResolutionFromOLATResource(entry.getOlatResource());
String masterTitle = videoManager.getDisplayTitleForResolution(masterResolution.getHeight(), getTranslator());
String masterSize = " (" + Formatter.formatBytes(videoManager.getVideoMetadata(entry.getOlatResource()).getSize()) + ")";
boolean addMaster = true;
// Mapper for Video
String masterMapperId = "master-" + entry.getOlatResource().getResourceableId();
String masterUrl = registerCacheableMapper(ureq, masterMapperId, new VideoMediaMapper(videoManager.getMasterContainer(entry.getOlatResource())));
mainVC.contextPut("masterUrl", masterUrl);
// Mapper for versions specific because not in same base as the resource itself
String transcodingMapperId = "transcoding-" + entry.getOlatResource().getResourceableId();
VFSContainer transcodedContainer = videoManager.getTranscodingContainer(entry.getOlatResource());
String transcodedUrl = registerCacheableMapper(ureq, transcodingMapperId, new VideoMediaMapper(transcodedContainer));
mainVC.contextPut("transcodedUrl", transcodedUrl);
// Add transcoded versions
List<VideoTranscoding> videos = videoManager.getVideoTranscodings(entry.getOlatResource());
List<VideoTranscoding> readyToPlayVideos = new ArrayList<>();
List<String> displayTitles = new ArrayList<>();
int preferredAvailableResolution = 0;
for (VideoTranscoding videoTranscoding : videos) {
if (videoTranscoding.getStatus() == VideoTranscoding.TRANSCODING_STATUS_DONE) {
readyToPlayVideos.add(videoTranscoding);
// Check if at least one has equal height, else use master as resource
addMaster &= videoTranscoding.getHeight() < masterResolution.getHeight();
// Use the users preferred resolution or the next higher resolution
if (videoTranscoding.getResolution() >= userPreferredResolution.intValue()) {
preferredAvailableResolution = readyToPlayVideos.size() - 1;
}
// Calculate title. Standard title for standard resolution, original title if not standard resolution
String title = videoManager.getDisplayTitleForResolution(videoTranscoding.getResolution(), getTranslator());
displayTitles.add(title);
}
}
mainVC.contextPut("addMaster", addMaster);
mainVC.contextPut("masterTitle", masterTitle + masterSize);
mainVC.contextPut("videos", readyToPlayVideos);
mainVC.contextPut("displayTitles", displayTitles);
mainVC.contextPut("useSourceChooser", Boolean.valueOf(readyToPlayVideos.size() > 1));
mainVC.contextPut(GUIPREF_KEY_PREFERRED_RESOLUTION, preferredAvailableResolution);
// Check for null-value posters
VFSLeaf poster = videoManager.getPosterframe(entry.getOlatResource());
mainVC.contextPut("usePoster", Boolean.valueOf(poster != null && poster.getSize() > 0));
// Load the track from config
Map<String, String> trackfiles = new HashMap<String, String>();
Map<String, VFSLeaf> configTracks = videoManager.getAllTracks(entry.getOlatResource());
for (HashMap.Entry<String, VFSLeaf> track : configTracks.entrySet()) {
trackfiles.put(track.getKey(), track.getValue().getName());
}
mainVC.contextPut("trackfiles", trackfiles);
// Load video chapter if available
mainVC.contextPut("hasChapters", videoManager.hasChapters(entry.getOlatResource()));
// Add duration without preloading video
String duration = entry.getExpenditureOfWork();
if (!StringHelper.containsNonWhitespace(duration)) {
duration = "00:00";
}
mainVC.contextPut("duration", duration);
}
}
Aggregations