Play an Audio File with PhoneGap


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $( '#play' )
  2. .bind( 'touchstart', function( e ) {
  3. if( media == null )
  4. {
  5. $( this ).attr( 'src', 'assets/play.down.png' );
  6. } else {
  7. $( this ).attr( 'src', 'assets/stop.down.png' );
  8. }
  9. } )
  10. .bind( 'touchend', function( e ) {
  11. if( media == null )
  12. {
  13. $( this ).attr( 'src', 'assets/stop.up.png' );
  14.  
  15. media = new Media( reference, function() {
  16. media.release();
  17. media = null;
  18.  
  19. $( '#play' ).attr( 'src', 'assets/play.up.png' );
  20. }, function() {
  21. // alert( 'Problems accessing audio' );
  22. } );
  23.  
  24. media.play();
  25. } else {
  26. $( this ).attr( 'src', 'assets/play.up.png' );
  27.  
  28. media.stop();
  29. media.release();
  30. media = null;
  31. }
  32. } );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.