玩瞳文档中心


音频接口

<h3>概述</h3> <p>该部分接口的入口类为 <strong>VTBRSDKManager</strong>,在调用该部分接口前,需要打开sdk,否则有可能会导致部分功能无法正常work。</p> <h3>1. 停止所有音频</h3> <p>停止当前正在播放的音频</p> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void stopAllAudio()</code></pre> <h3>2. 暂停所有音频</h3> <p>暂停当前正在播放的音频</p> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void pauseAllAudio()</code></pre> <h3>3. 恢复所有音频</h3> <p>恢复当前暂停中的音频</p> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void resumeAllAudio()</code></pre> <h3>4. 重新播放书页音频</h3> <p>播放指定的bookId、pageId、pageType对应的音频</p> <p><strong>接口名称:</strong></p> <pre><code class="language-java">/** * 播放书页音频 * * @param bookId bookId * @param pageId pageId * @param pageType 书页类型 * @return 播放结果{false: 失败; true: 成功} */ public boolean playPageAudio(int bookId, int pageId, int pageType)</code></pre> <h3>5. 监听音频播放状态</h3> <p><strong>接口名称:</strong></p> <pre><code class="language-java">public void setAudioStateListener(IAudioStateListener listener)</code></pre> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>listener</td> <td>IAudioStateListener</td> <td>音频状态回调</td> </tr> </tbody> </table> <h3>6. IAudioStateListener音频状态回调</h3> <p>该回调类用于监听音频播放状态的回调,接口类如下:</p> <pre><code class="language-java">public interface IAudioStateListener { void onSysAudioComplete(int id); void onPageAudioStart(int id); void onPageAudioComplete(int id); }</code></pre> <h4>6.1 onSysAudioComplete</h4> <p>该方法为app内置语音播放结束的回调</p> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>id</td> <td>int</td> <td>对应音频文件设置的id,默认为0</td> </tr> </tbody> </table> <h4>6.2 onPageAudioStart</h4> <p>该方法为开始播放书页音频的回调</p> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>id</td> <td>int</td> <td>对应音频文件设置的id,默认为0</td> </tr> </tbody> </table> <h4>6.3 onPageAudioComplete</h4> <p>该方法为书页音频播放结束的回调</p> <p><strong>参数:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>id</td> <td>int</td> <td>对应音频文件设置的id,默认为0</td> </tr> </tbody> </table> <h3>7. 音频播放</h3> <p>sdk提供了播放系统音的接口,可通过 <code>VTAudioCtrl.getInstance</code> 去调用</p> <p>备注:该模块接口受 <strong>VTBRSDKManager</strong> 的 <strong>init</strong> 和 <strong>exit</strong> 方法所影响,init后才可正常调用,exit后即退出</p> <h4>7.1 播放单个音频</h4> <p><strong>接口:</strong></p> <pre><code class="language-java">public void postSysAudio(AudioItem audio)</code></pre> <p><strong>参数:</strong>AudioItem为sdk封装的音频类文件</p> <h4>7.2 播放多个音频</h4> <p><strong>接口:</strong></p> <pre><code class="language-java">public void postSysAudios(AudioItem[] audios)</code></pre> <p><strong>参数:</strong>AudioItem array,AudioItem为sdk封装的音频类文件</p> <h4>7.3 AudioItem类</h4> <p><strong>类成员变量如下:</strong></p> <pre><code class="language-java">public class AudioItem { public static final int TYPE_VOICE = 0; // 语音类 public static final int TYPE_BGM = 1; // 背景音 public static final int TYPE_EFFECT = 2; // 音效类 private String filePath = ""; // 文件路径 private float startTime = 0; // 开始时间 private boolean isLoop = false; // 是否需要循环 private boolean isLocal = true; // 是否为app内置的音频文件 private int type = TYPE_VOICE; // 音频类型 private int priority = 0; // 优先级 private int id = 0; // AudioItem id } </code></pre> <p><strong>AudioItem需要通过AudioItem.Builder去创建,样例如下:</strong></p> <pre><code class="language-java">public static final AudioItem BGM_SYS_START = new AudioItem.Builder() .setFilePath("bgm_sys_start.mp3") .setPriority(500) .setType(AudioItem.TYPE_BGM) .setLoop(true) .build(); </code></pre> <h3>8 播放模式设置</h3> <pre><code class="language-java">public static void setPlayMode(int playMode) </code></pre> <p><strong>注: 接口在 PlayMode 类</strong></p> <p><strong>类型:</strong></p> <table> <thead> <tr> <th>参数名</th> <th>类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td>MODE_LOCAL</td> <td>int</td> <td>本地模式 ,值为 1</td> </tr> <tr> <td>MODE_ONLINE</td> <td>int</td> <td>在线模式 ,值为 2</td> </tr> </tbody> </table>

页面列表

ITEM_HTML