Android 2.2的MediaPlayer正在工作的罚款有一个Shoutcast一样的网址,但不与另一个不与、有一个、网址、工作

2023-09-12 00:10:55 作者:  灬ˊ辷桷落﹑彽調

请参见$ C $词现在用的流Shoutcast的流,它的工作原理有一个网址,但不与另一个。

Please see the code i am using for streaming shoutcast stream, it works with one URL but NOT with the other one.

这一件作品:

Uri myUri = Uri.parse("http://fr3.ah.fm:9000/");

但不是这一个:

But not with this one:

Uri myUri =  Uri.parse("http://someOtherURL");

SimpleMusicStream.java

SimpleMusicStream.java

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SimpleMusicStream extends Activity implements
  MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener,
  MediaPlayer.OnErrorListener, MediaPlayer.OnBufferingUpdateListener {

 private String TAG = getClass().getSimpleName();
 private MediaPlayer mp = null;

 private Button play;
 private Button pause;
 private Button stop;

 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);

  play = (Button) findViewById(R.id.play);
  pause = (Button) findViewById(R.id.pause);
  stop = (Button) findViewById(R.id.stop);

  play.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    play();
   }
  });

  pause.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    pause();
   }
  });

  stop.setOnClickListener(new View.OnClickListener() {
   public void onClick(View view) {
    stop();
   }
  });
 }

 private void play() {
  Uri myUri = Uri.parse("http://fr3.ah.fm:9000/");
  try {
   if (mp == null) {
    this.mp = new MediaPlayer();
   } else {
    mp.stop();
    mp.reset();
   }
   mp.setDataSource(this, myUri); // Go to Initialized state
   mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
   mp.setOnPreparedListener(this);
   mp.setOnBufferingUpdateListener(this);

   mp.setOnErrorListener(this);
   mp.prepareAsync();

   Log.d(TAG, "LoadClip Done");
  } catch (Throwable t) {
   Log.d(TAG, t.toString());
  }
 }

 @Override
 public void onPrepared(MediaPlayer mp) {
  Log.d(TAG, "Stream is prepared");
  mp.start();
 }

 private void pause() {
  mp.pause();
 }

 private void stop() {
  mp.stop();

 }

 @Override
 public void onDestroy() {
  super.onDestroy();
  stop();

 }

 public void onCompletion(MediaPlayer mp) {
  stop();
 }

 public boolean onError(MediaPlayer mp, int what, int extra) {
  StringBuilder sb = new StringBuilder();
  sb.append("Media Player Error: ");
  switch (what) {
  case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
   sb.append("Not Valid for Progressive Playback");
   break;
  case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
   sb.append("Server Died");
   break;
  case MediaPlayer.MEDIA_ERROR_UNKNOWN:
   sb.append("Unknown");
   break;
  default:
   sb.append(" Non standard (");
   sb.append(what);
   sb.append(")");
  }
  sb.append(" (" + what + ") ");
  sb.append(extra);
  Log.e(TAG, sb.toString());
  return true;
 }

 public void onBufferingUpdate(MediaPlayer mp, int percent) {
  Log.d(TAG, "PlayerService onBufferingUpdate : " + percent + "%");
 }

    }

main.xml中:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <Button
  android:text="Play"
  android:id="@+id/play"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"></Button>
 <Button
  android:text="Pause"
  android:id="@+id/pause"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"></Button>
 <Button
  android:text="Stop"
  android:id="@+id/stop"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"></Button>
</LinearLayout>

日志猫显示错误:

NuHTTPDataSource(33): Server did not give us the content length!

Media Player Error: Unknown (1) -2147483648
Media Player Error: Unknown (1) -1002

有人可以帮助我解决它?

Can someone help me to fix it?

编辑:

只是为了与大家分享的人,我们的current code工作与Android 2.1及放大器;次要版本,而不是作品与Android 2.2或更高版本。

Just to share with you people, that our current code works with Android 2.1 & minor versions, but not works with Android 2.2 or higher.

感谢

推荐答案

Shoutcast的MP3从Android 2.2的流起的原生支持。

Shoutcast mp3 streaming from Android 2.2 onwards is supported natively .

低于2.2的Andr​​oid操作系统无法播放Shoutcast的流本身,而不使用在上游端代理或流代理类设备上捕捉流,并将其传递给audioplayer一样的 NPR 一样。

Below 2.2 the Android OS cannot play shoutcast streams natively without using a proxy on the stream end or a stream proxy class on the device to capture the stream and pass it to the audioplayer just like NPR does.

音频/ AACP流不直接支持。为此,您可以使用的ffmpeg,的OpenCore或FAAD2库脱code成PCM和播放使用audiotrack的参考

audio/aacp streaming is not supported directly . For this you can use ffmpeg, opencore or faad2 library to decode it into PCM and play using audiotrack .Reference