📄 htmlembed.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.common.components.embed;import biz.tbuy.common.components.TbuyExtensionsFilter;import java.io.IOException;import javax.faces.component.UIComponentBase;import javax.faces.context.FacesContext;import javax.faces.context.ResponseWriter;/** * 这是一个音乐组件,支持lrc同步歌词!内含一个Mediaplay播放器!用于在网页中播放音乐, * 最简单的使用方法,指定两个属性即可:url, lrc 即音乐文件的地址及lrc歌词地址!可以 * 是网络或是站内地址! 使用该组件需要配置过滤器TbuyExtensionsFilter,请查看web.xml<br> * 存在的问题,因为内含的是MediaPlay播放器,所以在火狐(firefox)或其他浏览器可能无法 * 实现歌词同步! * @version 1.1 * @author huliqing * 最后修改:2007-12-06 * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class HtmlEmbed extends UIComponentBase{ private String _PATH = "biz/tbuy/common/components/embed/"; private String _SCRIPT = "embed.js"; private String _IMG_PLAYING = "playing.gif"; private String _BACKGROUND = "background.jpg"; private String _IMG_PLAY = "play.jpg"; private String _IMG_STOP = "stop.jpg"; private String _IMG_PAUSE = "pause.jpg"; public String getFamily() { return null; } @Override public void encodeBegin(FacesContext fc) throws IOException { String visible = (String)getAttributes().get("visible"); if (visible != null && (visible.equals("false") || visible.equals("0"))) { return; } ResponseWriter rw = fc.getResponseWriter(); String clientId = getClientId(fc); String bg = fc.getExternalContext().getRequestContextPath() + TbuyExtensionsFilter.TBUY_EXT_ID + TbuyExtensionsFilter.REQUEST_IMG + "=" + _PATH + _BACKGROUND; String style = "width:475px;height:22px;" + "padding:3px;" + //"border:1px solid #808080;" + "background: url("+ bg +");" + "font-family: 华文楷体;" + "font-size: 14px;" + "color:#00FF00;" + (String)getAttributes().get("style"); encodeScript(fc); // script资源 rw.startElement("div", this); rw.writeAttribute("id", clientId, null); rw.writeAttribute("style", style, null); encodePlayingImg(fc, clientId); // encodeMediaPlay2(fc, clientId); // .渲染播放器 encodeCurTime(fc, clientId); // .渲染当前播放时间区 encodeOutput(fc, clientId); // .渲染当前歌词区 encodeControls(fc, clientId); // .渲染控制按钮 rw.endElement("div"); encodeOutput2(fc, clientId); // .渲染所有歌词区 encodeOnStart(fc, clientId); // .渲染LRC歌词请求 } private void encodePlayingImg(FacesContext fc, String clientId) throws IOException { ResponseWriter rw = fc.getResponseWriter(); String contentPath = fc.getExternalContext().getRequestContextPath(); rw.startElement("div", this); if (clientId != null) rw.writeAttribute("id", clientId + ":playing", null); rw.writeAttribute("style", "float:left;margin-top:3px;margin-left:2px", null); rw.startElement("img", this); rw.writeAttribute("src", contentPath + TbuyExtensionsFilter.TBUY_EXT_ID + TbuyExtensionsFilter.REQUEST_IMG + "=" + _PATH + _IMG_PLAYING, null); rw.endElement("img"); rw.endElement("div"); } private void encodeScript(FacesContext fc) throws IOException { ResponseWriter rw = fc.getResponseWriter(); String contentPath = fc.getExternalContext().getRequestContextPath(); rw.startElement("script", this); rw.writeAttribute("type", "text/javascript", null); rw.writeAttribute("src", contentPath + TbuyExtensionsFilter.TBUY_EXT_ID + TbuyExtensionsFilter.REQUEST_SCRIPT + "=" + _PATH + _SCRIPT, null); rw.endElement("script"); } private void encodeMediaPlay2(FacesContext fc, String clientId) throws IOException { String id; String url; String autoStart; String playCount; String invokeURLs; String defaultFrame; String balance; String enabled; String enableContextMenu; String rate; String currentPosition; String currentMarker; String baseURL; String stretchToFit; String volume; String mute; String uiMode; String windowlessVideo; String fullScreen; String enableErrorDialogs; String SAMIStyle; String SAMILang; String SAMIFilename; url = (String)getAttributes().get("url"); autoStart = (String)getAttributes().get("autoStart"); playCount = (String)getAttributes().get("playCount"); invokeURLs = (String)getAttributes().get("invokeURLs"); defaultFrame = (String)getAttributes().get("defaultFrame"); balance = (String)getAttributes().get("balance"); enabled = (String)getAttributes().get("enabled"); enableContextMenu = (String)getAttributes().get("enableContextMenu"); rate = (String)getAttributes().get("rate"); currentPosition = (String)getAttributes().get("currentPosition"); currentMarker = (String)getAttributes().get("currentMarker"); baseURL = (String)getAttributes().get("baseURL"); stretchToFit = (String)getAttributes().get("stretchToFit"); volume = (String)getAttributes().get("volume"); mute = (String)getAttributes().get("mute"); uiMode = (String)getAttributes().get("uiMode"); windowlessVideo = (String)getAttributes().get("windowlessVideo"); fullScreen = (String)getAttributes().get("fullScreen"); enableErrorDialogs = (String)getAttributes().get("enableErrorDialogs"); SAMIStyle = (String)getAttributes().get("SAMIStyle"); SAMILang = (String)getAttributes().get("SAMILang"); SAMIFilename = (String)getAttributes().get("SAMIFilename"); ResponseWriter rw = fc.getResponseWriter(); rw.startElement("div", this); rw.writeAttribute("style", "float:left;", null); rw.startElement("object", this); rw.writeAttribute("classid", "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6", null); rw.writeAttribute("codebase", "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112", null); rw.writeAttribute("align", "baseline", null); rw.writeAttribute("border", "0", null); rw.writeAttribute("standby", "Loading Microsoft Windows Media Player components...", null); rw.writeAttribute("type", "application/x-oleobject", null); rw.writeAttribute("style", "float: baseline", null); rw.writeAttribute("width", "0", null); rw.writeAttribute("height", "0", null); if (clientId != null) rw.writeAttribute("id", clientId + ":player", null); if (url != null) encodeParam(rw, "url", url); if (autoStart != null) encodeParam(rw, "autoStart", autoStart); if (playCount != null) encodeParam(rw, "playCount", playCount); if (invokeURLs != null) encodeParam(rw, "invokeURLs", invokeURLs); if (defaultFrame != null) encodeParam(rw, "defaultFrame", defaultFrame); // 调整左右声道平衡,同上面旧播放器代码,默认 0 if (balance != null) encodeParam(rw, "Balance", balance); // 播放器是否可人为控制,默认 -1 if (enabled != null) encodeParam(rw, "enabled", enabled); // 是否启用上下文菜单,默认 -1 if (enableContextMenu != null) encodeParam(rw, "enableContextMenu", enableContextMenu);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -