|
|
@ -6,6 +6,7 @@ import android.graphics.drawable.AnimationDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.media.AudioManager;
|
|
|
|
import android.media.AudioManager;
|
|
|
|
import android.media.MediaPlayer;
|
|
|
|
import android.media.MediaPlayer;
|
|
|
|
|
|
|
|
import android.media.SoundPool;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
@ -39,7 +40,10 @@ import com.baidu.mapapi.utils.DistanceUtil;
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
import com.orhanobut.logger.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileDescriptor;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
@ -48,6 +52,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import butterknife.Bind;
|
|
|
|
import butterknife.Bind;
|
|
|
|
import cn.bmob.imdemo.R;
|
|
|
|
import cn.bmob.imdemo.R;
|
|
|
|
|
|
|
|
import cn.bmob.imdemo.adapter.BmobPlayManager;
|
|
|
|
import cn.bmob.imdemo.adapter.ChatAdapter;
|
|
|
|
import cn.bmob.imdemo.adapter.ChatAdapter;
|
|
|
|
import cn.bmob.imdemo.base.ParentWithNaviActivity;
|
|
|
|
import cn.bmob.imdemo.base.ParentWithNaviActivity;
|
|
|
|
import cn.bmob.imdemo.util.Util;
|
|
|
|
import cn.bmob.imdemo.util.Util;
|
|
|
@ -66,6 +71,7 @@ import cn.bmob.newim.listener.MessageListHandler;
|
|
|
|
import cn.bmob.newim.listener.MessageSendListener;
|
|
|
|
import cn.bmob.newim.listener.MessageSendListener;
|
|
|
|
import cn.bmob.newim.listener.ObseverListener;
|
|
|
|
import cn.bmob.newim.listener.ObseverListener;
|
|
|
|
import cn.bmob.newim.listener.OnRecordChangeListener;
|
|
|
|
import cn.bmob.newim.listener.OnRecordChangeListener;
|
|
|
|
|
|
|
|
import cn.bmob.v3.BmobUser;
|
|
|
|
import cn.bmob.v3.exception.BmobException;
|
|
|
|
import cn.bmob.v3.exception.BmobException;
|
|
|
|
|
|
|
|
|
|
|
|
public class LocActivity extends ParentWithNaviActivity implements ObseverListener,MessageListHandler {
|
|
|
|
public class LocActivity extends ParentWithNaviActivity implements ObseverListener,MessageListHandler {
|
|
|
@ -76,6 +82,7 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
BmobIMAudioMessage audio_msg;
|
|
|
|
BmobIMAudioMessage audio_msg;
|
|
|
|
MediaPlayer mediaPlayer = null;
|
|
|
|
MediaPlayer mediaPlayer = null;
|
|
|
|
Context mContext;
|
|
|
|
Context mContext;
|
|
|
|
|
|
|
|
String currentObjectId = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bind(R.id.btn_speak)
|
|
|
|
@Bind(R.id.btn_speak)
|
|
|
@ -109,6 +116,12 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
mLocationClient.registerLocationListener(myListener);
|
|
|
|
mLocationClient.registerLocationListener(myListener);
|
|
|
|
|
|
|
|
|
|
|
|
mContext = getApplicationContext();
|
|
|
|
mContext = getApplicationContext();
|
|
|
|
|
|
|
|
mediaPlayer = new MediaPlayer();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
currentObjectId = BmobUser.getCurrentUser(mContext).getObjectId();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_loc);
|
|
|
|
setContentView(R.layout.activity_loc);
|
|
|
|
c = BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
|
|
|
|
c = BmobIMConversation.obtain(BmobIMClient.getInstance(), (BmobIMConversation) getBundle().getSerializable("c"));
|
|
|
@ -329,7 +342,7 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected String title() {
|
|
|
|
protected String title() {
|
|
|
|
return "寻找 " + c.getConversationTitle();
|
|
|
|
return "寻找" + c.getConversationTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initLocation(){
|
|
|
|
private void initLocation(){
|
|
|
@ -532,19 +545,32 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( msg.getMsgType().equals("sound")){
|
|
|
|
else if ( msg.getMsgType().equals("sound")){
|
|
|
|
audio_msg = BmobIMAudioMessage.buildFromDB(true,msg);
|
|
|
|
audio_msg = BmobIMAudioMessage.buildFromDB(true,msg);
|
|
|
|
|
|
|
|
//if (audio_msg.getFromId().equals(currentObjectId)) {// 如果是自己发送的语音消息,则播放本地地址
|
|
|
|
|
|
|
|
// String localPath = audio_msg.getContent().split("&")[0];
|
|
|
|
|
|
|
|
//startPlayRecord(localPath, true);
|
|
|
|
|
|
|
|
//} else {// 如果是收到的消息,则需要先下载后播放
|
|
|
|
String localPath = BmobDownloadManager.getDownLoadFilePath(audio_msg);
|
|
|
|
String localPath = BmobDownloadManager.getDownLoadFilePath(audio_msg);
|
|
|
|
startPlayRecord(localPath, true);
|
|
|
|
startPlayRecord(localPath, true);
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private SoundPool soundPool;
|
|
|
|
|
|
|
|
private int soundID;
|
|
|
|
|
|
|
|
boolean loaded = false;
|
|
|
|
|
|
|
|
|
|
|
|
public void startPlayRecord(String filePath, boolean isUseSpeaker) {
|
|
|
|
public void startPlayRecord(String filePath, boolean isUseSpeaker) {
|
|
|
|
if (!(new File(filePath).exists())) {
|
|
|
|
if (!(new File(filePath).exists())) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Logger.i("start play Record ");
|
|
|
|
Logger.i("start play Record " + filePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BmobPlayManager playmanager = new BmobPlayManager();
|
|
|
|
|
|
|
|
playmanager.init(mContext);
|
|
|
|
|
|
|
|
playmanager.playRecording(filePath, isUseSpeaker);
|
|
|
|
|
|
|
|
|
|
|
|
/*AudioManager audioManager = (AudioManager) mContext
|
|
|
|
/* AudioManager audioManager = (AudioManager) mContext
|
|
|
|
.getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
.getSystemService(Context.AUDIO_SERVICE);
|
|
|
|
mediaPlayer = new MediaPlayer();
|
|
|
|
mediaPlayer = new MediaPlayer();
|
|
|
|
if (isUseSpeaker) {
|
|
|
|
if (isUseSpeaker) {
|
|
|
@ -563,15 +589,12 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
// mediaPlayer.setDataSource(filePath);
|
|
|
|
// mediaPlayer.setDataSource(filePath);
|
|
|
|
// 因此采用此方式会避免这种错误
|
|
|
|
// 因此采用此方式会避免这种错误
|
|
|
|
FileInputStream fis = new FileInputStream(new File(filePath));
|
|
|
|
FileInputStream fis = new FileInputStream(new File(filePath));
|
|
|
|
//mediaPlayer.setDataSource(fis.getFD());
|
|
|
|
mediaPlayer.setDataSource(fis.getFD());
|
|
|
|
mediaPlayer.setDataSource(filePath);
|
|
|
|
|
|
|
|
mediaPlayer.prepare();
|
|
|
|
mediaPlayer.prepare();
|
|
|
|
mediaPlayer.start();
|
|
|
|
|
|
|
|
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
|
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onPrepared(MediaPlayer arg0) {
|
|
|
|
public void onPrepared(MediaPlayer arg0) {
|
|
|
|
|
|
|
|
|
|
|
|
arg0.start();
|
|
|
|
arg0.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -587,6 +610,7 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void stopPlayRecord() {
|
|
|
|
public void stopPlayRecord() {
|
|
|
|
if (mediaPlayer != null) {
|
|
|
|
if (mediaPlayer != null) {
|
|
|
@ -603,6 +627,7 @@ public class LocActivity extends ParentWithNaviActivity implements ObseverListen
|
|
|
|
super.onDestroy();
|
|
|
|
super.onDestroy();
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
mLocationClient.unRegisterLocationListener( myListener );
|
|
|
|
mLocationClient.stop();
|
|
|
|
mLocationClient.stop();
|
|
|
|
|
|
|
|
|
|
|
|
// 当不需要定位图层时关闭定位图层
|
|
|
|
// 当不需要定位图层时关闭定位图层
|
|
|
|
mBaiduMap.setMyLocationEnabled(false);
|
|
|
|
mBaiduMap.setMyLocationEnabled(false);
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
|
|
|
|