android+微信语音,android 仿微信按住语音说话(语音聊天)源码下载

【实例简介】

【实例截图】

9216d8ed0a4af12a6a58f036451353bf.jpg

【核心代码】

package com.example.weixin_record;

import java.util.ArrayList;

import java.util.List;

import com.nickming.view.AudioRecordButton;

import com.nickming.view.AudioRecordButton.AudioFinishRecorderListener;

import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;

import android.widget.ListView;

public class MainActivity extends Activity {

AudioRecordButton button;

private ListView mlistview;

private ArrayAdapter mAdapter;

private View viewanim;

private List mDatas = new ArrayList();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mlistview = (ListView) findViewById(R.id.listview);

button = (AudioRecordButton) findViewById(R.id.recordButton);

button.setAudioFinishRecorderListener(new AudioFinishRecorderListener() {

@Override

public void onFinished(float seconds, String filePath) {

// TODO Auto-generated method stub

Recorder recorder = new Recorder(seconds, filePath);

mDatas.add(recorder);

mAdapter.notifyDataSetChanged();

mlistview.setSelection(mDatas.size() - 1);

}

});

mAdapter = new RecorderAdapter(this, mDatas);

mlistview.setAdapter(mAdapter);

mlistview.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView> parent, View view,

int position, long id) {

// TODO Auto-generated method stub

// 播放动画

if (viewanim!=null) {//让第二个播放的时候第一个停止播放

viewanim.setBackgroundResource(R.id.id_recorder_anim);

viewanim=null;

}

viewanim = view.findViewById(R.id.id_recorder_anim);

viewanim.setBackgroundResource(R.drawable.play);

AnimationDrawable drawable = (AnimationDrawable) viewanim

.getBackground();

drawable.start();

// 播放音频

MediaManager.playSound(mDatas.get(position).filePathString,

new MediaPlayer.OnCompletionListener() {

@Override

public void onCompletion(MediaPlayer mp) {

viewanim.setBackgroundResource(R.id.id_recorder_anim);

}

});

}

});

}

@Override

protected void onPause() {

// TODO Auto-generated method stub

super.onPause();

MediaManager.pause();

}

@Override

protected void onResume() {

// TODO Auto-generated method stub

super.onResume();

MediaManager.resume();

}

@Override

protected void onDestroy() {

// TODO Auto-generated method stub

super.onDestroy();

MediaManager.release();

}

class Recorder {

float time;

String filePathString;

public Recorder(float time, String filePathString) {

super();

this.time = time;

this.filePathString = filePathString;

}

public float getTime() {

return time;

}

public void setTime(float time) {

this.time = time;

}

public String getFilePathString() {

return filePathString;

}

public void setFilePathString(String filePathString) {

this.filePathString = filePathString;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值