how to play audio file in android

Simply you can use MediaPlayer and play the audio file. Check out this nice example for playing Audio: public void audioPlayer(String path, String fileName){ //set up MediaPlayer MediaPlayer mp = new MediaPlayer(); try { mp.setDataSource(path + File.separator + fileName); mp.prepare(); mp.start(); } catch (Exception e) { e.printStackTrace(); } }

Android: MediaPlayer setVolume function

This function is actualy wonderful. Thanks to it you can create a volume scale with any number of steps! Let’s assume you want 50 steps: int maxVolume = 50; Then to set setVolume to any value in this range (0-49) you do this: float log1=(float)(Math.log(maxVolume-currVolume)/Math.log(maxVolume)); yourMediaPlayer.setVolume(log1,log1); //set volume takes two paramater Nice and easy! And … Read more

Stopping & starting music on incoming calls

There are a few things you can do: First of all, you can listen for changes in the call state using a PhoneStateListener. You can register the listener in the TelephonyManager: PhoneStateListener phoneStateListener = new PhoneStateListener() { @Override public void onCallStateChanged(int state, String incomingNumber) { if (state == TelephonyManager.CALL_STATE_RINGING) { //Incoming call: Pause music } … Read more

Android MediaPlayer error (1, -2147483648)

Just to clarify something for anyone reading this question based on the title. When looking at the error value (1, -2147483648), the ‘1’ value corresponds to the constant in MediaPlayer.MEDIA_ERROR_UNKNOWN. -2147483648 corresponds to hexadecimal 0x80000000 which is defined as UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h This shows that the error’s source is hard to pin down as it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)