想使用 Salesforce CRM Content Documents 来存储视频文件和外部视频链接(比如说 YouTube 视频)的链接。事实上,我已经贡献了两个内容,一个是实际视频,另一个是 YouTube 视频的链接。如何在 Apex 页面中访问和显示它们?
问问题
1970 次
2 回答
0
我正在与您分享我的部分代码,希望对您有所帮助
Object
1 在具有YouTubevideoID
, ContentDocumentId
,imgUrl
字段的 SF 中创建。
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 个用于 YouTube 加载的 JS
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);
}
于 2013-06-20T05:55:18.520 回答
0
您可能必须以这种方式调用以避免州长限制
[NAME].force.com/sfc/servlet.shepherd/version/download/[CONTENTVERSIONID]
可能还需要一些额外的配置才能使其正常工作。请参阅以下链接:
于 2014-07-18T13:29:11.583 回答