仿微信的语音点击播放时的语音图标动画效果
来源:互联网 发布:mac上如何卸载软件 编辑:程序博客网 时间:2024/06/05 03:22
仿微信的语音点击播放时的语音图标动画效果
效果:
可能需要的图片:
需要定义的实例变量:
- //语音动画控制器
- Timer mTimer=null;
- //语音动画控制任务
- TimerTask mTimerTask=null;
- //记录语音动画图片
- int index=1;
- AudioAnimationHandler audioAnimationHandler=null;
需要定义的函数:
代码:
- /**
- * 播放语音图标动画
- */
- private void playAudioAnimation(final ImageView imageView) {
- //定时器检查播放状态
- stopTimer();
- mTimer=new Timer();
- //将要关闭的语音图片归位
- if(audioAnimationHandler!=null)
- {
- Message msg=new Message();
- msg.what=3;
- audioAnimationHandler.sendMessage(msg);
- }
- audioAnimationHandler=new AudioAnimationHandler(imageView);
- mTimerTask = new TimerTask() {
- public boolean hasPlayed=false;
- @Override
- public void run() {
- if(mMediaPlayer.isPlaying()) {
- hasPlayed=true;
- index=(index+1)%3;
- Message msg=new Message();
- msg.what=index;
- audioAnimationHandler.sendMessage(msg);
- }else
- {
- //当播放完时
- Message msg=new Message();
- msg.what=3;
- audioAnimationHandler.sendMessage(msg);
- //播放完毕时需要关闭Timer等
- if(hasPlayed)
- {
- stopTimer();
- }
- }
- }
- };
- //调用频率为500毫秒一次
- mTimer.schedule(mTimerTask, 0, 500);
- }
- class AudioAnimationHandler extends Handler
- {
- ImageView imageView;
- //判断是左对话框还是右对话框
- boolean isleft;
- public AudioAnimationHandler(ImageView imageView)
- {
- this.imageView=imageView;
- //判断是左对话框还是右对话框 我这里是在前面设置ScaleType来表示的
- isleft=imageView.getScaleType()==ScaleType.FIT_START?true:false;
- }
- @Override
- public void handleMessage(Message msg) {
- super.handleMessage(msg);
- //根据msg.what来替换图片,达到动画效果
- switch (msg.what) {
- case 0 :
- imageView.setImageResource(isleft?R.drawable.chatfrom_voice_playing_f1:R.drawable.chatto_voice_playing_f1);
- break;
- case 1 :
- imageView.setImageResource(isleft?R.drawable.chatfrom_voice_playing_f2:R.drawable.chatto_voice_playing_f2);
- break;
- case 2 :
- imageView.setImageResource(isleft?R.drawable.chatfrom_voice_playing_f3:R.drawable.chatto_voice_playing_f3);
- break;
- default :
- imageView.setImageResource(isleft?R.drawable.chatfrom_voice_playing_f3:R.drawable.chatto_voice_playing_f3);
- break;
- }
- }
- }
- /**
- * 停止
- */
- private void stopTimer(){
- if (mTimer != null) {
- mTimer.cancel();
- mTimer = null;
- }
- if (mTimerTask != null) {
- mTimerTask.cancel();
- mTimerTask = null;
- }
- }
0 0
- 仿微信的语音点击播放时的语音图标动画效果
- 仿微信的语音点击播放时的语音图标动画效果
- 仿微信的语音点击播放时的语音图标动画效果
- android 语音聊天播放动画的问题
- Android逐帧动画的简单使用-语音播放效果的实现
- 关于语音动画加上JS点击控制的方式
- 仿微信语音消息的录制和播放
- 实现语音播放的API
- 语音的播放与压缩
- 语音不能播放的问题
- 分答项目_知识点:伴随播放语音时的波浪图效果
- MediaPlayer--点击按钮,播放语音
- 移动端语音播放以及语音条拖动的实现
- 语音信号的短时语音能量
- js仿微信语音播放
- IM里的语音录制与播放
- angularjs解决播放语音出错的问题
- jPlayer播放后台返回的语音流
- python的time模块
- 接口测试相关文档管理规范
- 用opencv保存视频为什么打不开?
- 13、MongoDB的分片,以及分布式的实现(分片,拆分的是集合,不是单条数据)
- springmvc 常用的绑定参数用法
- 仿微信的语音点击播放时的语音图标动画效果
- 查找内存泄漏的一个思路
- html元素
- tableView高度自适应
- Java高级之Lock&Condition实现线程同步通信
- 对象信息生成Json串
- jdk,tomcat在myeclipse以及eclipse中的安装和配置
- Android工具类
- [Apple官方文档翻译]: NSURLSession Programming Guide