java - Audio start recording has stopped - not working -
even tried possible solutions find, couldnt solve problem. want make guitar tuner. when execute,getting message; "my application has stopped". think problem here "audio.startrecording();" when remove lane dont stopped message. tried api 15,25 versions app , virtual device phone. can u me guys problem?
here code:
package com.xxx.myapplication; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.app.activity; import android.media.audioformat; import android.media.audiorecord; import android.media.mediarecorder; public class mainactivity extends appcompatactivity { private static final int samplerate = 44100; private audiorecord audio; private int buffersize; private double lastlevel = 0; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } protected void onresume() { super.onresume(); buffersize = audiorecord .getminbuffersize(samplerate, audioformat.channel_in_mono, audioformat.encoding_pcm_16bit); audio = new audiorecord(mediarecorder.audiosource.mic, samplerate, audioformat.channel_in_mono, audioformat.encoding_pcm_16bit, buffersize); audio.startrecording(); short[] buffer = new short[buffersize]; int bufferreadresult = audio.read(buffer, 0, buffersize); } }
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxx.myapplication" > <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round" android:supportsrtl="true" android:theme="@style/apptheme" > <activity android:name=".mainactivity" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.record_audio"/> </manifest>
Comments
Post a Comment