I have written the most basic application I can think of to try to play an mp3 file, but it is not working. I don't get any errors, but when the application starts up, the sound is not played.
public class soundtest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer mp = new MediaPlayer();
mp.create(getApplicationContext(), R.raw.norm_iphone_money);
mp.start();
}
}
What am I missing? I have "norm_iphone_money.mp3" inside the res/raw folder. The file plays fine in Windows Media Player and iTunes.
I'm using the latest versions of Java SDK and Eclipse for Java. The app is targeted for Android 2.2 and runs fine in the emulator despite no sound.
Start/Pause the playback: After loading the media file, you can start playing the media file by using the start() method. Similarly, you can pause the playing media file by using the pause() method. Stop the playback: You can stop playback by using the reset() method.
String fileUrl = "http://192.168.1.131/myproject/songs/xyz"; String url = "http://myserver/songs/xyz"; //(myserver -> A remote server) mVideoView. setVideoURI(Uri. parse(fileUrl)); mVideoView. requestFocus();
The problem is that the media volume is set to 0 (not the ringer volume). You can set it by:
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
Have a look at the developer page and another question for the explanation of parameters for setStreamVolume(int, int, int).
The problem is with emulator, change the emulator or try to run the application on a real device. This should solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With