embed如何能播放多个声音文件

helloliu0915 2012-10-08 03:34:04
播放声音是用JS控制的,我想把数据库中的声音文件在GridView里显示出来,然后用户点哪个按钮就播放哪个声音,可现在只能播放第一行的,下面两行的都放不了?
这个是单独播放声音

<script language="javascript" type="text/javascript">
function ManageSoundControl(action)
{
var soundControl = document.getElementById("soundControl");
if(action == "play")
{
soundControl.play();
}
if(action == "stop")
{
soundControl.stop();
}
}
</script>
<embed id="soundControl" src="upfiles/263508.mp3" loop=false autostart=false width=10 height=10></embed>
<input id="btPlay" type="button" value="播放" onclick="ManageSoundControl('play')" />
<input id="btStop" type="button" value="停止" onclick="ManageSoundControl('stop')" />


我给改成GridView,然后就只能播放test表中的第一首歌,总共有三首歌,263508.mp3,测试9.26.WAV,测试录音9.26.pcm.这三首歌也全部取出来了。

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" >
<Columns>
<asp:TemplateField HeaderText="图标">
<ItemTemplate>
<embed id="soundControl" src="upfiles/<%#DataBinder.Eval(Container.DataItem,"soundName")%>" loop=false autostart=false width=10 height=10></embed>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="播放" >
<ItemStyle Wrap="False" Width="150px" />
<ItemTemplate>
<input id="btPlay" type="button" value="播放" onclick="ManageSoundControl('play')" />
<input id="btStop" type="button" value="停止" onclick="ManageSoundControl('stop')" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="录音文件">
<ItemStyle Wrap="False" Width="150px" />
<ItemTemplate>
<asp:Label ID="lblname" Width="150px" runat="server" Text='<%# Bind("soundName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>


public string soundName = "";
protected void Page_Load(object sender, EventArgs e)
{
DbCommand db_src = db.GetSqlStringCommand("select soundName,tid from test");
db.ExecuteNonQuery(db_src);

GridView1.DataSource = db.ExecuteDataSet(db_src).Tables[0];
GridView1.DataBind();

}
...全文
228 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
helloliu0915 2012-10-18
  • 打赏
  • 举报
回复
还是不行,用这个方法不提示错误,网页未响应了,弹出个对话框提示会导致系统变慢,是否关闭
Go 旅城通票 2012-10-17
  • 打赏
  • 举报
回复
更改下,有个函数错了
return tr.getElemenetsByTagName('embed')[0];
//===>
return tr.getElementsByTagName('embed')[0];
Go 旅城通票 2012-10-17
  • 打赏
  • 举报
回复
改成按照DOM关系来取,而不是按照ID
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"  GridLines="None"  >
<Columns>
<asp:TemplateField HeaderText="图标">
<ItemTemplate>
<embed id="soundControl" src="upfiles/<%#DataBinder.Eval(Container.DataItem,"soundName")%>" loop=false autostart=false width=10 height=10></embed>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="播放" >
<ItemStyle Wrap="False" Width="150px" />
<ItemTemplate><!---注意这里---->
<input id="btPlay" type="button" value="播放" onclick="ManageSoundControl('play',this)" />
<input id="btStop" type="button" value="停止" onclick="ManageSoundControl('stop',this)" /><!---注意这里---->
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="录音文件">
<ItemStyle Wrap="False" Width="150px" />
<ItemTemplate>
<asp:Label ID="lblname" Width="150px" runat="server" Text='<%# Bind("soundName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>

<script language="javascript" type="text/javascript">
function FindEmbed(btn) {
var tr, rst;
while (tr = btn.parentNode) { if (tr.tagName == 'TR') break; }
return tr.getElemenetsByTagName('embed')[0];
}
function ManageSoundControl(action, btn) {
var soundControl = FindEmbed(btn);
if (action == "play") { soundControl.play(); }
if (action == "stop") { soundControl.stop(); }
}
</script>
helloliu0915 2012-10-09
  • 打赏
  • 举报
回复
没人理啊?好像是embed id="soundControl"的问题,三个embed的ID全是soundControl,请问谁知道这个应该怎么解决呢,还是换种播放声音的方法?
helloliu0915 2012-10-09
  • 打赏
  • 举报
回复
自己顶

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧