如何在Apex页面中显示Salesforce CRM Content视频?

时间:2013-06-19 20:24:19

标签: video salesforce crm

希望使用Salesforce CRM内容文档来存储视频文件以及外部视频链接的链接(比如说YouTube视频)。事实上,我已经提供了两个内容,一个是实际视频,另一个是YouTube视频的链接。如何在Apex页面中访问和显示它们?

2 个答案:

答案 0 :(得分:0)

我正在与您分享我的部分代码,我希望这会有所帮助

1在SF Object中创建包含YouTubevideoIDContentDocumentIdimgUrl字段的内容。

2创建具有

的类
public string link {get;set;}
public string tendingAction {get;set;}
public string link {get;set;}

3通过此逻辑

填充此内容
public void updateActionAndImege(){
        if(this.YouTubevideoID!=null && this.YouTubevideoID!=''){
            this.tendingAction = 'loadVideo(\''+YouTubevideoID+'\');';
            this.link = 'https://youtube.com/watch?v='+YouTubevideoID;
        }
        if(this.ContentDocumentId!=null && this.ContentDocumentId!=''){
            this.tendingAction = 'OverlayDialogElement.showFilePreview(\'docViewerOverlay\',\'title_'+ContentDocumentId+'\',\'/_swf/121310/sfc\',\''+ContentDocumentId+'\',\'chatter_bubble\',\'false\',\'docViewerContainer\',false,\'docx\',false);';
            this.link = '/'+ContentDocumentId;
        }
        if(this.imgUrl==null || this.imgUrl==''){
            if(this.YouTubevideoID!=null && this.YouTubevideoID!=''){
                this.imgUrl = 'https://img.youtube.com/vi/'+YouTubevideoID+'/hqdefault.jpg';
                isYouTubeImg = true;    
            }
            if(this.ContentDocumentId!=null && this.ContentDocumentId!='')
                this.imgUrl = 'https://c.cs15.content.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId='+ContentDocumentId+'&operationContext=CHATTER';
        }

}

4在页面上显示此课程

<img src="{!cl.imgUrl}" alt="Click to preview" class="contentThumbnail {!IF(cl.isYouTubeImg,'yt_thumb_small','')}" title="Click to preview" id="ext-gen4"/>
 <a class="view_m" href="javascript:{!cl.tendingAction}">View </a>

6 JS for YouTube Load

 function loadVideo(videoID) {
        loadPopup();
        if(ytplayer) {
            ytplayer.loadVideoById(videoID);
        }
        else{
            loadPlayer(videoID);
        }
      }

      // This function is called when an error is thrown by the player
      function onPlayerError(errorCode) {
        alert("An error occured of type:" + errorCode);
      }

      // This function is automatically called by the player once it loads
      function onYouTubePlayerReady(playerId) {
        ytplayer = document.getElementById("ytPlayer");
        ytplayer.addEventListener("onError", "onPlayerError");
        centerPopup();
        ytplayer.playVideo();
      }

      // The "main method" of this sample. Called when someone clicks "Run".
      function loadPlayer(videoID) {
        // The video to load
        var videoID = videoID;
        // Lets Flash from another domain call JavaScript
        var params = { allowScriptAccess: "always" };
        // The element id of the Flash embed
        var atts = { id: "ytPlayer" };

        //var pageHeight =  $(window).height();
        var pageWidth =  $(window).width(); var tWidth; var tHeight;
        if(pageWidth <= 760) {tHeight = 278; tWidth = 440;}
        if(pageWidth > 760 && pageWidth <= 980){tHeight = 378; tWidth = 540;}  
        if(pageWidth > 980) {tHeight = 478; tWidth = 640;}
        // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)

        swfobject.embedSWF("https://www.youtube.com/v/" + videoID + 
                           "?version=3&enablejsapi=1&playerapiid=player1", 
                           "videoDiv", tWidth, tHeight, "9", null, null, params, atts);
      }

答案 1 :(得分:0)

您可能必须以这种方式呼叫以避免州长限制

[NAME].force.com/sfc/servlet.shepherd/version/download/[CONTENTVERSIONID]

可能还需要一些额外的配置才能实现此功能。请参阅以下链接:

Make ContentVersion downloadable