views:

572

answers:

3

The Stagefrigh media framework (Android 2.2) supports HTTP progressive streaming.
What's that means? I.e. is this an HTTP Live Streaming protocol realization?
And how to use HTTP Live Streaming on Android, I mean what's the client - web browser, MediaPlayer or just "in-SDK" realization and I have to inherit from some class?
Thanx.

+1  A: 

One big practical diffrence is that Stagefright media Framework supports mpeg3 streaming, which the old engine didn't. So you can use (shoutcast) mp3streams for example.

Here is a simple example of implementation, which streams a shoutcast URL: http://fr3.ah.fm:9000. Note that this only works on Android 2.2.

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>
droidgren
Many Thanx for code example! But my question is about protocol. In my understanding, a Progressive Download means you are able to watch the video while the rest of the video is loading into the player and is caching into the users temporary internet files. I.e. Streaming means you can click anywhere in the video and jump to where you clicked, while progressive means you have to wait for the bar to be ahead of the marker to play it. But what is Progressive Streaming?
headwire
In other words, using Android HTTP Progressive Streaming, will I be able to click and jump to unloaded segment?
headwire
And practical question: can I use Apple file/stream segmenter to make these "segmented" files for Live Streaming (via Apache web server) on Android platform?
headwire
A: 

Not Works for Me!!. Dont know if i missed something.. it shows "bufferCount (4) is too small and increased to 4. " while in debug mode

Himanshu.MarJAVA