无法使用ASP.NET中的Object标签播放声音 [英] Unable to play sound using Object tag in ASP.NET

查看:83
本文介绍了无法使用ASP.NET中的Object标签播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好......我有一个gridview,其中我正在显示波形文件路径以及指示立即播放的按钮。现在一切正常,即我正在获取记录(使用gridview的RowCommand方法)并显示路径等。但我无法使用嵌入在asp中的< object> 标记来播放这些声音。 net使用文字控件。这是我正在做的事情

< script runat =server> 
void OnRowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName.Equals(立即播放))
{
int index = Convert。 ToInt32(e.CommandArgument); //这将从gridview获得rowid
GridViewRow row = gridCalls.Rows [index];
txt1.Text = row.Cells [5] .Text; // sql server数据库中的第二列

myLiteral.Text =< object>;
myLiteral.Text + =< param name ='autostart'value ='true'>;
myLiteral.Text + =< param name ='src'value ='Likh Raha.mp3'>;
myLiteral.Text + =< param name ='autoplay'value ='true'>;
myLiteral.Text + =< param name ='controller'value ='true'>;
myLiteral.Text + =< embed src ='Likh Raha.mp3'controller ='true'autoplay ='true'autostart ='True'type ='audio / wav'/>;
myLiteral.Text + =< / object>;
}
}

解决方案

您好如果需要在运行时渲染此对象,请创建一个自定义控件这个对象。

您可以将该对象添加到网格视图单元格控件集合。



以下是播放声音的自定义类的链接



http://www.vbdotnetheaven。 com / UploadFile / scottlysle / PlaySoundsInASPX09032006083212AM / PlaySoundsInASPX.aspx [ ^ ]


你好朋友请使用文字的标签控件。

因为在我的应用程序中这个代码运行正常。 />

 protected void GridView1_RowCommand(object sender,GridViewCommandEventArgs e) 
{
if(e.CommandName.Equals(立即播放))
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gridCalls.Rows [index];
string songname = row.Cells [5] .Text; // sql server数据库中的第二列
StringBuilder str = new StringBuilder();
str.Append(< object width =' 300px' height =' 300px' > );
str.Append(< param 名称 =' autostart' value =' true' > );
str.Append(< param 名称 =' src' value =' songs /+ songname +' > );
str.Append(< param 名称 =' autoplay' value =' true' > );
str.Append(< param name =' controller' value =' true' > );
str.Append(< embed width =' 300px' height =' 300px' src =' songs /+ songname +' 控制器 =' true' autoplay =' true' autostart =' True' type =' audio / wav' / > );
str.Append(< / object > );

LoadPlayer.Text = str.ToString(); //这里的loadplayer是标签控件
}
}


我认为您错过了将文字控件(myLiteral)添加到页面上的控件集合的命令。例如,如果您的gridview位于标有pnl1的asp面板上,那么在myLiteral.Text + =< / object>;行之后,您需要一个命令pnl1.Controls.Add(myLiteral)

hello guys... I have a gridview inwhich I am showing the wave file paths along with the button stating "Play Now". Now everything is working OK i.e. I'm getting the records (using RowCommand method of gridview) and showing the paths etc. But I am unable to play these sounds using <object> tag embedded in asp.net using the literal control. Here is what I am doing

<script runat="server">
    void OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Play Now"))
        {
            int index = Convert.ToInt32(e.CommandArgument); //this will get rowid from gridview
            GridViewRow row = gridCalls.Rows[index];
            txt1.Text = row.Cells[5].Text; // second column in the sql server database

            myLiteral.Text = "<object>";
            myLiteral.Text += "<param name='autostart' value='true'>";
            myLiteral.Text += "<param name='src' value='Likh Raha.mp3'>";
            myLiteral.Text += "<param name='autoplay' value='true'>";
            myLiteral.Text += "<param name='controller' value='true'>";
            myLiteral.Text += "<embed src='Likh Raha.mp3' controller='true' autoplay='true' autostart='True' type='audio/wav' />";
            myLiteral.Text += "</object>";
        }
    }

解决方案

Hi If you need to render this object at runtime create a custom control which reders this object.
You may add that object to grid view cells control collection.

Here is the link for a custom class for playing sound

http://www.vbdotnetheaven.com/UploadFile/scottlysle/PlaySoundsInASPX09032006083212AM/PlaySoundsInASPX.aspx[^]


Hello friend please use label control insted of literal.
Because in my application this code will running fine.

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Play Now"))
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = gridCalls.Rows[index];
        string songname = row.Cells[5].Text; // second column in the sql server database
        StringBuilder str = new StringBuilder();
        str.Append("<object width='300px' height='300px'>");
        str.Append("<param name='autostart' value='true'>");
        str.Append("<param name='src' value='songs/" + songname + "'>");
        str.Append("<param name='autoplay' value='true'>");
        str.Append("<param name='controller' value='true'>");
        str.Append("<embed width='300px' height='300px' src='songs/" + songname + "' controller='true' autoplay='true' autostart='True' type='audio/wav' />");
        str.Append("</object>");

        LoadPlayer.Text = str.ToString();//here loadplayer is label control
    }
}


I think you're missing the command to add the literal control (myLiteral) to the collection of controls on your page. For example, if your gridview is on an asp panel labeled "pnl1", then after your "myLiteral.Text += "</object>"; line, you need a command that says "pnl1.Controls.Add(myLiteral)"


这篇关于无法使用ASP.NET中的Object标签播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆