原因:由于需要实现音频播放,故使用AudioTrack实现功能.

概况:音频播放可以使用MediaPlayer和AudioTrack两种方案,MediaPlayer可以播放多种格式的语音文件,例如.mp3,.wmv.等.而AudioTrack只能播放.pcm文件.通过了解可以看出MediaPlayer底层同样使用AudioTrack进行pcm填充.

流程如下:首先进行创建一个AudioTrack对象.该对象涉及参数为数据源,采样率,通道类型,样本类型,缓存大小。此时重点需要了解缓存大小。在设置缓存大小时,需要了解最后一个参数含义(用于描述是否是实时流还是读文件)。如果为实时流则需要使用getMinBufferSize获取支持的最小缓存.44.1KHZ,单声道,16bit样本类型.通过getMinBufferSize获取缓存大小为7072字节.大约80ms数据.

    /*** Class constructor.* @param streamType the type of the audio stream. See*   {@link AudioManager#STREAM_VOICE_CALL}, {@link AudioManager#STREAM_SYSTEM},*   {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_MUSIC},*   {@link AudioManager#STREAM_ALARM}, and {@link AudioManager#STREAM_NOTIFICATION}.* @param sampleRateInHz the initial source sample rate expressed in Hz.*   {@link AudioFormat#SAMPLE_RATE_UNSPECIFIED} means to use a route-dependent value*   which is usually the sample rate of the sink.*   {@link #getSampleRate()} can be used to retrieve the actual sample rate chosen.* @param channelConfig describes the configuration of the audio channels.*   See {@link AudioFormat#CHANNEL_OUT_MONO} and*   {@link AudioFormat#CHANNEL_OUT_STEREO}* @param audioFormat the format in which the audio data is represented.*   See {@link AudioFormat#ENCODING_PCM_16BIT},*   {@link AudioFormat#ENCODING_PCM_8BIT},*   and {@link AudioFormat#ENCODING_PCM_FLOAT}.* @param bufferSizeInBytes the total size (in bytes) of the internal buffer where audio data is*   read from for playback. This should be a nonzero multiple of the frame size in bytes.*   <p> If the track's creation mode is {@link #MODE_STATIC},*   this is the maximum length sample, or audio clip, that can be played by this instance.*   <p> If the track's creation mode is {@link #MODE_STREAM},*   this should be the desired buffer size*   for the <code>AudioTrack</code> to satisfy the application's*   latency requirements.*   If <code>bufferSizeInBytes</code> is less than the*   minimum buffer size for the output sink, it is increased to the minimum*   buffer size.*   The method {@link #getBufferSizeInFrames()} returns the*   actual size in frames of the buffer created, which*   determines the minimum frequency to write*   to the streaming <code>AudioTrack</code> to avoid underrun.*   See {@link #getMinBufferSize(int, int, int)} to determine the estimated minimum buffer size*   for an AudioTrack instance in streaming mode.* @param mode streaming or static buffer. See {@link #MODE_STATIC} and {@link #MODE_STREAM}* @throws java.lang.IllegalArgumentException* @deprecated use {@link Builder} or*   {@link #AudioTrack(AudioAttributes, AudioFormat, int, int, int)} to specify the*   {@link AudioAttributes} instead of the stream type which is only for volume control.*/public AudioTrack(int streamType, int sampleRateInHz, int channelConfig, int audioFormat,int bufferSizeInBytes, int mode)

AudioTrack开始进行播放如下:

 m_audioTrack.play();

数据填充如下:通过测试发现当填充数据大于缓存大小时,则会等到填充数据完全播放后才会同步返回(耗时为播放填充数据需要的时长)。故可以推测为音频播放是由硬件设备定时器回调进行数据获取.而内部维护一个缓存队列,上层通过数据填充缓存。

 m_audioTrack.write(pSrc,0,iR);

关闭设备:

 m_audioTrack.release();

总结:通过AudioTrack实现音频播放。

AudioTrack介绍相关推荐

  1. AudioTrack播放流程

    AudioTrack介绍 音频播放声音分为MediaPlayer和AudioTrack两种方案的.MediaPlayer可以播放多种格式的声音文件,例如MP3,WAV,OGG,AAC,MIDI等.然而 ...

  2. Android系统框架总结(好文)

    原址 通用概念 Android框架图 Android应用程序框架 UI基本开发 Fragment 安全策略 在Android中,安全涵盖了应用程序的部署和执行.对于部署来 说,Android应用程序必 ...

  3. 【翻译】安卓新播放器EXOplayer介绍

    [翻译]安卓新播放器EXOplayer介绍 http://developer.android.com/guide/topics/media/exoplayer.html 前言: Playing vid ...

  4. ktm390蓝牙连接安卓_蓝牙音乐AudioTrack Session ID的获取

    当今这个音视频无处不在的时代,音频跟踪会话ID(AudioTrack Session ID)是个很重要的参数,可以用来实现音频相关的一些特效.接下来的内容我们就探究如何在安卓蓝牙系统中获取该id. 熟 ...

  5. 智能会议系统(34)---Android语音通话实现方案及相关技术介绍

    Android语音通话实现方案及相关技术介绍 Android语音通话实现方案及相关技术介绍 语音通话 Step1语音采集和输出 Step2编解码方式 Step3网络传输 Step4去噪声消回音 语音通 ...

  6. 获取sessionid_蓝牙音乐AudioTrack Session ID的获取

    当今这个音视频无处不在的时代,音频跟踪会话ID(AudioTrack Session ID)是个很重要的参数,可以用来实现音频相关的一些特效.接下来的内容我们就探究如何在安卓蓝牙系统中获取该id. 熟 ...

  7. Android音视频【十二】使用opensles和audiotrack进行播放pcm

    人间观察 年龄到了,有些事就妥协了,这个世界上没有人可以随心所欲,生活会逼着你选择答案--最困难的是你什么都改变不了-- 介绍 播放pcm的两种方式 本节我们学习下如何播放pcm数据,在Android ...

  8. Android 11 Audio框架探索之AudioTracK(二)

    在上一篇介绍了关于AudioPolicyService与AudioFlinger服务的启动及初始化.这里探索一下AudioTrack与AudioFlinger做了那些事情. MediaPlayer会在 ...

  9. Android音视频学习系列(五) — 掌握音频基础知识并使用AudioTrack、OpenSL ES渲染PCM数据

    系列文章 Android音视频学习系列(一) - JNI从入门到精通 Android音视频学习系列(二) - 交叉编译动态库.静态库的入门 Android音视频学习系列(三) - Shell脚本入门 ...

最新文章

  1. [codevs 1034] 家园
  2. 精读《你不知道的javascript》中卷
  3. 树形可拖拽排序配置组件
  4. 苹果新机发布在即 供应链齐泼冷水:卖不了7000万台
  5. 电脑中毒了怎么办 电脑中病毒的解决方法
  6. 使用 Autofill 插件快速提交BUG
  7. 机器非正常关机 出现ora-01033 oracle,oracle ORA-01033问题的解决办法
  8. number数据类型
  9. 如何求有序数组绝对值最小的数
  10. file_put_contents() 利用技巧
  11. python爬取微博评论_python爬虫抓取新浪微博数据
  12. 《迅雷链精品课》第十课:共识算法理论基础
  13. 教你如何查看Ubuntu版本
  14. wargame v2.1 Web Wrtteup By Assassin
  15. 脚本语言与html语言的联系与区别,编程,标记和脚本语言三者有什么区别?
  16. Canvas 3D球形文字云动画特效
  17. 找懂的大佬做一个闲鱼监控软件,大概要求如下。
  18. 从软件分层说说LAXCUS分布式操作系统
  19. PHP实现一个简单的图书管理系统
  20. 素材资源库合集,再也不怕找不到素材了

热门文章

  1. freepbx搭建回拨测试系统
  2. 如何分析是后端问题和前端问题
  3. 搜索算法(迷宫问题)
  4. codeblock实现数组倒序输出
  5. MATLAB自定义函数 计算三元函数矢量符号微分
  6. 基于JDBC的账务管理系统
  7. python数组元素赋值_对numpy中数组元素的统一赋值实例
  8. vue3输入框生成的时候自动获取焦点
  9. 变分自编码器(一):原来是这么一回事
  10. Win 8应用开发马拉松——程序人生,共享精彩