Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you do not need the recording and playback functionality in your app, using off-the-shelf streaming app and player is a reasonable choice. </p> <p>If you do need them to be in your app, however, you will have to look into <a href="http://developer.android.com/reference/android/media/MediaRecorder.html" rel="nofollow noreferrer">MediaRecorder</a> API (for the server/camera app) and <a href="http://developer.android.com/reference/android/media/MediaPlayer.html" rel="nofollow noreferrer">MediaPlayer</a> (for client/player app).</p> <p>Quick sample code for the server:</p> <pre><code>// this is your network socket ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket); mCamera = getCameraInstance(); mMediaRecorder = new MediaRecorder(); mCamera.unlock(); mMediaRecorder.setCamera(mCamera); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // this is the unofficially supported MPEG2TS format, suitable for streaming (Android 3.0+) mMediaRecorder.setOutputFormat(8); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mediaRecorder.setOutputFile(pfd.getFileDescriptor()); mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); mMediaRecorder.prepare(); mMediaRecorder.start(); </code></pre> <p>On the player side it is a bit tricky, you could try this:</p> <pre><code>// this is your network socket, connected to the server ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDataSource(pfd.getFileDescriptor()); mMediaPlayer.prepare(); mMediaPlayer.start(); </code></pre> <p>Unfortunately mediaplayer tends to not like this, so you have a couple of options: either (a) save data from socket to file and (after you have a bit of data) play with mediaplayer from file, or (b) make a tiny http proxy that runs locally and can accept mediaplayer's GET request, reply with HTTP headers, and then copy data from the remote server to it. For (a) you would create the mediaplayer with a file path or file url, for (b) give it a http url pointing to your proxy.</p> <p>See also:</p> <p><a href="https://stackoverflow.com/questions/6116880/stream-live-video-from-phone-to-phone-using-socket-fd/">Stream live video from phone to phone using socket fd</a></p> <p><a href="https://stackoverflow.com/questions/5343730/mediaplayer-stutters-at-start-of-mp3-playback/">MediaPlayer stutters at start of mp3 playback</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload