How Kaltura video integration is done in confluence?
Asked by Shankar Murthy Pokala:

As the user gives the kaltura video url , i have written the code to auto convert the url to Widgetconnector macro. Can anyone help me on framing the iframe tag which is to be displayed in UI with thumbnail.


Answers:
author: Shankar Murthy Pokala
body: this was my java code and am rendering the velocity params to the vm.

```
public class KalturaWidgetRenderer implements WidgetRenderer {
 
 private final VelocityRenderService renderer;
 
 /**
 * Constructor. Used primarily to auto-wire dependencies.
 * 
 * @param renderer
 * Velocity rendering service used to render our custom template.
 */
 public KalturaWidgetRenderer(
 final VelocityRenderService renderer) {
 this.renderer = renderer;
 }
 
 /**
 * Returns the HTML to embed on the Confluence page.
 * 
 * @param url
 * Incoming URL for the Kaltura video
 * @param params
 * Velocity parameters (pre-populated with standard Confluence variables)
 */
 @Override
 public String getEmbeddedHtml(
 final String url,
 final Map<String, String> params) {
 
 String[] urlSegments = url.split("/");
 String videoId = "";
 if (urlSegments.length > 1) {
 videoId = urlSegments[(urlSegments.length - 1)];
 } else {
 params.put("error", "Invalid source URL: " + url);
 }
 for(int i=0;i<urlSegments.length;i++){
 System.out.println("url "+i+urlSegments[i]);
 }
 params.put(VelocityRenderService.TEMPLATE_PARAM, "templates/kaltura.vm");
 params.put("videoId", videoId);
 params.put("playerId", "kaltura_player_" + UUID.randomUUID().toString());
 params.put("videoSrcId", "1_swpunaa5");
 
 // For preview without width/height specified, default to 320x200
 if (params.get("width") == null) {
 params.put("width", "320");
 }
 if (params.get("height") == null) {
 params.put("height", "200");
 }
 System.out.println("render "+renderer.render(url, params));
 return renderer.render(url, params);
 }

 /**
 * @returns 'true if the incoming URL matches 'kaltura.com' 
 * (anywhere in it).
 */
 @Override
 public boolean matches(
 final String url) {
 return url.contains("kaltura.com");
 }
```

my kaltura.vm is

```
<iframe id="$playerId"
 src="https://cdnapisec.kaltura.com/p/2286491/sp/228649100/embedIframeJs/uiconf_id/39478542/partner_id/2286491?iframeembed=true&playerId=$playerId&entry_id=$videoId&flashvars[streamerType]=auto&amp;flashvars[localizationCode]=en&amp;flashvars[leadWithHTML5]=true&amp;flashvars[sideBarContainer.plugin]=true&amp;flashvars[sideBarContainer.position]=left&amp;flashvars[sideBarContainer.clickToClose]=true&amp;flashvars[chapters.plugin]=true&amp;flashvars[chapters.layout]=vertical&amp;flashvars[chapters.thumbnailRotator]=false&amp;flashvars[streamSelector.plugin]=true&amp;flashvars[EmbedPlayer.SpinnerTarget]=videoHolder&amp;flashvars[dualScreen.plugin]=true&amp;&wid=$videoSrcId" width=$width height=$height allowfullscreen webkitallowfullscreen mozAllowFullScreen frameborder="0" title="Kaltura Player">
</iframe>
```

With this code am able to play few kaltura videos.


author: Jens Kasperek
body: It would be great to have a Kaltura macro / plugin available...!


author: Shannon S
body: Hi Shankar,

I'm not clear on what it is you're asking.

Are you asking [how to add an iFrame into a Confluence page](https://confluence.atlassian.com/confkb/how-to-put-an-iframe-into-confluence-598837531.html)? Or do you require something more specific?

Please elaborate on what we can help you with and we'll be happy to assist.

Kind Regards,  
Shannon

comments: author: Shankar Murthy Pokala
body: Hi Shannon,

I pasted the kaltura url in the confluence, my code is able to auto convert that url into widget macro.

When I publish the page, i cant view the thumbnail of the video. It looks like below.

![kaltura1.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/5977iCD352092BB49AFB7/image-size/large?v=v2&px=999 "kaltura1.PNG")

I observed the code on the UI, the div tag is formed as

    <div class="widget-error">    <span class="widget-link">rcsaas.mediaspace.kaltura.com</span></div></div>

When I edit the html on UI to the below format, am able to see the kaltura thumbnail and able to play the video.

    <iframe class="conf-macro output-block" type="text/html" style="width: 400px; height: 300px" src="https://rcsaas.mediaspace.kaltura.com/media/Summer+Roses/0_t4ba0g3c/75994502https://rcsaas.mediaspace.kaltura.com/media/Summer+Roses/0_t4ba0g3c/75994502 frameborder="0" data-hasbody="false" data-macro-name="widget"></iframe>

I dont want to use available html macro plugin to be enabled manually. I want to handle this framing the div tag in java code.

I found ViewMacroErrorPlaceholderImpl.java class, from confluence source code, which forms the "widget-error" class.

Similarly, I am looking for a java class which can render the above iframe tag as response.


Tags: atl-dev

atlassian-marketplace