开发者

"cannot find symbol" error w/ AudioTrack

Considering I've never written a line of Java before today, I'm sure I've missed something obvious. In any case, I'm working开发者_如何学Python on an Android app that uses the AudioTrack class to play generated audio.

I'm importing everything I think I'm supposed to:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.CheckBox;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;

Within my Activity class I have this function:

public AudioTrack toneToAudioTrack(byte samples[], int numSamples) {
    final AudioTrack audioTrack = new AudioTrack(
        AudioManager.STREAM_MUSIC,
        sampleRate,
        AudioFormat.CHANNEL_CONFIGURATION_MONO,
        AudioFormat.ENCODING_PCM_8BIT,
        numSamples,
        AudioTrack.MODE_STATIC
    );

    audioTrack.write(samples, 0, numSamples);

    return audioTrack;
}

When I try to compile with ant, I get this:

compile:

[javac] /opt/android-sdk-update-manager/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not

set, defaulting to

build.sysclasspath=last; set to false

for repeatable builds

[javac] Compiling 2 source files to /home/electrode/ditdah/bin/classes

[javac] /home/electrode/ditdah/src/org/n8fq/DitDah/DitDahActivity.java:38:

cannot find symbol

[javac] symbol : constructor AudioTrack(int,double,int,int,int,int)

[javac] location: class android.media.AudioTrack

[javac] audioTrack = new AudioTrack(

[javac] ^

[javac] 1 error

BUILD FAILED

/opt/android-sdk-update-manager/tools/ant/main_rules.xml:384: Compile failed; see the compiler error

output for details.

So, what am I missing?


The 2nd argument to the constructor should be an int

final AudioTrack audioTrack = new AudioTrack(
    AudioManager.STREAM_MUSIC,
    (int) sampleRate,
    AudioFormat.CHANNEL_CONFIGURATION_MONO,
    AudioFormat.ENCODING_PCM_8BIT,
    numSamples,
    AudioTrack.MODE_STATIC
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜