安卓音效AudioEffect源码剖析2——音效库接口

1、库的导出符号表——audio_effect_library_t

audio_effect_library_t的定义在hardware/libhardware/include/hardware/audio_effect.h中。

这个结构体在Android4.3+时有发生变化,query_num_effects()和query_effect()被删除。

如果希望做库兼容性,需要检测EFFECT_LIBRARY_API_VERSION,当其为

#ifEFFECT_API_VERSION_MAJOR(EFFECT_LIBRARY_API_VERSION) > 2时query_num_effects()和query_effect()不复存在。

typedef struct audio_effect_library_s {
    // tag must be initialized to AUDIO_EFFECT_LIBRARY_TAG
    uint32_t tag;
    // Version of the effect library API : 0xMMMMmmmm MMMM: Major, mmmm: minor
    uint32_t version;
    // Name of this library
    const char *name;
    // Author/owner/implementor of the library
    const char *implementor;

    
    //
    //    Function:        query_num_effects
    //
    //    Description:    Returns the number of different effects exposed by the
    //          library. Each effect must have a unique effect uuid (see
    //          effect_descriptor_t). This function together with EffectQueryEffect()
    //          is used to enumerate all effects present in the library.
    //
    //    Input/Output:
    //          pNumEffects:    address where the number of effects should be returned.
    //
    //    Output:
    //        returned value:    0          successful operation.
    //                          -ENODEV     library failed to initialize
    //                          -EINVAL     invalid pNumEffects
    //        *pNumEffects:     updated with number of effects in library
    //
    
    int32_t (*query_num_effects)(uint32_t *pNumEffects);

    
    //
    //    Function:        query_effect
    //
    //    Description:    Returns the descriptor of the effect engine which index is
    //          given as argument.
    //          See effect_descriptor_t for details on effect descriptors.
    //          This function together with EffectQueryNumberEffects() is used to enumerate all
    //          effects present in the library. The enumeration sequence is:
    //              EffectQueryNumberEffects(&num_effects);
    //              for (i = 0; i < num_effects; i++)
    //                  EffectQueryEffect(i,...);
    //
    //    Input/Output:
    //          index:          index of the effect
    //          pDescriptor:    address where to return the effect descriptor.
    //
    //    Output:
    //        returned value:    0          successful operation.
    //                          -ENODEV     library failed to initialize
    //                          -EINVAL     invalid pDescriptor or index
    //                          -ENOSYS     effect list has changed since last execution of
    //                                      EffectQueryNumberEffects()
    //                          -ENOENT     no more effect available
    //        *pDescriptor:     updated with the effect descriptor.
    /
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是Android添加音效的方法和点击按钮播放音效的示例代码: 1. 在Android项目中添加音频文件 将音频文件放置在项目的`res/raw`目录下。如果该目录不存在,则可以在项目的`app/src/main`目录下创建一个`res/raw`目录,然后将音频文件放置在其中。 2. 创建MediaPlayer对象 在需要播放音效的Activity或Fragment中创建一个MediaPlayer对象,用于管理音频的播放。 ``` private MediaPlayer mediaPlayer; ``` 3. 初始化MediaPlayer对象 在`onCreate`或`onViewCreated`方法中初始化MediaPlayer对象,并设置音频文件的资源ID。 ``` mediaPlayer = MediaPlayer.create(getActivity(), R.raw.button_click_sound); ``` 4. 添加按钮点击事件 为需要播放音效的按钮添加点击事件,当按钮被点击时播放音效。 ``` button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mediaPlayer.start(); } }); ``` 完整代码示例: ``` public class MainActivity extends AppCompatActivity { private Button button; private MediaPlayer mediaPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = findViewById(R.id.button); mediaPlayer = MediaPlayer.create(this, R.raw.button_click_sound); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mediaPlayer.start(); } }); } } ``` 至于小视频源码,我不清楚你具体想要的是什么类型的小视频,可以提供更详细的信息或需求吗?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值