让Community Server 2008.5在Chrome支持播放FLV与MP4

   最近几天在看Community Server 2008.5的代码,CS中使用的FLV默认播放器是swfbject1.5的版本,此版本在Chrome浏览器中无法使用(不知道是很原因),于是在官方网站上下载了2.2的版本,拿下来一看尽是些JS(没有找到播放器文件,可能是连播放器文件都需要运行时从网上下载下来,太没意思了),没心思了,于是干脆将CS中默认的FLV播放器修改为Google的flvplayer(可以从这里下载,建议下载Maxi版本),使用起来方便多了,下面将介绍如何集成到Community Server中。

1、添加播放器到CS中

先将下载下来的播放器文件拷贝到CommunityServer.Components项目下的UI\Resources目录下,然后在Visual Studio中,将该播放器文件包含到项目中,以及打开VS中该文件的属性,将生成选项修改为"嵌入的资源",如下图:

注意,我这里将播放器的文件名修改了一下,将后面的版本信息部分去掉了(player_flv_maxi_1.6.0.swf)。

2、修改代码

打开CommunityServer.Components项目下的UI目录下的VideoFileViewer.cs文件,在类的声明部分将播放器文件声明为Web资源,注意第3行是添加上去的:

 

代码
1
2 [assembly: WebResource("CommunityServer.Components.UI.Resources.mediaplayer.swf", "application/x-shockwave-flash")]
3 [assembly: WebResource("CommunityServer.Components.UI.Resources.player_flv.swf", "application/x-shockwave-flash")]
4 [assembly: WebResource("CommunityServer.Components.UI.Resources.swfobject.js", "text/javascript")]
5 [assembly: WebResource("CommunityServer.Components.UI.Resources.silverlight.js", "text/javascript")]
6 [assembly: WebResource("CommunityServer.Components.UI.Resources.wmvplayer.js", "text/javascript")]
7 [assembly: WebResource("CommunityServer.Components.UI.Resources.wmvplayer.xaml", "application/xaml+xml")]
8 [assembly: WebResource("CommunityServer.Components.UI.Resources.insertmarkup.js", "text/javascript")]
9  namespace CommunityServer.Components
10 {
11 public class VideoFileViewer : IFileViewer
12  

 

 

 

然后在此代码文件中找到如下方法:

 

public string RenderView(string url, int width, int height)

 

定位到switch块中的case "FLV":部分,将原来的代码注释,修改成如下:

 

代码
1 case "FLV":
2 requiresWrapper = false;
3
4 ui.Append("<object ");
5 AddProperty(ui, "type", "application/x-shockwave-flash");
6 AddProperty(ui, "data", Globals.FullPath(page.ClientScript.GetWebResourceUrl(typeof(VideoFileViewer), "CommunityServer.Components.UI.Resources.player_flv.swf")));
7 AddProperty(ui, "width", width.ToString());
8 AddProperty(ui, "height", height.ToString());
9 ui.Append(">");
10
11 AddParameter(ui, "movie", Globals.FullPath(page.ClientScript.GetWebResourceUrl(typeof(VideoFileViewer), "CommunityServer.Components.UI.Resources.player_flv.swf")));
12 AddParameter(ui, "allowFullScreen", "true");
13 string strFLV = string.Format("flv={0}&title={1}&width={2}&height={3}&showstop=1&showvolume=1&showtime=1&showfullscreen=1&srt=1",
14 url, "点击播放按钮开始播放", width.ToString(), height.ToString());
15 AddParameter(ui, "FlashVars", strFLV);
16 ui.Append("</object>");

 

3、然后重新编译Web工程,就可以使用了。

 

  MP4视频类型是比较常用的类型,下面将介绍如何将使Community Server支持MP4的播放:

1、首先让CS将MP4文件的处理放到VideoFileViewer.cs代码中处理,要做如下修改:

打开communityserver.config文件,找到<FileViewers></FileViewers>中的类容:

 

代码
1 <FileViewers>
2 <add type="CommunityServer.Components.ImageFileViewer, CommunityServer.Components" extensions="gif;jpg;jpeg;bmp;png" urlPattern="^[^\?]*?\.(?:gif|jpg|jpeg|bmp|png)(?:\?.*)?extensionsquot; />
3 <add type="CommunityServer.Components.VideoFileViewer, CommunityServer.Components" extensions="avi;mov;swf;ra;ram;rpm;rv;mpg;mpeg;wmv;asf;asx;wm;wvx;wmx;flv;mp4;rm;rmvb" urlPattern="^[^\?]*?\.(?:avi|mov|swf|ra|ram|rpm|rv|mpg|mpeg|wmv|asf|asx|wm|wvx|wmx|flv|mp4|rm|rmvb)(?:\?.*)?extensionquot; />
4 <add type="CommunityServer.Components.AudioFileViewer, CommunityServer.Components" extensions="mp3;wav;wma" urlPattern="^[^\?]*?\.(?:mp3|wav|wma)(?:\?.*)?extensionsquot; />
5 <add type="CommunityServer.Components.YouTubeFileViewer, CommunityServer.Components" urlPattern="http://(?:[^.]+\.)?youtube\.com" />
6 <add type="CommunityServer.Components.SoapBoxFileViewer, CommunityServer.Components" urlPattern="http://video\.msn\.com" />
7 <add type="CommunityServer.Components.GoogleVideoFileViewer, CommunityServer.Components" urlPattern="http://video\.google\.com" />
8 <add type="CommunityServer.Components.MySpaceTVFileViewer, CommunityServer.Components" urlPattern="http://(?:vids\.myspace|myspacetv)\.com" />
9 <add type="CommunityServer.Components.YahooVideoFileViewer, CommunityServer.Components" urlPattern="http://video\.yahoo\.com" />
10 <add type="CommunityServer.Components.RevverFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?revver\.com" />
11 <add type="CommunityServer.Components.VimeoFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?vimeo\.com" />
12 <add type="CommunityServer.Components.VeohFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?veoh\.com" />
13 <add type="CommunityServer.Components.DailyMotionFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)dailymotion\.com" />
14 <add type="CommunityServer.Components.ClipShackFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?clipshack\.com" />
15 <add type="CommunityServer.Components.BlipTvFileViewer, CommunityServer.Components" urlPattern="http://[^/]*?blip.tv" />
16 <add type="CommunityServer.Components.GoFishFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?gofish.com" />
17 <add type="CommunityServer.Components.ScreencastFileViewer, CommunityServer.Components" urlPattern="http://(?:www\.)?screencast.com" />
18 <add type="CommunityServer.Components.DefaultFileViewer, CommunityServer.Components" extensions="*" urlPattern=".*" />
19 </FileViewers>
20  

 

注意第3行,在extensions属性的字符串中加入";mp4"(我这里在;flv后面),然后在urlPattern属性的字符串"^[^\?]*?\.(?:avi|mov|swf|ra|ram|rpm|rv|mpg|mpeg|wmv|asf|asx|wm|wvx|wmx|flv"后面加入"|mp4"字符串,这样,mp4文件的处理就交给CommunityServer.Components.VideoFileViewer这个类来处理了。

2、选择播放器来播放MP4视频

  上面Google的FLV播放器就可以播放MP4视频,所以很好办,在case "FLV":后面加入case "MP4":就可以了。接下来重新编译Web工程就可以了。

posted on 2009-12-28 18:23  Think...  阅读(1318)  评论(1编辑  收藏  举报