Streaming live camera feed in app using android studio
<p>I'm creating an app that I want to stream my <code>foscam</code> live feed in. I'm pretty new to coding and some of this code is over my head. I found some help getting this far but now am hitting a snag. The app runs but only displays a black screen. I believe i have the manifest and XML code all correct. The problem lies in my code. I hope someone can help me out</p>

<p><div class="snippet" data-lang="js" data-hide="true">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>package com.rednak.camerastream;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Base64;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity
implements MediaPlayer.OnPreparedListener,
  SurfaceHolder.Callback {
    final static String USERNAME = "guest";
    final static String PASSWORD = "Guest";
    final static String RTSP_URL = "rtsp://http://rednak71.ddns.net:8090/live1.sdp";

    private MediaPlayer _mediaPlayer;
    private SurfaceHolder _surfaceHolder;

    @
    Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      // Set up a full-screen black window.
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      Window window = getWindow();
      window.setFlags(
        WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
      window.setBackgroundDrawableResource(android.R.color.black);

      setContentView(R.layout.activity_main);

      // Configure the view that renders live video.
      SurfaceView surfaceView =
        (SurfaceView) findViewById(R.id.surfaceView);
      _surfaceHolder = surfaceView.getHolder();
      _surfaceHolder.addCallback(this);
      _surfaceHolder.setFixedSize(320, 240);
    }

    // More to come…

    /*
    SurfaceHolder.Callback
    */

    @
    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 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 Map getRtspHeaders() {
      Map headers = new HashMap();
      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);
    }

    /*
    MediaPlayer.OnPreparedListener
    */
    @
    Override
    public void onPrepared(MediaPlayer mp) {
      _mediaPlayer.start();
    }
  }</code></pre>
</div>
</div>
</p>