Breaking News
Home / Android / Android Snippets / Android MediaPlayer Source Code

Android MediaPlayer Source Code

  1. public class AudioStreamer extends Activity {
  2.  @Override
  3.  public void onCreate(Bundle savedInstanceState) {
  4.   super.onCreate(savedInstanceState);
  5.   String url = “http://www.yoursite:port/stream”;
  6.   MediaPlayer mp = new MediaPlayer();
  7.   try {
  8.    mp.setDataSource(url);
  9.    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  10.    mp.prepare();
  11.    mp.start();
  12.   } catch (Exception e) {
  13.    Log.i(“Exception”, “Error playing stream” + e.getMessage());
  14.   }
  15.  }
  16. }
[pb_builder]

Check Also

How to check if an Android device can connect to Internet?

The following code snippet shows how to check if an Android device can connect to …

Advertisment ad adsense adlogger