I'm trying to implement the solution from this SO answer to record video to socket (and then read it from the socket in the player side, When the ultimate goal is to broadcast video in real time)
but when trying to call the start() of the madiarecorder there is exception: start failed:-1010
the API says about this constant:
public static final int MEDIA_ERROR_UNSUPPORTED
Added in API level 17 Bitstream is conforming to the related coding standard or file spec, but the media framework does not support the feature.
but I'm guessing that if people check this answer to be effective it is supported in some way- so please
point at me, what's my mistake??
here is the code i'm using:
public class MainActivity extends Activity {
private Camera mCamera;
private MediaRecorder mMediaRecorder;
private Socket socket;
private Preview mPreView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.activity_main);
try {
socket = new Socket("10.0.0.4",8080);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// this is your network socket
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
mPreView=new Preview(this);
mCamera = getCameraInstance();
mMediaRecorder = new MediaRecorder();
mCamera.lock();
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);
mMediaRecorder.setOutputFile(pfd.getFileDescriptor());
// mMediaRecorder.setPreviewDisplay(null);
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mMediaRecorder.start();
}
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
} catch (Exception e) {
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
class Preview extends ViewGroup implements SurfaceHolder.Callback
{
SurfaceView mSurface;
SurfaceHolder mHolder;
public Preview(Context context) {
super(context);
// TODO Auto-generated constructor stub
mSurface=new SurfaceView(context);
addView(mSurface);
mHolder=mSurface.getHolder();
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3,
int arg4) {
// TODO Auto-generated method stub
}
}
}
why media recorder doesn't support it? and how can I solve it?
thank you for giving your time.