讓 CommunityServer 播放 MP4

Sunday, 29 March 2009 08:02 by admin

在預設值,CommunityServer 是可以撥放 FLV 的,這是利用了 JW FLV Media Player 播放器,有點納悶的就是這套其實可以撥放 MP4 ,但在 CommunityServer 上卻沒有支援

其實這純粹只是一個 Design Issue ,只要很簡單的就能修正了,只要打開 VideoFileViewer.cs 增加一行就可以修正 case "MP4": 完畢

case "FLV":
                case "MP4": // add this line

                    requiresWrapper = false;

                    ui.Append("<embed ");
                    AddProperty(ui, "src", Globals.FullPath(page.ClientScript.GetWebResourceUrl(typeof(VideoFileViewer), "CommunityServer.Components.UI.Resources.mediaplayer.swf")));
                    AddProperty(ui, "width", width.ToString());
                    AddProperty(ui, "height", height.ToString());
                    AddProperty(ui, "allowfullscreen", "true");
                    AddProperty(ui, "flashvars", string.Format("width={0}&height={1}&file={2}", width.ToString(), height.ToString(), Globals.UrlEncode(url)));
                    ui.Append(" />");

                    break;

修正完畢後重新編譯後,要修改 CommunityServer.config 讓 fileviewer 知道 mp4 是 VideoFileViewer 負責的

<FileViewers>
        <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" urlPattern="^[^\?]*?\.(?:avi|mov|swf|ra|ram|rpm|rv|mpg|mpeg|wmv|asf|asx|wm|wvx|wmx|flv|mp4)(?:\?.*)?$" />
    </FileViewers>

當然如果不想修改 SDK,也可以自己寫一個 FileViewer 替代原本的 VideoFileViewer