我想要一个简单的代码来播放视频从rtmp流为我的android应用程序项目

我想要一个简单的代码来播放视频从rtmp流为我的android应用程序项目,android,video-streaming,red5,rtmp,Android,Video Streaming,Red5,Rtmp,我有一个关于通过Android电视盒点播视频的项目。我有问题,我找不到开源的RTMP播放器。有没有人可以帮助我或指导我关于rtmp播放器的源代码 我使用red5为Android2.2(froyo)流式传输和构建。使用RTSP public class PlayVideoRemote extends Activity { private VideoView vView; private String vSource; /** Called when the activity is first

我有一个关于通过Android电视盒点播视频的项目。我有问题,我找不到开源的RTMP播放器。有没有人可以帮助我或指导我关于rtmp播放器的源代码

我使用red5为Android2.2(froyo)流式传输和构建。

使用RTSP

 public class PlayVideoRemote extends Activity
 {
private VideoView vView;
private String vSource;

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

    //get the VideoView from the layout file
    vView = (VideoView)findViewById(R.id.vview);

    //use this to get touch events
    vView.requestFocus();

    //loads video from remote server
    //set the video path
    vSource ="rtsp://v6.cache1.c.youtube.com/CjYLENy73wIaLQnF4qJzpSt4nhMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYMDFmvL1wMysTQw=/0/0/0/video.3gp";
    //set the video URI, passing the vSource as a URI
    vView.setVideoURI(Uri.parse(vSource));

    //enable this if you want to enable video controllers, such as pause and forward
    vView.setMediaController(new MediaController(this));

    //plays the movie
    vView.start();
}
}

有关RTMP,请参阅此

RTMP直播流可在Android webview嵌入flash player中播放。下面给出的是播放rtmp的完整源代码

虽然你必须通过这个网址 此处列出了支持闪存的设备。因此,在这样一个支持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;
    }

}
公共类WebViewPlayer扩展活动{
网络视图;
Utils-Utils;
字符串bodyHtml;
字符串rtmpUrl;
字符串文件名;
字符串HTMLVIDEO代码;
字符串htmlPost=“”;
字符串htmlPre=“”
+ ""
+ "" 
+ ""
+ "";
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.flash_播放器);
注册表活动。注册表活动(此);
utils=新utils(本);
如果(!utils.isConnectionPossible()){
utils.getMessageDialogBox(“警报”,“设备无法连接到internet。”
+“请确保互联网可用。”,“确定”,
(对)
.show();
}
rtmpUrl=您的\u RTMP\u URL);
文件名=您的文件名);
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);
setWebView.WebChromeClient(新WebChromeClient(){
public void onProgressChanged(WebView视图,int-progress){
如果(进度==100)
((ProgressBar)findViewById(R.id.progressBarWebView))
.setVisibility(视图.不可见);
}
});
刷新文件名();
}
@凌驾
受保护的void onResume(){
super.onResume();
刷新插件(true);
}
私有字符串getVideoEmbedCode(){
返回“”;
}
私有无效刷新文件名(){
if(fileName.endsWith(“.flv”)){
fileName=“flv:”+文件名;
}
bodyHtml=htmlVideoEmbedCode;
bodyHtml=bodyHtml.replaceAll(@FILESRC@),
“\”file=“+文件名
+“&streamer=“+rtmpUrl+”\”);
webView.loadDataWithBaseURL(“http://127.0.0.1",
htmlPre+bodyHtml
+htmlPost,“文本/html”,“UTF-8”,空);
}
@凌驾
受保护的空onDestroy(){
//TODO自动生成的方法存根
super.ondestory();
webView.stopLoading();
destroy();
//webView=null;
}
}

我的android应用程序如何连接到android player以及android player如何连接到流媒体服务器?非常感谢。@droidhot您可以使用启用了javascript和flashplayer支持的webview来使用RTMPT玩游戏。非常感谢您。今晚我要试试@droidhot@R_Hear你能和我们分享你的源代码吗?非常感谢,但是我在-Utils-Utils上发现了错误-registerActivity.registerActivity(this);-+“width=\”“+utils.getDisplayWidth()+”\”“+“height=\”“+(utils.getDisplayHeight()+40)+“\”“+”flashvars=@FILESRC@”关于utils的错误我如何处理它。utils是一个用户定义类的对象,其中定义了getDisplayHeight()/width()…所以你可以忽略这些方法..你可以放任何高度或宽度来代替..非常感谢。^@Sudiptaforandroid我如何用这个播放实时rtmp流?我尝试了每种组合,但它只是播放了C-span中的一些内容。。。有人能帮我吗?:)这里有什么用途??RegisterActivities abd Utils向我提供错误。。我需要一些外部LIB吗?谢谢。但它不能播放视频。我使用red5来流式传输,我只能在rtmp上进行streamrtsp@SudiptaforAndroid...Is该代码现在正常工作,因为我收到“无法加载插件”