0

I am working on my first android app where you hit a button and it plays a .wav sound, it works great when I run the phonegap server app to test it but then when I package it as an .APK with phonegap build and install it on my phone, it does not play the .wav sounds.

$('.sound1').on('touchstart', function () {

var thissound = new Audio();
thissound.src = $(this).attr('key');
thissound.play();   
});
Jeff
  • 1,018
  • 1
  • 15
  • 33

1 Answers1

0

The changes I made were instead of new audio(); I did new Media(); and after reading Playing Local Sound In Phonegap I found out it may have had something to do with the path needing to be an absolute local path, it works in the real packaged app now. I also discovered you need too use media.release(); because of the finite number of times you can play a sound.

$('.sound1').on('touchstart', function () {
    var path = window.location.pathname;
    path = path.substr( path, path.length - 10 );
    var finalpath = 'file://' + path;
    var key = $(this).attr('key');
    var thissound = new Media( finalpath + key, function onSuccess() {
    // release the media resource once finished playing
    thissound.release();
    } );
    thissound.play();
});
Community
  • 1
  • 1
Jeff
  • 1,018
  • 1
  • 15
  • 33