问题描述
我有项目有关视频通过安卓电视盒的需求。我有问题,我找不到RTMP播放器开源。要是有人能帮助我或者指导我有关RTMP播放器源$ C $ C?
I have project about Video on Demand via Android TV Box. I have problem,I can not find open source of RTMP player. Had someone can help me or guide me about the rtmp player source code ?
我用RED5流和BUIL为Android 2.2(升级Froyo)。
I use red5 to stream and buil for android 2.2(froyo).
推荐答案
RTMP直播流可以在Android中的WebView嵌入Flash播放器播放。下面举是完整的源$ C $ C打RTMP。
rtmp live stream can be play in Android webview embedding flash player. Give below is full source code to play rtmp.
虽然必须要经过这个网址 http://www.adobe.com/devnet-apps/flashruntimes/certified -devices.html 在这里闪光支持的设备列出。因此,在这样的装置,它支持闪光测试code
Though you must go through this urlhttp://www.adobe.com/devnet-apps/flashruntimes/certified-devices.htmlhere the flash supported device is listed. So test the code in such a device, which supports the flash.
public class WebViewPlayer extends Activity {
WebView webView;
Utils utils;
String bodyHtml;
String rtmpUrl;
String fileName;
String htmlVideoEmbedCode ;
String htmlPost = "</body></html>";
String htmlPre = "<!DOCTYPE html>"
+ "<html lang=\"en\">"
+ "<head><meta charset=\"utf-8\">"
+ "</head>"
+ "<body style='margin:0; pading:0;"
+ " background-color: #71D5CA;'>";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.flash_player);
RegisterActivities.registerActivity(this);
utils = new Utils(this);
if(! utils.isConnectionPossible()){
utils.getMessageDialogBox("Alert", "The Device cannot connect to the internet."
+ "Please make sure internet is available.", "OK",
true)
.show();
}
rtmpUrl = YOUR_RTMP_URL);
fileName = YOUR_FILE_NAME);
htmlVideoEmbedCode = getVideoEmbedCode();
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setAppCacheEnabled(true);
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
if(progress == 100)
((ProgressBar)findViewById(R.id.progressBarWebView))
.setVisibility(View.INVISIBLE);
}
});
refreshFileName();
}
@Override
protected void onResume() {
super.onResume();
webView.refreshPlugins(true);
}
private String getVideoEmbedCode() {
return "<embed "
+ "type=\"application/x-shockwave-flash\""
+ "id=\"player1\" " + "name=\"player1\" "
+ "src=\"http://www.c-span.org/"
+ "cspanVideoHD.swf\""
+ "width=\""+utils.getDisplayWidth()+"\""
+ "height=\""+(utils.getDisplayHeight()+40)+"\"" + " flashvars=@FILESRC@"
+ "allowfullscreen=\"true\""
+ "allowscripaccess=\"always\""
+ "/>";
}
private void refreshFileName() {
if (fileName.endsWith(".flv")) {
fileName = "flv:" + fileName;
}
bodyHtml = htmlVideoEmbedCode ;
bodyHtml = bodyHtml.replaceAll("@FILESRC@",
"\"file=" + fileName
+ "&streamer=" + rtmpUrl + "\"");
webView.loadDataWithBaseURL("http://127.0.0.1",
htmlPre + bodyHtml
+ htmlPost, "text/html", "UTF-8", null);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
webView.stopLoading();
webView.destroy();
// webView = null;
}
}
这篇关于我想要一个简单的code打从RTMP流视频为我的Android应用程序项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!