Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So I found this sample and it works for me, here it is if you have the same issue:</p> <p>in myMain.java</p> <pre><code>import android.app.Activity; import android.os.Bundle; import java.io.IOException; import android.media.MediaPlayer; import android.media.MediaPlayer.OnBufferingUpdateListener; import android.media.MediaPlayer.OnPreparedListener; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; public class myMain extends Activity implements OnClickListener { private ProgressBar playSeekBar; private Button buttonPlay; private Button buttonStopPlay; private MediaPlayer player; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initializeUIElements(); initializeMediaPlayer(); } private void initializeUIElements() { playSeekBar = (ProgressBar) findViewById(R.id.progressBar1); playSeekBar.setMax(100); playSeekBar.setVisibility(View.INVISIBLE); buttonPlay = (Button) findViewById(R.id.buttonPlay); buttonPlay.setOnClickListener(this); buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay); buttonStopPlay.setEnabled(false); buttonStopPlay.setOnClickListener(this); } public void onClick(View v) { if (v == buttonPlay) { startPlaying(); } else if (v == buttonStopPlay) { stopPlaying(); } } private void startPlaying() { buttonStopPlay.setEnabled(true); buttonPlay.setEnabled(false); playSeekBar.setVisibility(View.VISIBLE); 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); playSeekBar.setVisibility(View.INVISIBLE); } private void initializeMediaPlayer() { player = new MediaPlayer(); try { player.setDataSource("http://usa8-vn.mixstream.net:8138"); } 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) { playSeekBar.setSecondaryProgress(percent); Log.i("Buffering", "" + percent); } }); } @Override protected void onPause() { super.onPause(); if (player.isPlaying()) { player.stop(); } } } </code></pre> <p>in the XML (main.xml) code:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Source: (Radio La Chevere)" android:layout_marginTop="10dip" android:gravity="center" /&gt; &lt;ProgressBar android:id="@+id/progressBar1" android:indeterminateOnly="false" android:progressDrawable="@android:drawable/progress_horizontal" android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal" android:minHeight="20dip" android:maxHeight="20dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:layout_marginTop="10dip"&gt;&lt;/ProgressBar&gt; &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="20dip" android:gravity="center"&gt; &lt;Button android:text="Play" android:id="@+id/buttonPlay" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;Button android:text="Stop" android:id="@+id/buttonStopPlay" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the android manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="package.your.RadioStream" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".myMain" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></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