当同时进行摄像头视频预览和视频播放时,播放的视频只有声音,画面为全绿色。而单独进行摄像头视频预览或视频播放时,都是完全没有问题的。DDMS的LogCat中显示错误为:overlays already in use。在网上查找了很多资料,得到的答案是一般的手机硬件只支持一个overlay覆盖进行视频的显示。不知道这个答案是不是正解,也不知道如何解决这个问题。
求高手赐教!不胜感激!
13 个解决方案
#1
此段代码为视频采集线程的主要代码:
public void run() {
//创建视频采集实例
mMediaRecorder = new MediaRecorder();
mCamera = Camera.open(Camera.getNumberOfCameras()-1);
//设置视频采集的参数
Camera.Parameters p = mCamera.getParameters();
mCamera.setParameters(p);
mCamera.unlock();
String pathForAppFiles = yjs_VideoCaptureAct.mAbsolutePath;
pathForAppFiles += RECORDED_FILE;
Log.d("Video filename:",pathForAppFiles );
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setPreviewDisplay(yjs_VideoCaptureAct.shVideoCapture.getSurface());
mMediaRecorder.setOutputFile(pathForAppFiles);
//开始采集
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
mbStopRecording = false;
} catch (Exception e) {
Log.e("Video", "Failed to prepare and start video recording", e);
mMediaRecorder.release();
mMediaRecorder = null;
mbStopRecording = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopRecording){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止采集
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
mCamera.lock();
}
public void run() {
//创建视频采集实例
mMediaRecorder = new MediaRecorder();
mCamera = Camera.open(Camera.getNumberOfCameras()-1);
//设置视频采集的参数
Camera.Parameters p = mCamera.getParameters();
mCamera.setParameters(p);
mCamera.unlock();
String pathForAppFiles = yjs_VideoCaptureAct.mAbsolutePath;
pathForAppFiles += RECORDED_FILE;
Log.d("Video filename:",pathForAppFiles );
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setPreviewDisplay(yjs_VideoCaptureAct.shVideoCapture.getSurface());
mMediaRecorder.setOutputFile(pathForAppFiles);
//开始采集
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
mbStopRecording = false;
} catch (Exception e) {
Log.e("Video", "Failed to prepare and start video recording", e);
mMediaRecorder.release();
mMediaRecorder = null;
mbStopRecording = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopRecording){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止采集
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
mCamera.lock();
}
#2
此段代码为视频播放的代码:
public void run() {
//开始视频播放
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(PLAYING_FILE);
mMediaPlayer.setDisplay(yjs_VideoCaptureAct.shVideoPlaying);
mMediaPlayer.prepare();
mMediaPlayer.start();
mbStopPlaying = false;
}
catch(Exception e){
Log.e("Video", "Failed to prepare and start video playing", e);
mMediaPlayer.release();
mMediaPlayer = null;
mbStopPlaying = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopPlaying){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止播放
mMediaPlayer.stop();
mMediaPlayer.reset();
mMediaPlayer.release();
mMediaPlayer = null;
}
public void run() {
//开始视频播放
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(PLAYING_FILE);
mMediaPlayer.setDisplay(yjs_VideoCaptureAct.shVideoPlaying);
mMediaPlayer.prepare();
mMediaPlayer.start();
mbStopPlaying = false;
}
catch(Exception e){
Log.e("Video", "Failed to prepare and start video playing", e);
mMediaPlayer.release();
mMediaPlayer = null;
mbStopPlaying = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopPlaying){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止播放
mMediaPlayer.stop();
mMediaPlayer.reset();
mMediaPlayer.release();
mMediaPlayer = null;
}
#3
我这星期花了一个星期刚做了一个类似你这样的视频对话软件,能在局域网内使用WIFI进行视频通话,但没有实现实时通话,只实现了在本地录制视频存成MP4格式,然后在对方开启接受的情况下发送自己的视频文件给他,对方可以接受到,同时它还可以进行播放,所以每个手机即使客户端又是服务器,你要是要的话我可以给你发一份参考一下,我的邮箱jianzhao880502@126.com,你给我回复个邮件就行
#4
overlays already in use
Andorid机制决定的
Andorid机制决定的
#5
同时工作应该没有热和问题,清参考相关代码
#6
太感谢了 我已经给你发邮件了 期待回复!
#7
请问能说的具体一些吗 要参考哪一层的什么代码?
#8
你的意思是说不可能同时播放两个视频?
#9
我也遇到这个问题了,总是不能同时采集视频和播放视频,单独分开测试都是正常的,请高手赐教,我的邮箱biela_520@163.com,请好心人能回复个邮件
#10
解决方法其实很简单,不用overlay显示就行啦,直接在surface上显示内容,具体可以查阅一下android的媒体数据传输线路,新版的android和旧版的也有差异的
#11
楼主的问题解决了没有,如果解决了可以分享一下吗,谢谢!
#12
楼主,该问题是否解决,如果解决,能分享一下代码?谢谢
#13
这个问题有没有人解决啊,说白了就是在一个Activity有两个surfaceview,一个用来做录像预览,一个做本地视频文件播放,经测试不能同时工作,考虑将两个surfaceview分散在两个fragment中,之后集成在一个Activity,也没能解决,期待高人给出解决方案~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#1
此段代码为视频采集线程的主要代码:
public void run() {
//创建视频采集实例
mMediaRecorder = new MediaRecorder();
mCamera = Camera.open(Camera.getNumberOfCameras()-1);
//设置视频采集的参数
Camera.Parameters p = mCamera.getParameters();
mCamera.setParameters(p);
mCamera.unlock();
String pathForAppFiles = yjs_VideoCaptureAct.mAbsolutePath;
pathForAppFiles += RECORDED_FILE;
Log.d("Video filename:",pathForAppFiles );
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setPreviewDisplay(yjs_VideoCaptureAct.shVideoCapture.getSurface());
mMediaRecorder.setOutputFile(pathForAppFiles);
//开始采集
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
mbStopRecording = false;
} catch (Exception e) {
Log.e("Video", "Failed to prepare and start video recording", e);
mMediaRecorder.release();
mMediaRecorder = null;
mbStopRecording = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopRecording){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止采集
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
mCamera.lock();
}
public void run() {
//创建视频采集实例
mMediaRecorder = new MediaRecorder();
mCamera = Camera.open(Camera.getNumberOfCameras()-1);
//设置视频采集的参数
Camera.Parameters p = mCamera.getParameters();
mCamera.setParameters(p);
mCamera.unlock();
String pathForAppFiles = yjs_VideoCaptureAct.mAbsolutePath;
pathForAppFiles += RECORDED_FILE;
Log.d("Video filename:",pathForAppFiles );
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setPreviewDisplay(yjs_VideoCaptureAct.shVideoCapture.getSurface());
mMediaRecorder.setOutputFile(pathForAppFiles);
//开始采集
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
mbStopRecording = false;
} catch (Exception e) {
Log.e("Video", "Failed to prepare and start video recording", e);
mMediaRecorder.release();
mMediaRecorder = null;
mbStopRecording = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopRecording){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止采集
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
mCamera.lock();
}
#2
此段代码为视频播放的代码:
public void run() {
//开始视频播放
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(PLAYING_FILE);
mMediaPlayer.setDisplay(yjs_VideoCaptureAct.shVideoPlaying);
mMediaPlayer.prepare();
mMediaPlayer.start();
mbStopPlaying = false;
}
catch(Exception e){
Log.e("Video", "Failed to prepare and start video playing", e);
mMediaPlayer.release();
mMediaPlayer = null;
mbStopPlaying = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopPlaying){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止播放
mMediaPlayer.stop();
mMediaPlayer.reset();
mMediaPlayer.release();
mMediaPlayer = null;
}
public void run() {
//开始视频播放
mMediaPlayer = new MediaPlayer();
try{
mMediaPlayer.setDataSource(PLAYING_FILE);
mMediaPlayer.setDisplay(yjs_VideoCaptureAct.shVideoPlaying);
mMediaPlayer.prepare();
mMediaPlayer.start();
mbStopPlaying = false;
}
catch(Exception e){
Log.e("Video", "Failed to prepare and start video playing", e);
mMediaPlayer.release();
mMediaPlayer = null;
mbStopPlaying = true;
}
//当主线程不设置停止播放时一直停在循环里
while(!mbStopPlaying){
try{
sleep(100);
}
catch(Exception e){
e.printStackTrace();
}
}
//停止播放
mMediaPlayer.stop();
mMediaPlayer.reset();
mMediaPlayer.release();
mMediaPlayer = null;
}
#3
我这星期花了一个星期刚做了一个类似你这样的视频对话软件,能在局域网内使用WIFI进行视频通话,但没有实现实时通话,只实现了在本地录制视频存成MP4格式,然后在对方开启接受的情况下发送自己的视频文件给他,对方可以接受到,同时它还可以进行播放,所以每个手机即使客户端又是服务器,你要是要的话我可以给你发一份参考一下,我的邮箱jianzhao880502@126.com,你给我回复个邮件就行
#4
overlays already in use
Andorid机制决定的
Andorid机制决定的
#5
同时工作应该没有热和问题,清参考相关代码
#6
太感谢了 我已经给你发邮件了 期待回复!
#7
请问能说的具体一些吗 要参考哪一层的什么代码?
#8
你的意思是说不可能同时播放两个视频?
#9
我也遇到这个问题了,总是不能同时采集视频和播放视频,单独分开测试都是正常的,请高手赐教,我的邮箱biela_520@163.com,请好心人能回复个邮件
#10
解决方法其实很简单,不用overlay显示就行啦,直接在surface上显示内容,具体可以查阅一下android的媒体数据传输线路,新版的android和旧版的也有差异的
#11
楼主的问题解决了没有,如果解决了可以分享一下吗,谢谢!
#12
楼主,该问题是否解决,如果解决,能分享一下代码?谢谢
#13
这个问题有没有人解决啊,说白了就是在一个Activity有两个surfaceview,一个用来做录像预览,一个做本地视频文件播放,经测试不能同时工作,考虑将两个surfaceview分散在两个fragment中,之后集成在一个Activity,也没能解决,期待高人给出解决方案~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!