MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.song); mediaPlayer.start();
MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource("https://example.com/song.mp3"); mediaPlayer.prepare(); mediaPlayer.start();In this code example, the MediaPlayer object is created and the data source is set to a URL. The prepare() method is called to prepare the MediaPlayer for playback before calling the start() method. Both of these examples use the android.media package library.