Commit b573ce5e authored by sheteng's avatar sheteng

开始测试 1

parent 6cf704cf
......@@ -44,9 +44,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.2.0'
def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"
def lifecycle_version = "2.3.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
......
......@@ -277,7 +277,12 @@ public class FirstFragment extends Fragment {
binding.startRecordAudioMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CCIMClient.getInstance().startRecordAudioMessage(getActivity());
CCIMClient.getInstance().startRecordAudioMessage(getActivity(), new ResultCallback() {
@Override
public void onSuccess() {
}
});
}
});
binding.stopAndSendAudioMessage.setOnClickListener(new View.OnClickListener() {
......
package com.ccwangluo.im;
import android.os.Bundle;
import com.ccwangluo.ccim.util.HmacUtil;
import com.google.android.material.snackbar.Snackbar;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
......@@ -16,9 +11,6 @@ import androidx.navigation.ui.NavigationUI;
import com.ccwangluo.im.databinding.ActivityMainBinding;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration appBarConfiguration;
......
......@@ -7,10 +7,13 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.ccwangluo.ccim.CCIMClient;
import com.ccwangluo.ccim.listener.ResultCallback;
import com.ccwangluo.ccim.modle.MessageContent;
import com.ccwangluo.im.R;
......@@ -75,6 +78,19 @@ public class ChannelMsgAdapter extends BaseAdapter {
} else {
mHolder.msg_content.setText("语音消息");
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageContent.getMsgType() == MessageContent.MessageType.MESSAGE_TYPE_VOICE) {
CCIMClient.getInstance().startPlayAudio(messageContent.getMsgId(), new ResultCallback() {
@Override
public void onSuccess() {
Toast.makeText(context, "播放成功", Toast.LENGTH_SHORT).show();
}
});
}
}
});
return convertView;
}
......
......@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.ccwangluo.ccim.CCIMClient;
import com.ccwangluo.ccim.listener.ResultCallback;
import com.ccwangluo.ccim.modle.Contact;
import com.ccwangluo.ccim.modle.MessageContent;
import com.ccwangluo.ccim.listener.ResultEventCallback;
......@@ -73,6 +74,11 @@ public class ConnectFragment extends Fragment {
loginViewModel.addPrivateMsg(messageContent);
Toast.makeText(getContext(), "send Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), "send onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
});
......@@ -88,10 +94,19 @@ public class ConnectFragment extends Fragment {
loginViewModel.addPrivateMsg(message);
Toast.makeText(getContext(), "send Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), "send onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
CCIMClient.getInstance().startRecordAudioMessage(getActivity());
CCIMClient.getInstance().startRecordAudioMessage(getActivity(), new ResultCallback() {
@Override
public void onSuccess() {
}
});
}
return false;
......
......@@ -109,6 +109,10 @@ public class ContactsFragment extends Fragment {
showSearchResultdialog(users);
}
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), " onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
});
......@@ -140,6 +144,11 @@ public class ContactsFragment extends Fragment {
Toast.makeText(getContext(), "createContactGroup success", Toast.LENGTH_SHORT).show();
loginViewModel.getContactList();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), " onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
});
......
......@@ -6,7 +6,6 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
......@@ -36,7 +35,6 @@ public class LoginActivity extends AppCompatActivity {
final EditText usernameEditText = binding.username;
final EditText UserIdEditText = binding.password;
final Button loginButton = binding.login;
final ProgressBar loadingProgressBar = binding.loading;
loginViewModel.loginState.observe(this, new Observer<Boolean>() {
@Override
......
......@@ -12,6 +12,7 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.ccwangluo.ccim.CCIMClient;
import com.ccwangluo.ccim.listener.ResultCallback;
import com.ccwangluo.ccim.listener.ResultEventCallback;
import com.ccwangluo.ccim.modle.MessageContent;
import com.ccwangluo.im.adapter.ChannelMsgAdapter;
......@@ -71,6 +72,10 @@ public class ConnectChannelFragment extends Fragment {
loginViewModel.addChannelMsg(messageContent);
Toast.makeText(getContext(), "send Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), "send onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
});
......@@ -86,10 +91,20 @@ public class ConnectChannelFragment extends Fragment {
loginViewModel.addChannelMsg(message);
Toast.makeText(getContext(), "send Success", Toast.LENGTH_LONG).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), "send onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
CCIMClient.getInstance().startRecordAudioMessage(getActivity());
CCIMClient.getInstance().startRecordAudioMessage(getActivity(), new ResultCallback() {
@Override
public void onSuccess() {
}
});
}
return false;
......
......@@ -97,6 +97,11 @@ public class NotificationsFragment extends Fragment {
Toast.makeText(getContext(), "join success", Toast.LENGTH_SHORT).show();
loginViewModel.addChannelId(Id);
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), " onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
......@@ -141,11 +146,17 @@ public class NotificationsFragment extends Fragment {
@Override
public void onSuccess(Long aLong) {
//获取剪贴板管理器:
loginViewModel.addChannelId(aLong);
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData mClipData = ClipData.newPlainText("Label", aLong.toString());
cm.setPrimaryClip(mClipData);
Toast.makeText(getContext(), "create success,id copy success", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), " onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
}
});
......@@ -170,6 +181,11 @@ public class NotificationsFragment extends Fragment {
loginViewModel.removeChannelId(id);
Toast.makeText(getContext(),"退出成功",Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(int errorCode) {
Toast.makeText(getContext(), " onFailed :" + errorCode, Toast.LENGTH_LONG).show();
}
});
break;
}
......
......@@ -14,7 +14,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:text="15"
android:text="18"
android:inputType="textEmailAddress"
android:selectAllOnFocus="true"
app:layout_constraintEnd_toEndOf="parent"
......@@ -27,7 +27,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="UserId"
android:text="15"
android:text="18"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionDone"
android:selectAllOnFocus="true"
......
......@@ -4,9 +4,7 @@ import android.Manifest;
import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;
import androidx.fragment.app.FragmentActivity;
import com.ccwangluo.ccim.listener.ContactsCallBack;
import com.ccwangluo.ccim.listener.OnClientConnectListener;
import com.ccwangluo.ccim.listener.OnConnectListener;
......@@ -28,13 +26,11 @@ import com.ccwangluo.ccim.util.MediaHelper;
import com.google.gson.Gson;
import com.google.protobuf.util.JsonFormat;
import com.permissionx.guolindev.PermissionX;
import java.io.File;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
import ccim.protocol.Chat;
import ccim.protocol.Message;
import ccim.protocol.MessageSpec;
......@@ -53,6 +49,7 @@ public class CCIMClient {
private Long lastSendTimemillis = 0L; //上次发送消息时间,用于时间间隔
private int maxSendMsgInterval = 0;
private int maxAudioDuration = 0;
private int minAudioDuration = 500;
private String downloadPrefix;
private String cachePath;
......@@ -60,7 +57,11 @@ public class CCIMClient {
private CCIMClient() {
callBackManager = new CallBackManager<>();
socketManager = new SocketManager(callBackManager);
contactManager = new ContactManager(socketManager, callBackManager);
channelManager = new ChannelManager(socketManager, callBackManager);
messageManager = new MessageManager(socketManager, callBackManager, executor);
}
private static CCIMClient mInstance;
......@@ -70,10 +71,6 @@ public class CCIMClient {
synchronized (CCIMClient.class) {
if (mInstance == null) {
mInstance = new CCIMClient();
callBackManager = new CallBackManager<>();
socketManager = new SocketManager(callBackManager);
contactManager = new ContactManager(socketManager, callBackManager);
channelManager = new ChannelManager(socketManager, callBackManager);
}
}
}
......@@ -85,12 +82,13 @@ public class CCIMClient {
}
public void initSDK(Context context, String appKey, String userName, String extData, Long userId, Long ts, String sign, OnConnectListener resultCallback) {
messageManager = new MessageManager(executor, context, userId, socketManager, callBackManager);
this.userId = userId;
messageManager.init(context, userId);
socketManager.initChat(context, appKey, userName, extData, userId, ts, sign, new OnClientConnectListener() {
@Override
public void onSocketConnection(Chat.ConnectResponse.ClientConfig clientConfig) {
maxSendMsgInterval = clientConfig.getSendMsgInterval();
maxAudioDuration = clientConfig.getMaxAudioDuration();
maxAudioDuration = clientConfig.getMaxAudioDuration() * 1000;
downloadPrefix = clientConfig.getDownloadPrefix();
getContactList((contacts, contactGroups, dialog) -> {
if (!isConnected) {
......@@ -149,6 +147,7 @@ public class CCIMClient {
MessageContent messageContent = gson.fromJson(print, MessageContent.class);
messageContent.setChannelId(channelMsgRes.getChannelId());
pushMsgListener.pushChannelMsg(messageContent);
messageManager.pushNewMessage(messageContent);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -297,7 +296,7 @@ public class CCIMClient {
}
/**
* 加入频道
* 频道拉黑
*/
public void blockChannelUser(Long channelId, Long userId, ResultCallback callback) {
channelManager.blockChannelUser(channelId, userId, callback);
......@@ -408,14 +407,16 @@ public class CCIMClient {
* 开始录音
*/
public void startRecordAudioMessage(FragmentActivity activity) {
public void startRecordAudioMessage(FragmentActivity activity, ResultCallback resultCallback) {
PermissionX.init(activity)
.permissions(Manifest.permission.RECORD_AUDIO)
.onExplainRequestReason((scope, deniedList, beforeRequest) -> scope.showRequestReasonDialog(deniedList, "即将申请的权限是程序必须依赖的权限", "我已明白"))
.onForwardToSettings((scope, deniedList) -> scope.showForwardToSettingsDialog(deniedList, "您需要去应用程序设置当中手动开启权限", "我已明白"))
.request((allGranted, grantedList, deniedList) -> {
if (allGranted) {
MediaHelper.getInstance().prepare(activity, cachePath);
MediaHelper.getInstance().prepare(cachePath,maxAudioDuration, resultCallback);
} else {
resultCallback.onFailed(ErrorCode.START_VOICE_FAILED);
}
});
}
......@@ -424,7 +425,9 @@ public class CCIMClient {
* 停止录音并上传 私聊
*/
public void stopAndSendAudioMessage(Long receiveUserId, String receiveUserName, ResultEventCallback<MessageContent> callback) {
if (checkAudio(callback)) return;
if (checkAudio(callback)) {
return;
}
messageManager.uploadFileMessage(cachePath, new ResultEventCallback<String>() {
@Override
public void onSuccess(String fileName) {
......@@ -453,7 +456,9 @@ public class CCIMClient {
* 停止录音并上传 频道
*/
public void stopAndSendChannelAudioMessage(Long channelID, ResultEventCallback<MessageContent> callback) {
if (checkAudio(callback)) return;
if (checkAudio(callback)) {
return;
}
messageManager.uploadFileMessage(cachePath, new ResultEventCallback<String>() {
@Override
public void onSuccess(String fileName) {
......@@ -469,7 +474,7 @@ public class CCIMClient {
private boolean checkAudio(ResultEventCallback<MessageContent> callback) {
Long release = MediaHelper.getInstance().release();
if (release < 500) {
if (release < minAudioDuration) {
callback.onFailed(ErrorCode.VOICE_TOO_SHORT);
MediaHelper.getInstance().cancel();
return true;
......
......@@ -102,7 +102,7 @@ public class ChannelManager {
}
/**
* 加入频道
* 频道拉黑
*/
public void blockChannelUser(Long channelId, Long userId, ResultCallback callback) {
Chat.ChatRequestMessage.Builder builder = Chat.ChatRequestMessage.newBuilder();
......
......@@ -386,11 +386,19 @@ public class ContactManager {
});
}
/**
*
* @param strangerDialog
*/
public void putStrangerDialog(Dialog strangerDialog) {
dialogs.put(strangerDialog.getContactUserId(), strangerDialog);
}
/**
* 新增对话列表
* @param senderUserId
* @param userName
*/
public void putContactDialog(Long senderUserId, String userName) {
if (!dialogs.containsKey(senderUserId)) {
Dialog dialog = new Dialog();
......@@ -413,6 +421,10 @@ public class ContactManager {
}
/**
* 新联系人
* @param contact
*/
public void pushNewContact(Contact contact) {
contacts.put(contact.getContactUserId(), contact);
Dialog dialog = dialogs.get(contact.getContactUserId());
......@@ -421,11 +433,20 @@ public class ContactManager {
}
}
/**
* 删除联系人
* @param contactUserId
*/
public void pushDeleteContact(long contactUserId) {
contacts.remove(contactUserId);
dialogs.remove(contactUserId);
}
/**
* 更新联系人网络状态
* @param contactUserId
* @param netStatus
*/
public void pushContactNetStatus(long contactUserId, NetStatus netStatus) {
Contact contact = contacts.get(contactUserId);
if (contact != null) {
......
......@@ -29,16 +29,20 @@ public class MessageManager {
private CallBackManager<Chat.ChatResponseMessage> callBackManager;
private ExecutorService executor;
private Long lastSendTimemillis = 0L;
private long userId;
private AppDatabase db;
public MessageManager(ExecutorService executor, Context context, Long userId, SocketManager socketManager, CallBackManager<Chat.ChatResponseMessage> callBackManager) {
this.userId = userId;
public MessageManager(SocketManager socketManager, CallBackManager<Chat.ChatResponseMessage> callBackManager, ExecutorService executor) {
this.socketManager = socketManager;
this.callBackManager = callBackManager;
this.executor = executor;
db = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "ccim_db").build();
}
public void init(Context context, Long userId) {
this.userId = userId;
if (db == null) {
db = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "ccim_db").build();
}
}
......@@ -163,7 +167,6 @@ public class MessageManager {
FileUtils.uploadFile(filePath, preSignedUrl, new ResultCallback() {
@Override
public void onSuccess() {
// sendVoidMessage(filename, receiveUserId, callback);
callback.onSuccess(filename);
}
......@@ -184,11 +187,10 @@ public class MessageManager {
}
public void playAudio(Long msgId, String downloadPrefix, String cachePath, ResultCallback resultCallback) {
executor.execute(() -> {
MessageContent messageContent = db.messageDao().getMsgById(msgId);
if (messageContent == null){
if (messageContent == null) {
resultCallback.onFailed(ErrorCode.MSG_NOT_EXISTS);
return;
}
......
......@@ -20,8 +20,7 @@ import ccim.protocol.Common;
public class SocketManager {
private final Logger logger = Logger.getLogger(CCIMClient.class.getName());
// private static final String SERVER_IP = "117.144.156.2";
private static String SERVER_IP = "10.4.5.134";
private static String SERVER_IP = "106.15.237.67";
private static int SERVER_PORT = 8000;
private static final int version = 1;
......@@ -58,7 +57,7 @@ public class SocketManager {
@Override
public void onSuccess(Chat.ChatResponseMessage chatResponseMessage) {
Chat.ConnectResponse connectRes = chatResponseMessage.getConnectRes();
long l = connectRes.getHeartBeatInterval() * 1000L;
long l = connectRes.getHeartBeatInterval();
pulseData(l);
Chat.ConnectResponse.ClientConfig clientCfg = connectRes.getClientCfg();
onConnectListener.onSocketConnection(clientCfg);
......@@ -94,7 +93,6 @@ public class SocketManager {
String json = JsonFormat.printer().print(data);
logger.info(json);
if (data.hasHeartbeatRes()) {
// OkSocket.open(chatInfo).getPulseManager().feed();
return;
}
if (data.hasConnectionStateRes()) {
......@@ -165,7 +163,6 @@ public class SocketManager {
}
public void disConnect() {
socketClient.destroy();
}
......
......@@ -8,10 +8,10 @@ import android.net.NetworkInfo;
import com.ccwangluo.ccim.CCIMClient;
import com.ccwangluo.ccim.listener.MessageListener;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import ccim.protocol.Chat;
......@@ -48,9 +48,7 @@ public class NettyChatClient implements SocketClient {
EventLoopGroup group = new NioEventLoopGroup();
private ExecutorService executor = Executors.newSingleThreadExecutor();
// 计时器
private Timer timer;
ScheduledExecutorService timerExcutor;
public NettyChatClient(Context context, String ip, int port) {
this.ip = ip;
......@@ -87,11 +85,13 @@ public class NettyChatClient implements SocketClient {
private void connect() {
try {
channelFuture = bootstrap.connect(ip, port).sync();
} catch (Exception e) {
e.printStackTrace();
}
executor.execute(() -> {
try {
channelFuture = bootstrap.connect(ip, port).sync();
} catch (Exception e) {
e.printStackTrace();
}
});
}
......@@ -127,8 +127,8 @@ public class NettyChatClient implements SocketClient {
@Override
public void destroy() {
if (timer != null) {
timer.cancel();
if (timerExcutor != null) {
timerExcutor.shutdown();
}
if (channelFuture != null) {
channelFuture.channel().close();
......@@ -146,11 +146,11 @@ public class NettyChatClient implements SocketClient {
@Override
public void heartBeat(Long frequency, Chat.ChatRequestMessage build) {
if (timer != null) {
timer.cancel();
if (timerExcutor != null) {
timerExcutor.shutdown();
}
timer = new Timer();
TimerTask timerTask = new TimerTask() {
timerExcutor = Executors.newScheduledThreadPool(1);
timerExcutor.schedule(new Runnable() {
@Override
public void run() {
if (getConnectivityStatus(context)) {
......@@ -167,8 +167,7 @@ public class NettyChatClient implements SocketClient {
}
}
}
};
timer.schedule(timerTask, frequency, frequency);
}, frequency, TimeUnit.MILLISECONDS);
}
......
......@@ -13,5 +13,6 @@ public class ErrorCode {
public static final int MSG_NOT_EXISTS = 908; //播放类型错误
public static final int MSG_CONTENT_IS_EMPTY = 910; //发送消息体为空
public static final int START_VOICE_FAILED = 911; //录音创建失败
}
......@@ -58,7 +58,7 @@ public class FileUtils {
return null;
}
File oldFile = new File(oldPath);
File newFile = new File(newPath,newFileName);
File newFile = new File(newPath, newFileName);
if (oldFile.exists() && oldFile.isFile()) {
boolean b = oldFile.renameTo(newFile);
}
......@@ -74,35 +74,37 @@ public class FileUtils {
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
logger.info(e.toString());
resultEventCallback.onFailed(ErrorCode.DOWNLOAD_ERR);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
writeFile(file,response);
writeFile(file, response);
resultEventCallback.onSuccess(file);
}
});
}
private static void writeFile(File file,Response response) {
private static void writeFile(File file, Response response) {
OutputStream outputStream = null;
InputStream inputStream = response.body().byteStream();
try {
outputStream = new FileOutputStream(file);
int len = 0;
byte[] buffer = new byte[1024*10];
while ((len = inputStream.read(buffer))!=-1){
outputStream.write(buffer,0,len);
byte[] buffer = new byte[1024 * 10];
while ((len = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
} finally {
try {
if(inputStream != null)
if (inputStream != null)
inputStream.close();
if(outputStream != null)
if (outputStream != null)
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
......
package com.ccwangluo.ccim.util;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Build;
......@@ -8,7 +7,6 @@ import android.os.Build;
import com.ccwangluo.ccim.listener.ResultCallback;
import java.io.File;
import java.io.IOException;
public class MediaHelper {
private MediaRecorder mMediaRecorder;
......@@ -32,15 +30,15 @@ public class MediaHelper {
}
return mInstance;
}
/**
* 准备录音
*/
public void prepare(Activity activity,String path) {
public void prepare(String path, int maxAudioDuration, ResultCallback resultCallback) {
try {
if (mMediaRecorder != null){
if (mMediaRecorder != null) {
cancel();
}
String fileName = System.currentTimeMillis() + ".aac"; // 文件名字
File file = new File(path, fileName); // 文件路径
mMediaRecorder = new MediaRecorder();
......@@ -61,12 +59,12 @@ public class MediaHelper {
mMediaRecorder.prepare();
mMediaRecorder.start();
start_record_millis = System.currentTimeMillis();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
resultCallback.onSuccess();
} catch (Exception e) {
resultCallback.onFailed(ErrorCode.START_VOICE_FAILED);
}
}
/**
* 释放资源,获取录音时长
*/
......@@ -75,13 +73,14 @@ public class MediaHelper {
mMediaRecorder.release();
mMediaRecorder = null;
}
if (start_record_millis != 0L){
if (start_record_millis != 0L) {
long l = System.currentTimeMillis() - start_record_millis;
start_record_millis = 0L;
return l;
}
return 0L;
}
/**
* 取消
*/
......@@ -99,9 +98,10 @@ public class MediaHelper {
/**
* 播放
*
* @param filePath
*/
public void play(String filePath, ResultCallback resultCallback) {
public void play(String filePath, ResultCallback resultCallback) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(filePath);
......@@ -114,7 +114,7 @@ public class MediaHelper {
}
//获取生成的文件路径
public String getFilePath(String filename,String path) {
return FileUtils.renameFile(mFilePath,path,filename);
public String getFilePath(String filename, String path) {
return FileUtils.renameFile(mFilePath, path, filename);
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment