2011-12-30 9 views
12

ストリーミングshoutcastストリームに使用しているコードを参照してください。Android 2.2 MediaPlayerは1つのSHOUTcast URLで正常に動作していますが、他の1つではありません

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

でもないと、この1:

この1つは動作します

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

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:

<?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 

を誰かが私はそれを修正するのに役立つことはできますか?

EDIT:

ちょうどあなたと共有する人々、私たちのcurrent code works with Android 2.1 & minor versions, but not works with Android 2.2 or higherいます。

おかげ

+1

。 – harism

+1

もう本当に良い議論はここで見つけることができます:http://stackoverflow.com/questions/1650983/server-side-aac-audio-with-android – poitroae

+0

この時に私を助けてhttp://stackoverflow.com/questions/16264225/ andriod-shoutcast-internet-radio-filenotfoundexception – String

答えて

7

Shoutcastはmp3が以降ネイティブにサポートされています。

以下2.2のように、Android OSはストリームをキャプチャするデバイスのストリームエンドまたはストリームプロキシクラスのプロキシを使用せずにストリームをネイティブで再生することはできません。NPRと同じようにストリームをキャプチャしてオーディオプレーヤに渡します。

audio/aacpストリーミングは直接サポートされていません。このためにffmpeg、opencore、faad2ライブラリを使ってPCMにデコードし、audiotrackを使って再生することができます。 Reference

+0

Shoutcastはストリームが2.2からサポートされていthe100rabh –

+0

私はShoutcast mp3ストリーミングだけがAndroid 2.2からサポートされていると述べました。あなたのURLの1つはコンテンツタイプ "audio/aacp"です。これは再生していないと思われます。もう1つはアンドロイド2.2以降でサポートされている "audio/mpeg"です。 AACPの場合は、コンテンツをファイルに保存して再生するか、または私が言及したデコードライブラリを使用します。ただし、使用中の法的な問題も考慮してください。 –

+0

このhttp://stackoverflow.com/questions/16264225/andriod-shoutcast-internet-radio-filenotfoundexceptionで私を助けて@SanthoshShettigar – String

1

問題が

問題がaacpが適切にAndroidのメディアプレーヤーによってレンダリングされていないということであるオーディオ/ aacpでエンコーディングです。他のコーデックを試したり、独自のデコーダを作成しなければなりません。

+0

このhttp://stackoverflow.com/questions/16264225/andriod-shoutcast-internet-radio-filenotfoundexception @で私を助けてください以降、私はそれを知っているが、なぜそれがURLの1&いないと動作しますもう1つ働いていますか? – String

1

Mediaplayerthese formatsは、アンドロイドデベロッパードキュメントに記載されています。

いくつかのストリームは、これを満たすことができるが、いくつかは、Android 2.2からのストリーミングではない

0

Freeware Advanced Audio (AAC) Decoder for Androidがあります。これをヘルプとガイダンスに使用したり、Multiplayerクラスを使用してaacオーディオを再生することができます。あなたの理解を助けるサンプルアプリケーションとライブラリがあります。私はShoutcastオンラインストリームを再生するためにこのライブラリを使用しました。私は、これは

0

最後に、私はシンプルなShoutcastはストリーミングアプリを得た支援を期待

ライブラリで提供マルチクラスを使用してAACとMP3の両方を果たしました。 お試しください thisストリーミングURLを変更するだけです。 StreamService.javaそれはあまりにも他の人のためのいくつかの頭痛の原因となる音声符号 ``オーディオ/ aacp``ですグーグルでいくつかの簡単に基づいて

関連する問題