---
title: 音频引擎的开启和静音
description: "设置音频引擎开启和静音。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcps/boostcph/instrucstreamengine/kunpengcpsinstruction_16_0026.html
sourcePath: /source/zh/kunpengcps/boostcph/instrucstreamengine/kunpengcpsinstruction_16_0026.html
indexId: c339b595e403ab0eafe83f5446f5a2bff2cf97d95077e287cde193cf1ff9024e85
---
# 音频引擎的开启和静音

#### 场景介绍

设置音频引擎开启和静音。


#### 前提条件

- 指令流引擎启动成功。
- 音频引擎注册成功。


#### 开发流程

1. 在Activity启动时调用startAudio，开启声音。
2. 在Activity退出时调用stopAudio，静音。


#### 编码实例

```
public class Activity implements NativeListener {
    public void onStart() {
        int ret = AudioTrackPlayer.startAudio();
        if (ret == AudioTrackPlayer.VMI_SUCCESS) {
            // 音频开启成功
        }
        if (ret == AudioTrackPlayer.VMI_AUDIO_ENGINE_CLIENT_START_FAIL) {
            // 音频开启失败
        }
    }
    public void onStop() {
        int ret = AudioTrackPlayer.stopAudio();
        if (ret == AudioTrackPlayer.VMI_SUCCESS) {
            // 音频静音成功
        }
        if (ret == AudioTrackPlayer.VMI_AUDIO_ENGINE_CLIENT_STOP_FAIL) {
            // 音频静音失败
        }
    }
}
```
