0

I had developed one Android Application which contains Mediaplayer for playing rtsp url.For that, I user D-Link router and Dlink DCS-933L camera .Configure wireless settings to the router and camera.Now router and camera has same wifi network.Ip Camera has static IP address.

Here just i include my code for mediaplayer RTSP URL:

public class MainActivity extends Activity implements
        MediaPlayer.OnPreparedListener, SurfaceHolder.Callback {
    final static String USERNAME = "";
    final static String PASSWORD = "";
    String RTSP_URL = "";
    private MediaPlayer _mediaPlayer;
    private SurfaceHolder _surfaceHolder;
    Context context;

    private final static String TAG = "VideoActivity";

    private SurfaceView mSurfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        context = this;
        applyProxyParameter("proxyserver", "port", "user", "password");
        String Ip = getIpAddr();
        System.out.println(Ip);
        RTSP_URL="rtsp://"192.168.0.20:554";
          mSurfaceView =     (SurfaceView) findViewById(R.id.surface);
                _surfaceHolder = mSurfaceView.getHolder();
                _surfaceHolder.addCallback(this);
                _surfaceHolder.setFixedSize(320, 240);
    }

    @Override
    public void surfaceChanged(SurfaceHolder sh, int f, int w, int h) {
    }

    @Override
    public void surfaceCreated(SurfaceHolder sh) {
        _mediaPlayer = new MediaPlayer();
        _mediaPlayer.setDisplay(_surfaceHolder);

        Context context = getApplicationContext();
        Map<String, String> headers = getRtspHeaders();
        Uri source = Uri.parse(RTSP_URL);

        try {
            // Specify the IP camera's URL and auth headers.
            _mediaPlayer.setDataSource(context, source, headers);

            // Begin the process of setting up a video stream.
            _mediaPlayer.setOnPreparedListener(this);
            _mediaPlayer.prepareAsync();
        } catch (Exception e) {
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder sh) {
        _mediaPlayer.release();
    }

    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);
    }

    private Map<String, String> getRtspHeaders() {
        Map<String, String> headers = new HashMap<String, String>();
        String basicAuthValue = getBasicAuthValue(USERNAME, PASSWORD);
        headers.put("Authorization", basicAuthValue);
        return headers;
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        _mediaPlayer.start();
    }

    private void applyProxyParameter(String proxy, String port,
            final String username, final String password) {
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password
                        .toCharArray());
            }
        });
        Properties systemProperties = System.getProperties();
        systemProperties.setProperty("http.proxyHost", proxy);
        systemProperties.setProperty("http.proxyPort", port);

    }

    public String getIpAddr() {
        WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ip = wifiInfo.getIpAddress();

        String ipString = String.format("%d.%d.%d.%d", (ip & 0xff),
                (ip >> 8 & 0xff), (ip >> 16 & 0xff), (ip >> 24 & 0xff));

        return ipString;

    }
}

When I tried to play RTSP url which contains Ip address of the camera and port number.But it is not playing.I throws following error

path is null

Couldn't play client side try server side

media server died

Audio Flinger died

Mediaplayer died

Error(100,1)

Any help would be appreciated !

prakash
  • 109
  • 12

2 Answers2

2

You opened in your router the ports that the camera works so you can access it externally ? so the camera (I have the 930L model) has something like:

http://user:pass@yourip:80/video/mjpg.cgi

see this answer for the mjpeg client Android and MJPEG

haven't test it, but it should work

Community
  • 1
  • 1
OWADVL
  • 10,704
  • 7
  • 55
  • 67
0

Maybe you should use the actual url instead of the fake one you stored in RTSP_URL?

dcow
  • 7,765
  • 3
  • 45
  • 65
  • @prakash not according to the code you've provided: `RTSP_URL="rtsp://IPaddress:port";` – dcow Aug 11 '14 at 10:45