Adding Sound to Android PhoneGap

This commit is contained in:
Joe Bowser 2008-12-18 16:36:11 -08:00
parent a32ae0f28a
commit fca16adf1d

View File

@ -1,10 +1,13 @@
package com.nitobi.phonegap; package com.nitobi.phonegap;
import java.io.IOException;
import android.content.Context; import android.content.Context;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.location.Location; import android.location.Location;
import android.location.LocationManager; import android.location.LocationManager;
import android.location.LocationListener; import android.location.LocationListener;
import android.media.MediaPlayer;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Vibrator; import android.os.Vibrator;
@ -86,6 +89,24 @@ public class PhoneGap{
}); });
} }
public void playSound(final String filename)
{
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("file:///android_asset/" + filename);
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
//TO-DO: Load a Javascript Exception thrower
} catch (IllegalStateException e) {
//TO-DO: Load a Javascript Exception thrower
} catch (IOException e) {
//TO-DO: Load a Javascript Exception thrower
}
}
public String outputText(){ public String outputText(){
String test = "<p>Test</p>"; String test = "<p>Test</p>";
return test; return test;