www.webdeveloper.com
Results 1 to 4 of 4

Thread: Execute function when play button is clicked in html5 audio player

  1. #1
    Join Date
    Sep 2011
    Posts
    31

    Execute function when play button is clicked in html5 audio player

    Is it possible to detect when the play button in the html5 audio player is clicked? For example:

    Code:
    <audio controls>
        <source src="music.mp3"/>
        <source src="music.ogg" />
    </audio>
    ....
    ....
    $('playbutton').on('click', function(e){
        //some functions
    });

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787

  3. #3
    Join Date
    Sep 2011
    Posts
    31
    I tried this but it doesn't do anything, no alert is produced when I click play button:
    Code:
    $(audio)[0].onplay= function(e){
        alert('playing');
    };
    ...
    ...
    <audio controls>
        <source src="music.mp3"/>
        <source src="music.ogg" />
    </audio>
    What is the [0] for?

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    oops:

    Code:
    $('audio')[0].onplay= function(e){
        //some functions
    };

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles