Android 2.2 HTTP 渐进式流媒体 = HTTP 实时流媒体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3595491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is Android 2.2 HTTP progressive streaming = HTTP Live Streaming?
提问by headwire
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?
Stagefigh 媒体框架 (Android 2.2) 支持 HTTP 渐进式流媒体。
那是什么意思?即这是一个 HTTP Live Streaming 协议实现吗?
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?
以及如何在 Android 上使用 HTTP Live Streaming,我的意思是客户端是什么 - Web 浏览器、MediaPlayer 或只是“in-SDK”实现,我必须从某个类继承?
回答by droidgren
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.
一个很大的实际差异是 Stagefright 媒体框架支持 mpeg3 流,而旧引擎不支持。例如,您可以使用(shoutcast)mp3streams。
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.
这是一个简单的实现示例,它流式传输一个shoutcast 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>
Read more http://developer.android.com/guide/topics/media/index.htmlcheck Asynchronous Preparation
阅读更多 http://developer.android.com/guide/topics/media/index.html检查异步准备
回答by Leox
HTTP progressive streaming is like playing media file in the mean time downloading the file.
HTTP 渐进式流式传输就像在下载文件的同时播放媒体文件。
Is not realization. 1st, stagefright doesn't contain any .m3u8 file handler. 2nd, stagefright doesn't support .ts file format.
不是实现。第一,stagefright 不包含任何 .m3u8 文件处理程序。2、stagefright 不支持 .ts 文件格式。
currently, you can reimplement your mediaplayer for playing live streaming.
目前,您可以重新实现媒体播放器以播放实时流媒体。