本文介绍了在Android棒棒糖MediaRecorder问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试 libstreaming 在新的Andr​​oid 棒棒堂 ,和在previous发布了这个工作code,似乎推出例外。

I'm testing libstreaming on new Android Lollipop, and this code that worked on previous release, seems to launch exception.

    try {
        mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setCamera(mCamera);

        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mMediaRecorder.setVideoEncoder(mVideoEncoder);
        mMediaRecorder.setPreviewDisplay(mSurfaceView.getHolder().getSurface());
        mMediaRecorder.setVideoSize(mRequestedQuality.resX,mRequestedQuality.resY);


        mMediaRecorder.setVideoFrameRate(mRequestedQuality.framerate);

        // The bandwidth actually consumed is often above what was requested

        mMediaRecorder.setVideoEncodingBitRate((int)(mRequestedQuality.bitrate*0.8));

        // We write the ouput of the camera in a local socket instead of a file !
        // This one little trick makes streaming feasible quiet simply: data from the camera
        // can then be manipulated at the other end of the socket

        mMediaRecorder.setOutputFile(mSender.getFileDescriptor());

        mMediaRecorder.prepare();
        mMediaRecorder.start();

    } catch (Exception e) {
        throw new ConfNotSupportedException(e.getMessage());
    }

推出的例外是:

Launched exception is:

MediaRecorder:启动失败-38

MediaRecorder: start failed -38

九月11号至18日:50:21.028:W / System.err的(15783):net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException9月11号至18日:50:21.028:W / System.err的(15783):在net.majorkernelpanic.streaming.video.VideoStream.en codeWithMediaRecorder(VideoStream.java:442)9月11号至18日:50:21.028:W / System.err的(15783):在net.majorkernelpanic.streaming.MediaStream.start(MediaStream.java:250)

11-18 09:50:21.028: W/System.err(15783): net.majorkernelpanic.streaming.exceptions.ConfNotSupportedException11-18 09:50:21.028: W/System.err(15783): at net.majorkernelpanic.streaming.video.VideoStream.encodeWithMediaRecorder(VideoStream.java:442)11-18 09:50:21.028: W/System.err(15783): at net.majorkernelpanic.streaming.MediaStream.start(MediaStream.java:250)

我已经试过评论:

mMediaRecorder.setOutputFile(mSender.getFileDescriptor());

mMediaRecorder.setOutputFile(mSender.getFileDescriptor());

也不例外推出,但是当我开始流一个对话框告诉我,需要一个OUTPUTFILE。

no exception launched, but when I start streaming a dialog tell me that need an outputfile.

帮助AP preciated。

Help appreciated.

推荐答案

我提交的AOSP的bug报告。<一href="https://$c$c.google.com/p/android/issues/detail?id=80715">https://$c$c.google.com/p/android/issues/detail?id=80715

I filed a bug report on AOSP.https://code.google.com/p/android/issues/detail?id=80715

目前的SELinux策略不允许的媒体服务器来处理生成的应用程序抽象的UNIX域套接字。

"The current SELinux policies don't allow for mediaserver to handle app generated abstract unix domain sockets.

相反,我建议你创建一个管道对(http://developer.android.com/reference/android/os/ParcelFileDescriptor.html#createPipe() ),其允许由所述机器人5.0政策。我不知道他们为什么这样做,否则我们是如何应该知道。

Instead, I'd recommend you create a pipe-pair ( http://developer.android.com/reference/android/os/ParcelFileDescriptor.html#createPipe() ) which is allowed by the Android 5.0 policy."I don't know why they did this or how we were supposed to know.

我使用的是很旧的/修改(不能告诉)版本​​libstreaming哪里MediaStream可仍然受到mediarecorder延长,但看目前的版本,在MediaStream可你可能会想createSockets更改为包括以下内容:

I'm using a very old/modified (can't tell) version of libstreaming where mediastream is still extended from mediarecorder, but looking at the current version, in MediaStream you'll probably want to change createSockets to something including the following:

        ParcelFileDescriptor[] parcelFileDescriptors =ParcelFileDescriptor.createPipe();
        parcelRead = new ParcelFileDescriptor(parcelFileDescriptors[0]);
        parcelWrite  = new ParcelFileDescriptor(parcelFileDescriptors[1]);

然后在您的视频/音频流

then in your video/audio stream

setOutputFile(parcelWrite.getFileDescriptor());

和在该相同的文件变更

and in that same filechange

    // The packetizer encapsulates the bit stream in an RTP stream and send it over the network
    mPacketizer.setInputStream(mReceiver.getInputStream());
    mPacketizer.start();

            InputStream is = null;
            try{ is = new ParcelFileDescriptor.AutoCloseInputStream(parcelRead);
            }
            catch (Exception e){}
            mPacketizer.setInputStream(is);

这工作,但由于某些原因,视频很janky。如果我解决这个问题,我会编辑这个答案。编辑:jankiness走了,当我重新启动设备。正如andreasperelli指出的评论,请务必关闭closeSockets的ParcelFileDescriptors(),或者根据您的实现和版本,closeSockets()之前,你调用MediaRecorder.stop()。在

This works, but for some reason the video is very janky. I'll edit this answer if I fix that. the jankiness went away when I restarted the device. As andreasperelli pointed out in the comment, make sure to close the ParcelFileDescriptors in closeSockets(), or depending on your implementation and version, before closeSockets() and before you call MediaRecorder.stop().

这篇关于在Android棒棒糖MediaRecorder问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 06:39