Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream and Play .m4a stream (Itunes preview Url) in android

I want to stream and play itunes preview urls like http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a. I tried to use AAC Decoder Android Library. By which I can stream and play AAC stream urls like http://http.yourmuze.com:8000/play/paradise/l.aac. But it dnt stream m4a urls(Logcat says java.io.FileNotFoundException: http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a).

How I can stream the .m4a links?

My Code:

public class AACPlayerActivity extends Activity implements OnClickListener,PlayerCallback{

private Button btnPlay;
private ProgressBar progress;
private Handler uiHandler;

private MultiPlayer multiPlayer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btnPlay = (Button)findViewById(R.id.playButton);
    progress = (ProgressBar)findViewById(R.id.progress);
    progress.setVisibility(View.INVISIBLE);

    btnPlay.setOnClickListener(this);

    uiHandler = new Handler();
}

public void playerException(Throwable arg0) {
    // TODO Auto-generated method stub

}

public void playerMetadata(String arg0, String arg1) {
    // TODO Auto-generated method stub

}

public void playerPCMFeedBuffer(boolean arg0, final int audioBufferSizeMs, final int audioBufferCapacityMs) {
    // TODO Auto-generated method stub
    uiHandler.post(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
             progress.setProgress( audioBufferSizeMs * progress.getMax() / audioBufferCapacityMs );
        }
    });
}

public void playerStarted() {

    uiHandler.post(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            progress.setProgress( 0 );
            progress.setVisibility( View.VISIBLE );
        }
    });

}

public void playerStopped(int arg0) {
    // TODO Auto-generated method stub
    uiHandler.post(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            progress.setVisibility( View.INVISIBLE );
        }
    });

}

public void onClick(View v) {
    // TODO Auto-generated method stub
    if(btnPlay.getText().equals("Play")){
        start();
        btnPlay.setText("stop");
    }else{
        stop();
    }
}


 private void start() {
        stop();
        // we cannot do it in playerStarted() - it is too late:
        multiPlayer = new MultiPlayer(this,MultiPlayer.DEFAULT_AUDIO_BUFFER_CAPACITY_MS, MultiPlayer.DEFAULT_DECODE_BUFFER_CAPACITY_MS);
        multiPlayer.playAsync("http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a");
    }


    private void stop() {
        if (multiPlayer != null) {
            multiPlayer.stop();
            multiPlayer = null;
        }
    }

Updates

  1. I try to use ServeStream it says the url could not be opened.
  2. I try to use Vitamio SDK it also fails to play the itunes preview Urls.

Is possible to play itunes preview urls in android?

like image 396
Ajmal M A Avatar asked Jul 17 '12 11:07

Ajmal M A


2 Answers

Take a look at ServeStream:

HTTP media server browser and stream player for Android.

Features:

  • Supports Android 2.2+, 3.0+ (No support for < 2.2)
  • Plays Android supported media files
  • Additional support for m3u, m3u8, pls and asx playlists
  • Supports multitasking/playing audio in the background
  • Repeat and shuffle modes
  • Alarm clock support
  • Home screen widget
  • Utilizes HTML parsing to allow navigation of HTTP media servers that serve HTML pages
like image 139
Eng.Fouad Avatar answered Nov 15 '22 20:11

Eng.Fouad


M4A and AAC are supported by Android. I would recommend to read this page: http://developer.android.com/guide/appendix/media-formats.html

Just couple of thing which you should be aware of a) Older devices may have no particular coded or format support (especially, if you go below OS 2.2) b) Some cheap devices may have quite strange things integrated in audio/video stack. I saw it on couple of cheap Chinese devices.

So, you can try to use MediaPlayer API to play it: http://developer.android.com/reference/android/media/MediaPlayer.html

You can take a look at example here: http://blog.endpoint.com/2011/03/api-gaps-android-mediaplayer-example.html

like image 34
Victor Ronin Avatar answered Nov 15 '22 19:11

Victor Ronin