Kamihan Kamihan - 1 year ago 235
Android Question

android rtsp live stream - "Can't play this video"

public class MainActivity extends Activity
VideoView vv;
protected void onCreate(Bundle savedInstanceState)
vv = (VideoView)findViewById(R.id.videoView);

Uri uri;

I am using the above code, trying to play my IP live camera stream. The used URI works when used in VLC player. I have Internet permissions set inside my manifest too. But when I run the app on my emulator, or live device, I get the "Can't play this video" error.

The error that pops up in logcat is:

08-31 09:21:15.602 2487-2487/package D/MediaPlayer: Couldn't open file on client side, trying server side
08-31 09:21:15.612 2487-2503/package W/MediaPlayer: info/warning (701, 0)
08-31 09:21:15.666 2487-2502/package E/MediaPlayer: error (1, -2147483648)
08-31 09:21:15.725 2487-2487/package E/MediaPlayer: Error (1,-2147483648)
08-31 09:21:15.725 2487-2487/package D/VideoView: Error: 1,-2147483648

I have tried setting it up with media player aswell:

public class MainActivity extends Activity implements MediaPlayer.OnPreparedListener, SurfaceHolder.Callback
final static String USERNAME = "user";
final static String PASSWORD = "pass";
final static String RTSP_URL = "rtsp://192.168.x.x:554/cam/realmonitor?channel=1&subtype=00";

private MediaPlayer _mediaPlayer;
private SurfaceHolder _surfaceHolder;

protected void onCreate(Bundle savedInstanceState)
Window window = getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
_surfaceHolder = surfaceView.getHolder();
_surfaceHolder.setFixedSize(320, 240);
public void surfaceChanged(SurfaceHolder sh, int f, int w, int h) {}
public void surfaceCreated(SurfaceHolder sh) {
_mediaPlayer = new MediaPlayer();
Context context = getApplicationContext();
Map<String, String> headers = getRtspHeaders();
Uri source = Uri.parse(RTSP_URL);
try {
_mediaPlayer.setDataSource(context, source, headers);
catch (Exception e) {}
public void surfaceDestroyed(SurfaceHolder sh) {
private Map<String, String> getRtspHeaders() {
Map<String, String> headers = new HashMap<String, String>();
String basicAuthValue = getBasicAuthValue(USERNAME, PASSWORD);
headers.put("Authorization", basicAuthValue);
return headers;
private String getBasicAuthValue(String usr, String pwd) {
String credentials = usr + ":" + pwd;
int flags = Base64.URL_SAFE | Base64.NO_WRAP;
byte[] bytes = credentials.getBytes();
return "Basic " + Base64.encodeToString(bytes, flags);
public void onPrepared(MediaPlayer mp) {

the above code has been taken from here
but none of them work.
I've also tried the Vitamio library with no results. Nothing I do seems to be working.

Am I missing any small details somewhere? I'm assuming the URI is fine since that works in VLC player just fine. At some point the emulator was also giving a "java.io.FileNotFoundException: No content provider", but no longer.

At one point, I was thinking that maybe the authentication is a problem, so I streamed the IP camera using VLC, without user/pass, and tried to connect, but that didn't work either, so I'm assuming it is successfully authenticating.

I have also tried passing the url in as "rtsp://user:pass@192.168.x.x:554/", that also works in VLC player. But not in my app.

I have tried everything I was able to find, with no success. If anyone is able to help out, would be much appreciated!

Edit 1: The VideoView has been able to successfully play pre-recorded clips such as "rtsp://mpv.cdn3.bigCDN.com:554/bigCDN/definst/mp4:bigbuckbunnyiphone_400.mp4"
same with vitamio and mediaplayer.

Answer Source

You are trying to play the video inVideoView. Unfortunately VideoView does not support videos which try to play using RTSP protocol.

You can use a library called Vitamino to play videos using RTSP. You can check out their demo here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download