Unable to play rtsp using videoview in android

这一生的挚爱 提交于 2019-12-01 22:47:18

问题


I have set up a RTSP server using VLC. then I write an app,this is my code:

package com.ashley.work;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.app.Activity;  
import android.net.Uri;  
import android.os.Bundle;  
import android.view.View;  
import android.widget.Button;  
import android.widget.EditText;  
import android.widget.VideoView;  


public class TestPlayRTSP extends Activity {

Button playButton ;  
VideoView videoView ;  

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_play_rtsp);

    videoView = (VideoView)this.findViewById(R.id.myvideoview);  

    playButton = (Button)this.findViewById(R.id.button1);  
    playButton.setOnClickListener(new Button.OnClickListener(){  
    public void onClick(View v) {  
    PlayRtspStream("rtsp://140.xxx.xxx.xxx:8554/");  
    }  
    });  


}

private void PlayRtspStream(String rtspUrl){  
    videoView.setVideoURI(Uri.parse(rtspUrl));  
    videoView.requestFocus();  
    videoView.start();  
}  

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_test_play_rtsp, menu);
    return true;
}

}

and I already set the permission. but this still can not play. nothing happend after I click the button. But if I replace the rtsp with other this two:

  1. rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp

  2. rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp

the app will play correctly. can any one tell me why? and is there any solution to play the VLC stream???

thank you


回答1:


Android really only supports mpeg 4 encoded baseline profile with the MOOV atom set correctly. Newer devices support other methods (HLS & higher profiled mpeg4 types) but not all device will work that way. Your rtsp stream must be encoding using the base line profile.

If you open your RTSP stream in VLC and open your network stream and then MEdia Information you can see what codecs your stream is using for audio and video

Here is more definitive info on android and supported media : http://developer.android.com/guide/appendix/media-formats.html#recommendations



来源:https://stackoverflow.com/questions/13291632/unable-to-play-rtsp-using-videoview-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!