Android日志无法打印

时间:2016-10-25 17:10:43

标签: android tarsosdsp

我使用TarsosDsp并且我不知道我的问题是否与图书馆有关。如果有人能帮助我解决这个问题,我会感到高兴。 这是我的代码:

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MyActivity";
private Handler handler;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    handler = new Handler();
}

protected void run(View view) {
    new AndroidFFMPEGLocator(this);
    new Thread(new Runnable() {
        @Override
        public void run() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    File externalStorage = Environment.getExternalStorageDirectory();
                    File sourceFile = new File(externalStorage.getAbsolutePath(), "/440.wav");
                    final int bufferSize = 4096;
                    final int fftSize = bufferSize / 2;
                    final int sampleRate = 44100;

                    AudioDispatcher audioDispatcher;
                    audioDispatcher = AudioDispatcherFactory.fromPipe(sourceFile.getAbsolutePath(), sampleRate, bufferSize, 0);
                    audioDispatcher.addAudioProcessor(new AudioProcessor() {

                        FFT fft = new FFT(bufferSize);
                        final float[] amplitudes = new float[fftSize];

                        @Override
                        public boolean process(AudioEvent audioEvent) {
                            float[] audioBuffer = audioEvent.getFloatBuffer();
                            fft.forwardTransform(audioBuffer);
                            fft.modulus(audioBuffer, amplitudes);
                            for (int i = 0; i < amplitudes.length; i++) {
                                Log.println(Log.DEBUG, TAG, String.format("Amplitude at %3d Hz: %8.3f", (int) fft.binToHz(i, sampleRate), amplitudes[i]));
                            }

                            return true;
                        }

                        @Override
                        public void processingFinished() {
                            Toast.makeText(getApplicationContext(), "salam", Toast.LENGTH_SHORT).show();
                        }
                    });
                    audioDispatcher.run();
                }
            });
        }
    }).start();
}

}

问题是

上的日志行
Log.println(Log.DEBUG, TAG, String.format("Amplitude at %3d Hz: %8.3f", (int) fft.binToHz(i, sampleRate), amplitudes[i]));

不会打印任何内容。有帮助吗? 这是我的日志:

    10-25 20:48:22.423 19019-19019/com.example.me W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
10-25 20:48:22.693 19019-19019/com.example.me D/Atlas: Validating map...
10-25 20:48:22.753 19019-19062/com.example.me I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.02.006.020 - CR771817 ()
                                                                             OpenGL ES Shader Compiler Version: E031.25.03.06
                                                                             Build Date: 03/04/15 Wed
                                                                             Local Branch: 
                                                                             Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.02.006.020
                                                                             Local Patches: NONE
                                                                             Reconstruct Branch: NOTHING
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: Processor   : ARMv7 Processor rev 0 (v7l)
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor   : 0
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS    : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: 
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor   : 1
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS    : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: 
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor   : 2
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS    : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: 
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor   : 3
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS    : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: 
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: Features    : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4 
10-25 20:48:30.231 19019-19019/com.example.me I/AndroidFFMPEGLocator: Detected Native CPU Architecture: ARMEABI_V7A_NEON
10-25 20:48:30.231 19019-19019/com.example.me I/AndroidFFMPEGLocator: Ffmpeg binary location: /data/data/com.example.me/cache/ffmpeg is executable? true size: 15417252 bytes
10-25 20:48:30.251 19019-19019/com.example.me I/System: exec(ffmpeg -version @ be.tarsos.dsp.io.PipeDecoder.isAvailable:-1)
10-25 20:48:30.281 19019-19019/com.example.me I/System: exec(avconv -version @ be.tarsos.dsp.io.PipeDecoder.isAvailable:-1)
10-25 20:48:30.311 19019-19019/com.example.me I/System.out: Running on Android!
10-25 20:48:30.311 19019-19019/com.example.me I/PipeDecoder: Starting piped decoding process for /storage/emulated/0/440.wav
10-25 20:48:30.322 19019-19019/com.example.me I/System: exec(/system/bin/sh -c "/data/data/com.example.me/cache/ffmpeg" -i "/storage/emulated/0/440.wav" -vn -ar 44100 -ac 1 -sample_fmt s16 -f s16le pipe:1 @ be.tarsos.dsp.io.PipeDecoder.getDecodedStream:-1)
10-25 20:48:30.382 19019-19386/com.example.me I/PipeDecoder: Finished piped decoding process

P.S。看起来过程功能没有运行。虽然ProcessingFinished运行。

更新:这是处理程序的一个问题,我不知道为什么,但当我将运行(View视图)中的代码移动到onTouchEvent时,它工作正常。

3 个答案:

答案 0 :(得分:0)

关闭Android Studio的即时运行功能,卸载应用程序,清理项目,然后运行应用程序。这对我有所帮助,可能适合你。祝你好运。

答案 1 :(得分:0)

可能是您忘了拨打protected void run(View view)方法?

答案 2 :(得分:0)

事实证明,当涉及到主线程以外的线程登录时,android studio(java)以一种奇怪的方式工作。

相关问题