adandelion

诗词在线 http:/www.chinapoesy.com


诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|现代诗歌

博客园 首页 联系 订阅 管理

这里和发送没一点关系,只实现简单的预览(HTML)功能,把各帧的内容读取到JS数组中,完全是用JavaScript客户端实现的。每一帧持续指定的时间(秒)各帧循环显示。因为无法直接修改embed的SRC所以只能使用DIV的innerHTML来实现了。各帧的持续时间通过setTimeout()来实现的。

ShowMMS.aspx

<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="0">
    
<TR>
        
<TD></TD>
        
<TD width="250" height="200" valign="top"><div id="PnlContent"><!-- 显示正文图片等< -->/div></TD>
        
<TD></TD>
    
</TR>
    
<TR>
        
<TD></TD>
        
<TD width="250" height="40" valign="top"><div id="PnlBgSound"><!-- 背景音乐 --></div></TD>
        
<TD></TD>
    
</TR>
    
<TR>
        
<TD></TD>
        
<TD align="center"><div id="PnlBootom">
            
<input type="submit" name="BtnClose" value="关闭" id="BtnClose" onclick="window.close();return false" /></div></TD>
        
<TD></TD>
    
</TR>
</TABLE>

ShowMMS.aspx.cs主要内容

/// <summary>
/// 生成多帧预览,背景音乐格式为amr/mid
///其实就是生成循环显示每一帧的JavaScript。
/// </summary>
/// <param name="strParentid"></param>

private void ShowMMSMulti(string strParentid)
{
    
string strSql = "select * from MMS_Frames where parentid ="+strParentid;
    DataSet ds 
= new DataSet();
    ds 
= connE.getDs(strSql);
    DataTable dt 
= ds.Tables[0];

    StringBuilder builder 
= new StringBuilder();
    builder.Append(
"\n<script>\n");
    builder.Append(
"var array1 = new Array();\n");
    
int ii=0;
    
//循环读出各帧的正文(图片)、背景音乐
    foreach (DataRow row in dt.Rows)
    
{
        builder.Append(
"array1["+ii+"] = new Array();\n");
        
//正文(包括图片)
        builder.Append("array1["+ii+"][0] = \""
                + row["HTMLContent"].ToString().Replace("\r\n","<br>").Replace("\"","'")+"\";\n");
        //背景音乐文件
        string strBgSound = row["Bgsound"].ToString();
        strBgSound 
= System.Configuration.ConfigurationSettings.AppSettings["BgSoundURL"].ToString()
                
+ strBgSound.Substring(strBgSound.IndexOf("uploadfiles"));
        builder.Append(
"array1["+ii+"][1] =\"<embed autostart='true' loop='-1'  controls='ControlPanel' "
                + "width='0' height='0' src='"+strBgSound+"'>\";\n");
        //背景音乐持续时间(秒)
        builder.Append("array1["+ii+"][2] = "+row["keeptime"].ToString()+";\n");
        ii
++;
    }


    builder.Append(
"setTimeout(\"show(0)\",0);//这里的0是用来设置第一一运行的延时.\n");
    builder.Append(
"function show(index)\n{\n");
    builder.Append(
"var tempIndex,tempTime; //tempIndex是当前一级数组的下标;tempTime是当前一级数组要持续的时间.\n");
    builder.Append(
"if (index == array1.length) //3是一级数组个数.\n{\n");
    builder.Append(
"index = -1;//因为这是一级数组最后一个,进行下一个一级数组的循环是下标应为0,但下面index++的,所以现在置为-1;\n");
    builder.Append(
"tempTime =0;//一级数组循环完毕后进入第二次循环时候的延时.\n");
    builder.Append(
"tempIndex =array1.length-1 //2是一级数组的倒数第二个数组.\n}\n");
    builder.Append(
"else\n{\n");
    builder.Append(
"tempTime = array1[index][2];\n");
    builder.Append(
"tempIndex = index;\n}\n");
    builder.Append(
"PnlContent.innerHTML = array1[tempIndex][0];\n");
    builder.Append(
"PnlBgSound.innerHTML = array1[tempIndex][1];\n");
    builder.Append(
"index++;\n");
    builder.Append(
"//alert(index+\"AA\"+tempTime);\n");
    builder.Append(
"setTimeout(\"show(\"+index+\")\",tempTime);\n}\n");
    builder.Append(
"</script>\n");
    
//注册JS脚本
    
//Page.RegisterClientScriptBlock("showMMS",builder.ToString());
    Page.RegisterStartupScript("showMMS",builder.ToString());
}

上面生成的JS如下(两帧的例子)
<script>
var array1 = new Array();
array1[
0= new Array();
array1[
0][0= "<P>正文第一帧内容</P><br><P><IMG src='http://localhost/uploadfiles/baozang/SMIL/200512191573.gif'></P>";
array1[
0][1="<embed autostart='true' loop='-1' controls='ControlPanel' width='0' height='0' src='http://localhost/uploadfiles/baozang/SMIL/20051219105129.mid'>";
array1[
0][2= 10000;
array1[
1= new Array();
array1[
1][0= "<P>正文第二帧内容</P><br><P><IMG src='http://localhost/uploadfiles/baozang/SMIL/2005121915723.gif'></P>";
array1[
1][1="<embed autostart='true' loop='-1' controls='ControlPanel' width='0' height='0' src='http://localhost/uploadfiles/baozang/SMIL/2005121915342.amr'>";
array1[
1][2= 10000;

setTimeout(
"show(0)",0);//这里的0是用来设置第一帧运行的延时.

function show(index)
{
    
var tempIndex,tempTime; //tempIndex是当前一级数组的下标;tempTime是当前一级数组要持续的时间.
    if (index == array1.length) //3是一级数组个数.
    {
        index 
= -1;//因为这是一级数组最后一个,进行下一个一级数组的循环是下标应为0,但下面index++的,所以现在置为-1;
        tempTime =0;//一级数组循环完毕后进入第二次循环时候的延时.
        tempIndex =array1.length-1 //2是一级数组的倒数第二个数组.
    }

    
else
    
{
        tempTime 
= array1[index][2];
        tempIndex 
= index;
    }

    PnlContent.innerHTML 
= array1[tempIndex][0];
    PnlBgSound.innerHTML 
= array1[tempIndex][1];
    index
++;
    
//alert(index+"AA"+tempTime);
    setTimeout("show("+index+")",tempTime);
}

</script>

我只想到了这个方法。不知道有更好的方法不?


posted on 2005-12-19 22:16  猪头  阅读(3338)  评论(3编辑  收藏  举报

欢迎访问诗词在线http://www.chinapoesy.com   诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|古典诗歌|现代诗歌|古典诗词|现代诗词|诗歌可以陶冶你的情操、丰富你的生活,让你更具内涵。诗词在线打造中国最好的诗词社区!

诗词在线社区

126在线阅读网 历史书籍、文学书籍、小说。。。