Android 2.2 HTTP 渐进式流媒体 = HTTP 直播流媒体吗?

发布于 2024-09-17 07:01:42 字数 199 浏览 6 评论 0原文

Stagefright 媒体框架 (Android 2.2) 支持 HTTP 渐进式流式传输。
那是什么意思?即,这是 HTTP Live Streaming 协议实现吗?

如何在 Android 上使用 HTTP Live Streaming,我的意思是客户端是什么 - Web 浏览器、MediaPlayer 或只是“SDK 内”实现,我必须从某个类继承?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅紫色的梦幻 2024-09-24 07:01:42

一个很大的实际差异是 Stagefright 媒体框架支持 mpeg3 流,而旧引擎不支持。例如,您可以使用 (shoutcast) mp3streams。

下面是一个简单的实现示例,它流式传输喊播 URL:http://fr3.ah.fm:9000。请注意,这仅适用于 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>

了解更多
http://developer.android.com/guide/topics/media/index.html 检查异步准备

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 and up.

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>

Read more
http://developer.android.com/guide/topics/media/index.html check Asynchronous Preparation

旧伤还要旧人安 2024-09-24 07:01:42

HTTP 渐进式流媒体就像在下载文件的同时播放媒体文件。

不是觉悟。
第一,stagefright 不包含任何 .m3u8 文件处理程序。
第二,stagefright不支持.ts文件格式。

目前,您可以重新实现媒体播放器来播放实时流媒体。

HTTP progressive streaming is like playing media file in the mean time downloading the file.

Is not realization.
1st, stagefright doesn't contain any .m3u8 file handler.
2nd, stagefright doesn't support .ts file format.

currently, you can reimplement your mediaplayer for playing live streaming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文