Issues with loading sound to UIWebView using JavaScript

Discussion in 'iOS Programming' started by Danneman101, Jan 7, 2009.

  1. macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    Ive got a UIWebView that loads a local html-page, which in turn should play a wav-file also located locally (in the resource-folder of the project).

    Anyway, two methods almost works:

    1. Simple href-call
    Code:
    <a href="test.wav">Play Sound</a>
    
    Problem with this method is that it loads the sound in Quicktime, but when finished (or clicking "Done" in QT), it doesnt return to the original page but to a blank one. Ive tried target="self" in the href-tag, but that doesnt seem to work...


    2. Using javascript
    Code:
    <script>
    function EvalSound(soundobj) {
    	var thissound= eval("document."+soundobj);
    	thissound.Play(true);
    }
    </script>
    
    <embed src="test.wav" autostart=false width=0 height=0 name="sound1"
    
    enablejavascript="true">
    <form>
    <input type="button" value="Play Sound" onClick="EvalSound('sound1')">
    </form>
    
    There are two problems with this approach:

    a. The sound doesnt restart, but continiues playing from where I last cut it short. Is there a "restart"-attribute to the <embed>-tag?

    b. [ solved ]There is an icon displayed on top of the button of an overcrossed speaker, indicating that there is no sound available. This is from the <embed>-tag. When pressing the form-button, however, it does work. Can this icon be removed, since its missleading? For instance, is there an "invisible"-property in <embed>?


    [*edit ]

    Solution to b.
    Code:
    <embed src="test.wav" autostart="false" controls="SmallConsole" width="100" height="100" hidden="true" name="sound1" enablejavascript="true" loop="false">
    
     

Share This Page