From 8769195311cc450c2b55b759f57aad8ba4efd790 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 19 Jul 2021 15:01:39 +0200 Subject: [PATCH] Fix video display. --- .../argeo/docbook/ui/AbstractDbkViewer.java | 11 ++-- .../src/org/argeo/docbook/ui/DbkVideo.java | 57 ++++++++++++------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java index 7c2b59b..e900093 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java @@ -221,13 +221,13 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke protected DbkVideo newVideo(TextSection parent, Node node) { try { - DbkVideo video = new DbkVideo(parent,getCmsEditable().canEdit()?SWT.NONE : SWT.READ_ONLY, node); + DbkVideo video = new DbkVideo(parent, getCmsEditable().canEdit() ? SWT.NONE : SWT.READ_ONLY, node); GridData gd; if (maxMediaWidth != null) { gd = new GridData(SWT.CENTER, SWT.FILL, false, false); // TODO, manage size - gd.widthHint = maxMediaWidth; - gd.heightHint = (int) (gd.heightHint * 0.5625); +// gd.widthHint = maxMediaWidth; +// gd.heightHint = (int) (gd.heightHint * 0.5625); } else { gd = new GridData(SWT.CENTER, SWT.FILL, false, false); // gd.widthHint = video.getWidth(); @@ -235,7 +235,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke } video.setLayoutData(gd); updateContent(video); - return null; + return video; } catch (RepositoryException e) { throw new JcrException("Cannot add new image " + node, e); } @@ -807,8 +807,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke return newParagraph; } - protected Paragraph sectionTitleSplitted(DbkSectionTitle sectionTitle, Node newNode) - throws RepositoryException { + protected Paragraph sectionTitleSplitted(DbkSectionTitle sectionTitle, Node newNode) throws RepositoryException { updateContent(sectionTitle); Paragraph newParagraph = newParagraph(sectionTitle.getSection(), newNode); // we assume beforeFirst is not null since there was a sectionTitle diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkVideo.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkVideo.java index af2ee84..acb266b 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkVideo.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkVideo.java @@ -58,15 +58,15 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart { Composite browserC = new Composite(wrapper, SWT.NONE); browserC.setLayout(CmsUiUtils.noSpaceGridLayout()); -// wrapper.setLayoutData(CmsUiUtils.fillAll()); - Browser browser = new Browser(browserC, SWT.NONE); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); + GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, true); gd.widthHint = getWidth(); gd.heightHint = getHeight(); browserC.setLayoutData(gd); +// wrapper.setLayoutData(CmsUiUtils.fillAll()); + Browser browser = new Browser(browserC, SWT.NONE); if (editable) { - Composite editor = new Composite(wrapper, SWT.NONE); + Composite editor = new Composite(wrapper, SWT.BORDER); editor.setLayout(new GridLayout(3, false)); editor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); String fileref = DbkUtils.getMediaFileref(mediaobject); @@ -74,7 +74,7 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart { if (fileref != null) text.setText(fileref); else - text.setMessage("Embed URL of the video."); + text.setMessage("Embed URL of the video"); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Button updateB = new Button(editor, SWT.FLAT); updateB.setText("Update"); @@ -95,22 +95,39 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart { return; } - // transform YouTube watch URL in embed - String youTubeVideoId = null; - if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) { - if ("/watch".equals(uri.getPath())) { - Map> map = NamingUtils.queryToMap(uri); - youTubeVideoId = map.get("v").get(0); + // Transform watch URL in embed + // YouTube + String videoId = null; + if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost()) + || "youtu.be".equals(uri.getHost())) { + if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) { + if ("/watch".equals(uri.getPath())) { + Map> map = NamingUtils.queryToMap(uri); + videoId = map.get("v").get(0); + } + } else if ("youtu.be".equals(uri.getHost())) { + videoId = uri.getPath().substring(1); + } + if (videoId != null) { + try { + uri = new URI("https://www.youtube.com/embed/" + videoId); + text.setText(uri.toString()); + } catch (URISyntaxException e1) { + throw new IllegalStateException(e1); + } } - } else if ("youtu.be".equals(uri.getHost())) { - youTubeVideoId = uri.getPath().substring(1); } - if (youTubeVideoId != null) { - try { - uri = new URI("https://www.youtube.com/embed/" + youTubeVideoId); - text.setText(uri.toString()); - } catch (URISyntaxException e1) { - throw new IllegalStateException(e1); + + // Vimeo + if ("vimeo.com".equals(uri.getHost())) { + videoId = uri.getPath().substring(1); + if (videoId != null) { + try { + uri = new URI("https://player.vimeo.com/video/" + videoId); + text.setText(uri.toString()); + } catch (URISyntaxException e1) { + throw new IllegalStateException(e1); + } } } @@ -175,7 +192,7 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart { @Override protected void setContainerLayoutData(Composite composite) { - composite.setLayoutData(CmsUiUtils.fillAll()); + composite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true)); } @Override -- 2.30.2