android收音机shoutcast链接

时间:2012-12-25 03:07:55

标签: android radio shoutcast

  

可能重复:
  Android: Redirecting pls file so that mediaplayer can read it

我可以在setDataSource中使用此链接:http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361

player.setDataSource("http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361");

这不起作用,我怎么能让这个链接起作用,我需要更改它,添加端口还是......?

这是电台'Arman FM':http://www.shoutcast.com/Internet-Radio/Arman+FM

代码:

import android.app.Activity;
import android.net.Uri;
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 ArmanFMRadio 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.armanfm);
    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);

}

private void initializeMediaPlayer() {
    player = new MediaPlayer();
    try {
        String strurl="http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361";
        player = MediaPlayer.create(ArmanFMRadio.this, Uri.parse(strurl));
        //player.setDataSource("http://yp.shoutcast.com/sbin/tunein-station.pls?id=13361");
    } 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.setVisibility(View.VISIBLE);
            playSeekBar.setSecondaryProgress(percent);
            Log.i("Buffering", "" + percent);

        }
    });
}

public void onClick(View v) {
    switch(v.getId()){
    case R.id.buttonPlay:
        startPlaying();
        break;
    case R.id.buttonStopPlay:
        stopPlaying();
        break;
    } 

}

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);
}

@Override
protected void onPause() {
    super.onPause();
    if (player.isPlaying()) {
        player.stop();
    }
}
}

   12-25 03:50:09.310: W/ActivityThread(712): Application com.afghan.radios is waiting for the debugger on port 8100...
   12-25 03:50:09.340: I/System.out(712): Sending WAIT chunk
   12-25 03:50:09.350: I/dalvikvm(712): Debugger is active
   12-25 03:50:09.401: I/System.out(712): Debugger has connected
   12-25 03:50:09.401: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:09.600: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:09.810: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:10.010: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:10.210: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:10.410: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:10.611: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:10.811: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:11.020: I/System.out(712): waiting for debugger to settle...
   12-25 03:50:11.220: I/System.out(712): debugger has settled (1318)
   12-25 03:50:39.881: D/MediaPlayer(712): Couldn't open file on client side, trying server side
   12-25 03:50:40.320: E/MediaPlayer(712): error (1, -2147483648)
   12-25 03:50:40.431: D/MediaPlayer(712): create failed:
   12-25 03:50:40.431: D/MediaPlayer(712): java.io.IOException: Prepare failed.: status=0x1
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.media.MediaPlayer.prepare(Native Method)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.media.MediaPlayer.create(MediaPlayer.java:611)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.media.MediaPlayer.create(MediaPlayer.java:588)
   12-25 03:50:40.431: D/MediaPlayer(712):  at        com.afghan.radios.ArmanFMRadio.initializeMediaPlayer(ArmanFMRadio.java:54)
   12-25 03:50:40.431: D/MediaPlayer(712):  at com.afghan.radios.ArmanFMRadio.onCreate(ArmanFMRadio.java:31)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.os.Handler.dispatchMessage(Handler.java:99)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.os.Looper.loop(Looper.java:123)
   12-25 03:50:40.431: D/MediaPlayer(712):  at android.app.ActivityThread.main(ActivityThread.java:4627)
   12-25 03:50:40.431: D/MediaPlayer(712):  at java.lang.reflect.Method.invokeNative(Native Method)
   12-25 03:50:40.431: D/MediaPlayer(712):  at java.lang.reflect.Method.invoke(Method.java:521)
   12-25 03:50:40.431: D/MediaPlayer(712):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   12-25 03:50:40.431: D/MediaPlayer(712):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   12-25 03:50:40.431: D/MediaPlayer(712):  at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案