satyres
satyres

Reputation: 377

Shoutcast Radio on Android

I'm making an app for streaming radio content from internet ! and i spent so much time trying to find a simple source code showing how to implement a streaming content ! i found some useful links in StackOverflow but no one worked for me !! Please i need your help ! , here is the piece of code that i made but still doesn't work ! and i don't know why ! Ps : the url of the radio station is working fine

package com.example.radio;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity implements OnPreparedListener  {



    MediaPlayer mp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
             mp = new MediaPlayer();
             String url="http://108.168.175.174:7120";
             mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
             mp.setDataSource(url);
             mp.prepareAsync();
             mp.setOnPreparedListener(this);
        } catch (Exception e) {
            Log.i("ExceptionOnCreate:",e.getMessage());
        }


    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();

    }



}

here is the log cat :

05-06 10:20:07.291: E/MediaPlayer(1470): error (1, -2147483648)
05-06 10:20:07.291: E/MediaPlayer(1470): Error (1,-2147483648)

Upvotes: 0

Views: 1465

Answers (1)

Brad
Brad

Reputation: 163593

Your problem is likely due to SHOUTcast sending you to the admin interface. If your user agent string contains Mozilla, then you get the admin page instead of the stream. You can override this behavior by requesting a semicolon in your URL:

http://108.168.175.174:7120/;

That will force the server to see your user agent string as MPEG OVERRIDE, and it will send you the real stream.

If that doesn't fix it, you are likely bumping up an issue where SHOUTcast servers are not HTTP compliant. They send their status line as ICY 200 OK instead of HTTP/1.0 200 OK, which breaks many clients.

Upvotes: 1

Related Questions