简体   繁体   English

在Nexus 7 Marshmallow上初始化AudioRecorder

[英]Initializing AudioRecorder on Nexus 7 Marshmallow

I have a program that's been running successfully on half a dozen test devices, and hundreds of apparently happy users who download my app from Google Play. 我有一个程序已经在六个测试设备上成功运行,还有数百个显然很开心的用户从Google Play下载我的应用程序。

I bought a used Nexus 7 that has been upgraded to Marshmallow, and I can't record. 我买了一台已升级到Marshmallow的二手Nexus 7,我无法录制。 The device runs other sound-recording apps just fine, but it just won't run my app. 该设备运行其他录音应用程序就好了,但它不会运行我的应用程序。

Here's some code: 这是一些代码:

private static AudioRecord recorder = null;

public static void record() throws IllegalArgumentException
{
    int channelConfig = AudioFormat.CHANNEL_IN_MONO;
    int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
    int sampleRate = 44100;
    int minSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat );
    int latencySize = 3584;
    int inputBufferSize = Math.max( minSize, latencySize );
    recorder = new AudioRecord( MediaRecorder.AudioSource.DEFAULT, sampleRate, channelConfig, audioFormat, inputBufferSize );
    int state = recorder.getState();
    if ( state != AudioRecord.STATE_INITIALIZED )
    {
        if ( recorder != null )
            recorder.release();
        recorder = null;
        throw new IllegalArgumentException( "Failed to initialize Audio recorder.  State = " + state );
    }
    recorder.startRecording();
    Thread inputThread = new Thread( new Runnable() { public void run() { inputTask(); } }, "Input" );
    inputThread.setPriority( Thread.MAX_PRIORITY );
    inputThread.start();
}

This fails with state 0, which is the same as STATE_UNINITIALIZED . 这与状态0失败,这与STATE_UNINITIALIZED相同。

My AndroidManifest.xml includes 我的AndroidManifest.xml包括

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

As I've said, this code runs successfully on hundreds of other machines, it just fails on my Nexus 7. Is there something new and different about Marshmallow? 正如我所说,这个代码在数百台其他机器上成功运行,它在我的Nexus 7上失败了。有没有关于Marshmallow的新的和不同的东西? Should I suspect some glitch in my hardware? 我应该怀疑我的硬件有些故障吗? What's going on? 这是怎么回事?

In Android 6.0 Marshmallow there has been introduced a new way to work with permissions. 在Android 6.0 Marshmallow中,已经引入了一种使用权限的新方法。

Now some permissions should be asked during runtime and user can choose, allow it or not. 现在应该在运行时询问一些权限,用户可以选择,允许或不允许。

Check this link for more information 请查看此链接以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM