Video 如何在Apex页面中显示Salesforce CRM内容视频?
希望使用Salesforce CRM内容文档来存储视频文件和指向外部视频链接(比如YouTube视频)的链接。事实上,我已经贡献了两个内容,一个是真实的视频,另一个是YouTube视频的链接。如何在Apex页面中访问和显示它们?我正在与您分享我的部分代码,希望这能有所帮助 1在SFVideo 如何在Apex页面中显示Salesforce CRM内容视频?,video,salesforce,crm,Video,Salesforce,Crm,希望使用Salesforce CRM内容文档来存储视频文件和指向外部视频链接(比如YouTube视频)的链接。事实上,我已经贡献了两个内容,一个是真实的视频,另一个是YouTube视频的链接。如何在Apex页面中访问和显示它们?我正在与您分享我的部分代码,希望这能有所帮助 1在SF对象中创建具有YouTubevideoID,ContentDocumentId,imgUrl字段的对象 2创建具有 public string link {get;set;} public string tending
对象中创建具有YouTubevideoID
,ContentDocumentId
,imgUrl
字段的对象
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用于YouTube加载
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);
}
函数加载视频(videoID){
loadPopup();
如果(玩家){
ytplayer.loadVideoById(videoID);
}
否则{
loadPlayer(videoID);
}
}
//当播放机抛出错误时调用此函数
函数onplayerror(错误代码){
警报(“发生类型为:+errorCode的错误”);
}
//此函数在加载后由播放机自动调用
函数onYouTubePlayerReady(playerId){
ytplayer=document.getElementById(“ytplayer”);
ytplayer.addEventListener(“onError”、“onplayerror”);
centerPopup();
ytplayer.playVideo();
}
//本样本的“主要方法”。当有人单击“运行”时调用。
函数loadPlayer(视频ID){
//要加载的视频
var videoID=videoID;
//允许从另一个域调用JavaScript刷新
var params={allowScriptAccess:“始终”};
//闪存的元素id
var atts={id:“ytPlayer”};
//var pageHeight=$(窗口).height();
var pageWidth=$(窗口).width();var tWidth;var tHeight;
如果(页面宽度760&&pageWidth 980){tHeight=478;tWidth=640;}
//SWFObject处理的所有魔法(http://code.google.com/p/swfobject/)
swfobject.embeddeswf(“https://www.youtube.com/v/“+videoID+
“?版本=3&enablejsapi=1&PlayerAPI=player1”,
“videoDiv”、tWidth、tHeight、“9”、null、null、params、atts);
}
您可能必须以这种方式呼叫以避免调速器限制
[NAME].force.com/sfc/servlet.shepherd/version/download/[CONTENTVERSIONID]
可能还需要一些额外的配置才能使其正常工作。请参阅以下连结:
ContentVersion sObject的VersionData字段似乎是一条出路:我应该编写一个客户端代码(例如javascript)来调用Web服务并检索VersionData;虽然这将是一个新的挑战。Shimshon,谢谢你发布这个答案!我认为这将适用于YouTube链接内容,但我也在寻找一种方法来呈现存储实际视频文件(而不是YouTube视频链接)的视频CRM内容。我认为,我应该创建一个使用ContentVersion.VersionData来提供视频内容的页面,以及另一个使用jscript(与您的类似)来显示提供的视频的页面。