Delay playing audio

3 posts, 0 answers
  1. Arie Taslim
    Arie Taslim avatar
    4 posts
    Member since:
    May 2010

    Posted 27 May 2010 Link to this post

    Is it possible to delay playing the audio after users click on the "Get Audio Code" link? I would like to set a pause functionality on the link click. This is useful for accessibility usage.

    Thanks.

  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 01 Jun 2010 Link to this post

    Hi Arie,

    There is no built-in functionality, that will enable the user to pause the audio playback. However if the <embed/> or <audio/> elements support pausing the audio you could achieve this functionality with some custom JavaScript. I tested the following code, and it works in Firefox, Safari and Opera, but not in IE and Chrome (they do not support HTML5 <audio/> element):

    <%@ Page %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
     
        <script type="text/javascript">
            var paused = true;
            function PlayPause(button)
            {
                var captcha = $find("RadCaptcha1");
     
                if (captcha._objectElement)
                {
                    if (paused)
                    {
                        captcha._objectElement.Play();
                        paused = false;
                        button.value = "Pause";
                    }
                    else
                    {
                        captcha._objectElement.Pause();
                        paused = true;
                        button.value = "Play";
                    }
                }
                else if (captcha._audioElement && captcha._audioElement.play)
                {
                    captcha._audioElement.play();
     
                    if (paused)
                    {
                        captcha._audioElement.play();
                        paused = false;
                        button.value = "Pause";
                    }
                    else
                    {
                        captcha._audioElement.pause();
                        paused = true;
                        button.value = "Play";
                    }
                }
            }
        </script>
     
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            </Scripts>
        </asp:ScriptManager>
        <div>
            <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Please enter the code shown correctly."
                CaptchaTextBoxLabel="ENTER CODE" CssClass="testClass" ForeColor="Brown">
                <CaptchaImage EnableCaptchaAudio="true" />
            </telerik:RadCaptcha>
            <input type="button" onclick="PlayPause(this); return false;" value="Play" />
            <asp:Button ID="Button1" runat="server" Text="Verify Code" />
        </div>
        </form>
    </body>
    </html>


    Greetings,
    Pero
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Arie Taslim
    Arie Taslim avatar
    4 posts
    Member since:
    May 2010

    Posted 01 Jun 2010 Link to this post

    That's too bad that IE and Chrome are not supported for the suggested workaround. 
    Thanks a lot for your help Pero!
Back to Top