Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do you get the artist and song title from MediaPlayer?
    text
    copied!<p>I'm building a simple app for an online radio station. I using this code to use the MediaPlayer to stream the station. It works great with one problem. I don't know how to show the listener what they're actually listening too. My code:</p> <pre><code>package com.xxxx.android; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.List; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.app.Activity; import android.media.MediaPlayer; import android.media.MediaPlayer.OnBufferingUpdateListener; import android.media.MediaPlayer.OnPreparedListener; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.provider.MediaStore.Audio; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; @SuppressWarnings("unused") public class MainActivity extends Activity implements OnClickListener { private final static String RADIO_STATION_URL = "http://"; private Button buttonPlay; private Button buttonStopPlay; private MediaPlayer player; private TextView showdisplay; private String strInfo; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializeUIElements(); initializeMediaPlayer(); } private void initializeUIElements() { buttonPlay = (Button) findViewById(R.id.buttonPlay); buttonPlay.setOnClickListener(this); buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay); buttonStopPlay.setEnabled(false); buttonStopPlay.setOnClickListener(this); showdisplay = (TextView) findViewById(R.id.lblDisplay); } public void onClick(View v) { if (v == buttonPlay) { startPlaying(); } else if (v == buttonStopPlay) { stopPlaying(); } } private void startPlaying() { buttonStopPlay.setEnabled(true); buttonPlay.setEnabled(false); showdisplay.setText("Buffering.."); player.prepareAsync(); player.setOnPreparedListener(new OnPreparedListener() { public void onPrepared(MediaPlayer mp) { player.start(); } }); } private void stopPlaying() { if (player.isPlaying()) { player.stop(); player.release(); initializeMediaPlayer(); } buttonPlay.setEnabled(true); buttonStopPlay.setEnabled(false); } private void initializeMediaPlayer() { player = new MediaPlayer(); try { player.setDataSource(RADIO_STATION_URL); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() { public void onBufferingUpdate(MediaPlayer mp, int percent) { Log.i("Buffering", "" + percent); } }); } @Override protected void onPause() { super.onPause(); if (player.isPlaying()) { player.stop(); } } </code></pre> <p>How...specifically..and in great detail...do I update the Textview "showdisplay" with the artist and song title coming down from the radio stream in MediaPlayer?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload