问题描述
因此,我试图将Android用作网络摄像头.我的代码非常适合API< =22.我正在使用ParcelFileDescriptor
的createPipe()
方法创建用于读取和写入的管道.
So I am trying to use my Android as a webcam. My code is working perfectly for API <= 22. I am using ParcelFileDescriptor
's createPipe()
method to create pipe for reading and writing.
简而言之,我写给管道的内容如下:
In short, my writing to the pipe looks like following:
ParcelFileDescriptor[] parcelFileDescriptors = ParcelFileDescriptor.createPipe();
ParcelFileDescriptor mParcelWrite =new ParcelFileDescriptor(mParcelFileDescriptors[1]);
MediaRecorder mMediaRecorder = new MediaRecorder();
mMediaRecorder.setOutputFile(mParcelWrite.getFileDescriptor());
..
..// Other settings.
mMediaRecorder.start();
运行此命令时,出现以下异常
When I run this, I get the following exception,
E/MediaRecorder: start failed: -2147483648
W/System.err: java.lang.RuntimeException: start failed. W/System.err: at android.media.MediaRecorder.start(Native Method)
W/System.err: at com.ksy.recordlib.service.recoder.RecoderVideoSource.prepare(RecoderVideoSource.java:105)
W/System.err: at com.ksy.recordlib.service.recoder.RecoderVideoSource.run(RecoderVideoSource.java:173)
W/System.err: at java.lang.Thread.run(Thread.java:818)
我知道,在API 23中,他们制作了更改,导致MediaRecorder
无法使用不可搜索的文件描述符.
I got to know, that in API 23, they made a change which prevented MediaRecorder
to work with File descriptors that are not seekable.
ParcelFileDescriptor
似乎不是可搜索的.
我的问题是,如何使它易于寻找?有其他选择吗?谢谢.
My question is, How can I make it seekable? Is there any alternative to it?Thanks.
推荐答案
我已经对此进行了一周的调查.您可以设置的输出格式中有一个隐藏格式,即
I have been investigating this for a week. There is a hidden format in the output formats you can set which is
mMediaRecorder.setOutputFormat(8);
从文档中
**@hide H.264/AAC data encapsulated in MPEG2/TS
public static final int OUTPUT_FORMAT_MPEG2TS = 8; **
public static final int OUTPUT_FORMAT_MPEG2TS = 8;**
但是,它仍然不能在棉花糖或牛轧糖上使用.我使它适用于kit kat.让我知道是否有帮助.
However it does not still work on Marshmallow or Nougat. I made it work for kit kat. Let me know if this helps.
这篇关于“可搜索"与MediaRecorder Android 6.0(API 23)一起使用的文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!