I need to play audio file from remote server in my app. I could play when I tested with localhost server (using WAMP). When the same file supplied from the server it is not
If you are writing Java programs to play media files, then the first port of call is the MediaPlayer class. Typical code to play a file using the streaming mechanism of MediaPlayer is
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Uri uri = Uri.parse("http://192.168.1.9/music/test.ogg");
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(this, uri);
player.prepare();
player.start();
} catch(Exception e) {
System.out.println(e.toString());
}
}
Wake Lock Permission - If your player application needs to keep the screen from dimming or the processor from sleeping, or uses the MediaPlayer.setScreenOnWhilePlaying() or MediaPlayer.setWakeMode() methods, you must request this permission.