当前位置:操作系统 > 安卓/Android >>

Android Audio代码分析24 - AudioEffect::setEnabled函数

 

之前已经看过,通过接口getEnabled可以取得effect的enable状态。

今天来看看如何来改变enable状态。

 

 

*****************************************源码*************************************************

    //Test case 2.0: test setEnabled() and getEnabled() in valid state

    @LargeTest

    public void test2_0SetEnabledGetEnabled() throws Exception {

        boolean result = false;

        String msg = "test2_0SetEnabledGetEnabled()";

 

 

        try {

            AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER,

                    AudioEffect.EFFECT_TYPE_NULL,

                    0,

                    0);

            assertNotNull(msg + ": could not create AudioEffect", effect);

            try {

                effect.setEnabled(true);

                assertTrue(msg + ": invalid state from getEnabled", effect.getEnabled());

                effect.setEnabled(false);

                assertFalse(msg + ": invalid state to getEnabled", effect.getEnabled());

                result = true;

            } catch (IllegalStateException e) {

                msg = msg.concat(": setEnabled() in wrong state");

            } finally {

                effect.release();

            }

        } catch (IllegalArgumentException e) {

            msg = msg.concat(": Equalizer not found");

            loge(msg, ": Equalizer not found");

        } catch (UnsupportedOperationException e) {

            msg = msg.concat(": Effect library not loaded");

            loge(msg, ": Effect library not loaded");

        }

        assertTrue(msg, result);

    }

**********************************************************************************************

源码路径:

frameworks\base\media\tests\mediaframeworktest\src\com\android\mediaframeworktest\functional\MediaAudioEffectTest.java

 

 

#######################说明################################

    //Test case 2.0: test setEnabled() and getEnabled() in valid state

    @LargeTest

    public void test2_0SetEnabledGetEnabled() throws Exception {

        boolean result = false;

        String msg = "test2_0SetEnabledGetEnabled()";

 

 

        try {

            AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_EQUALIZER,

                    AudioEffect.EFFECT_TYPE_NULL,

                    0,

                    0);

            assertNotNull(msg + ": could not create AudioEffect", effect);

            try {

                effect.setEnabled(true);

++++++++++++++++++++++++++++++setEnabled++++++++++++++++++++++++++++++++++

    /**

     * Enable or disable the effect.

     * Creating an audio effect does not automatically apply this effect on the audio source. It

     * creates the resources necessary to process this effect but the audio signal is still bypassed

     * through the effect engine. Calling this method will make that the effect is actually applied

     * or not to the audio content being played in the corresponding audio session.

     *

     * @param enabled the requested enable state

     * @return {@link #SUCCESS} in case of success, {@link #ERROR_INVALID_OPERATION}

     *         or {@link #ERROR_DEAD_OBJECT} in case of failure.

     * @throws IllegalStateException

     */

// 创建一个audio effect,它并不会自发发挥作用。

// 该函数可以启动/停止该audio effect发挥作用。

    public int setEnabled(boolean enabled) throws IllegalStateException {

        checkState("setEnabled()");

        return native_setEnabled(enabled);

++++++++++++++++++++++++++++++android_media_AudioEffect_native_setEnabled++++++++++++++++++++++++++++++++++

static jint

android_media_AudioEffect_native_setEnabled(JNIEnv *env, jobject thiz, jboolean enabled)

{

    // retrieve the AudioEffect object

    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField(

        thiz, fields.fidNativeAudioEffect);

 

 

    if (lpAudioEffect == NULL) {

        jniThrowException(env, "java/lang/IllegalStateException",

            "Unable to retrieve AudioEffect pointer for enable()");

        return AUDIOEFFECT_ERROR_NO_INIT;

    }

 

 

 

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,