Reputation: 636
I'm trying to record live stream video played by vitamio videoView. right now i'm using MediaRecorded but it's just not working.
how should i do that? i have those 3 main recording methods.
is there another method to record live stream?
holder = mVideoView.getHolder();
holder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
initRecorder();
}
});
private void initRecorder() {
if (recorder == null) recorder = new MediaRecorder();
recorder.setPreviewDisplay(holder.getSurface());
//recorder.setCamera(mCamera);
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
// mrecorder.setOutputFormat(8);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoEncodingBitRate(512 * 1000);
recorder.setVideoFrameRate(25);
recorder.setVideoSize(352, 288);
recorder.setOutputFile(Utils.getTuracoFolder() + "/video.mp4");
try {
recorder.prepare();
} catch (IllegalStateException e) {
// This is thrown if the previous calls are not called with the
// proper order
e.printStackTrace();
TLog.e(TAG, e.getMessage());
} catch (IOException e) {
e.printStackTrace();
TLog.e(TAG, e.getMessage());
}
}
private void toggleRecording() {
if (recorder == null) return;
if (recording) {
try {
recorder.stop();
recorder.reset();
initRecorder();
recording = false;
TLog.d(TAG, "Stopped Recording");
} catch (Exception ex) {
TLog.d(TAG, "Error - " + ex.getMessage());
}
} else {
try {
recorder.start();
} catch (IllegalStateException e) {
TLog.e(TAG, e.getMessage());
}
Log.v(TAG, "Recording Started");
recording = true;
}
}
Upvotes: 2
Views: 1023
Reputation: 45
i have done it but with ffmpeg. so do this to download m3u8 streaming using ffmpeg.
update you gradle.built
dependencies {
compile 'com.writingminds:FFmpegAndroid:0.3.2'
}
now in you activity class write this
FFmpeg ffmpeg;
//command that will create new file mani.mp4 file in root
String cmdd="-i http://rt-a.akamaihd.net/ch_04@325608/720p.m3u8 -c:a copy -c:v copy -bsf:a aac_adtstoasc "+ new File(Environment.getExternalStorageDirectory() + "/mani.mp4").getAbsolutePath();
String[] cmd = cmdd.split(" ");
ffmpeg = FFmpeg.getInstance(getApplicationContext());
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onFailure() {}
@Override
public void onSuccess() {}
@Override
public void onFinish() {}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
Log.e("com",e.toString());
}
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onProgress(String message) {
// will print information about every new frame it find on given link
Log.e("com",message);
}
@Override
public void onFailure(String message) {
}
@Override
public void onSuccess(String message) {
}
@Override
public void onFinish() {}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
to stop downloading run this on button click
ffmpeg.killRunningProcesses();
Remember to add internet and read/ write permission
Upvotes: 1