views:

102

answers:

1

I'm trying to use JQTouch to make a basic mobile site to play a list of audio files. I'm trying to make a simple playlist of tracks to be used in an art exhibit here at school. Sort of like those walking tours you may have seen. When I link to an mp3 file in an unordered list the browser doesn't open the file and start playing it. It simply throws up trash text.

This happens both in a regular web browser as well as my iPhone and Android phones. If I specify the link destination as _blank it will work but opens the file in another window which has to be closed to go back to the mobile site. I would prefer for a user to simply click on the link and have the phone start playing the audio.

I tried working with the audio tags for HTML5 but had trouble making them work. The player would not show or did something similar to the problem mentioned above.

What's strange is that after clicking on the link the browser shows me that the link is #undefined.

To be fair I'm not all that great with Javascript so it might be something fairly obvious but so far it eludes me. Thanks for the help.

You can see my mockup at http://trinity.edu/rchapman/iphone/

A: 

You can't link directly to an MP3 file in HTML and have it play... You are going to have to do some javascript here:

In your script section:

change

<script type="text/javascript" charset="utf-8">
    $.jQTouch({
        icon: 'tower_logo.png',
        statusBar: 'black'
    });
</script>

to

<script type="text/javascript" charset="utf-8">
    $.jQTouch({
        icon: 'tower_logo.png',
        statusBar: 'black'
    });
            $(document).ready(function () {
                    var audio = $('#audio');
                    $('#audio1').tap(function() { audio.attr('src', 'audio1.mp3')[0].play()});
                    $('#audio2').tap(function () {audio.attr('src', 'audio2.mp3')[0].play()});
            });
</script>

change

<ul class="edgetoedge">
    <li><a href="audio1.mp3">Item 1</a></li>
    <li><a href="audio2.mp3">Item 2</a></li>
</ul>

to:

<audio id="audio"></audio>

<a href="#" class="whiteButton" id="audio1">Item 1</a>
<a href="#" class="whiteButton" id="audio2">Item 2</a> 

See the audio tag, and html5 rocks for more details.

Kris Erickson
Thanks for the reply Kris. I did as you suggested but for some reason it appears this makes the elements merely disappear entirely. I updated the page to reflect the code changes on the following link. I also found a workaround that's less than ideal but seems to get me almost there using the audio tag rather than the href link. Thanks for your time and help.http://trinity.edu/rchapman/iphone/index2.html#homehttp://trinity.edu/rchapman/mobile/#home
rschapman
The audio tag, it appears, has to be closed with a full tag (see the changes). That and I messed up the jQuery (early morning post, no testing, no coffee). See http://jsbin.com/ojefe3/edit for the complete solution.
Kris Erickson
That's great. Thanks for the help. One interesting note when I click on the items it plays the same audio file for both. I will try and trouble shoot it in the morning. If there's anything off the top of your head that jumps out I'd appreciate it. Thanks again for all of your help.
rschapman
Weird the link at http://jsbin.com/ojefe3#home works for me for the two different audio files. However, their is a glitch in that the audio tag shows visibly on the iphone, solution would be to position it waaaaay of screen...
Kris Erickson