1

可能重复:
Android:重定向 pls 文件以便媒体播放器可以读取它

我可以在 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)
4

0 回答 0