upgrade
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.coolape.tianrun;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class CLOutgoingCallListener extends BroadcastReceiver {
|
||||
String TAG = "unity";
|
||||
static Boolean isOutgoingCall = false;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
|
||||
Log.d(TAG, "开始拨号,但并不知道是否接通电话");
|
||||
if (U3dPlugin.isNeedRecordOutCall) {
|
||||
isOutgoingCall = true;
|
||||
U3dPlugin.onBegainOutgoingCall();
|
||||
}
|
||||
} else if (intent.getAction().equals(
|
||||
TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) context
|
||||
.getSystemService(Context.TELEPHONY_SERVICE);// 注册监听器
|
||||
if (telephonyManager.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
||||
|
||||
if (U3dPlugin.isNeedRecordOutCall && isOutgoingCall) {
|
||||
U3dPlugin.onEndgoingCall();
|
||||
isOutgoingCall = false;
|
||||
}
|
||||
Log.d(TAG, "挂电话");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c47c9be3131645a7b1255d79145cd79
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.coolape.tianrun;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
import com.newland.PhoneUtils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Message;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JD 功能:打电话,录音,通话时间
|
||||
*
|
||||
*/
|
||||
public class CLTeleInterface {
|
||||
|
||||
private String TAG = "TeleInterface";
|
||||
private Context activity;
|
||||
// private Handler handler;
|
||||
private Calendar calendar;
|
||||
private String teleStartTime;
|
||||
private String teleEndTime;
|
||||
private TelephonyManager telephonyManager;
|
||||
public static int TELE_START_TIME = 5;
|
||||
public static int TELE_END_TIME = 6;
|
||||
|
||||
public String getTeleStartTime() {
|
||||
return teleStartTime;
|
||||
}
|
||||
|
||||
public String getTeleEndTime() {
|
||||
return teleEndTime;
|
||||
}
|
||||
public PhoneListener listener;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param activity
|
||||
* @param handler
|
||||
* 自定义handler接收消息 msg.what 5:电话拨通时间 6:电话挂断时间
|
||||
*/
|
||||
// public TeleInterface(Context activity, Handler handler) {
|
||||
public CLTeleInterface(Context activity) {
|
||||
this.activity = activity;
|
||||
// this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拨打电话
|
||||
*
|
||||
* @param phoneNum
|
||||
* 需要拨打号码
|
||||
*/
|
||||
public void Call(String phoneNum) {
|
||||
if (phoneNum.length() != 0) {
|
||||
Intent phoneIntent = new Intent("android.intent.action.CALL",
|
||||
Uri.parse("tel:" + phoneNum));
|
||||
activity.startActivity(phoneIntent);
|
||||
} else {
|
||||
Toast.makeText(activity, "不能输入为空", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 来电监听注册
|
||||
*/
|
||||
public void teleListen() {
|
||||
telephonyManager = (TelephonyManager) activity
|
||||
.getSystemService(Context.TELEPHONY_SERVICE);// 注册监听器
|
||||
if(listener == null) {
|
||||
listener = new PhoneListener();
|
||||
}
|
||||
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);// 监听电话状态
|
||||
}
|
||||
|
||||
/**
|
||||
* 挂断电话
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void endCall() throws Exception {
|
||||
ITelephony iTelephony = PhoneUtils.getITelephony(telephonyManager);
|
||||
iTelephony.endCall();// 自动挂断电话
|
||||
}
|
||||
|
||||
private final class PhoneListener extends PhoneStateListener {
|
||||
private String incomeNumber=""; // 来电号码
|
||||
private boolean isComingCall = false;
|
||||
// private MediaRecorder mediaRecorder;
|
||||
// private File root_file, file;
|
||||
|
||||
@Override
|
||||
public void onCallStateChanged(int state, String incomingNumber) {
|
||||
try {
|
||||
switch (state) {
|
||||
case TelephonyManager.CALL_STATE_RINGING: // 来电
|
||||
Log.d(TAG, "来电============");
|
||||
this.incomeNumber = incomingNumber;
|
||||
Log.d(TAG, "incomingNumber==" + incomingNumber);
|
||||
isComingCall = true;
|
||||
break;
|
||||
case TelephonyManager.CALL_STATE_OFFHOOK: // 接通电话
|
||||
Log.d(TAG, "接通电话============");
|
||||
calendar = Calendar.getInstance();
|
||||
teleStartTime = calendar.getTime().toString();
|
||||
|
||||
Message msg_start = new Message();
|
||||
msg_start.what = TELE_START_TIME;
|
||||
msg_start.obj = teleStartTime;
|
||||
Log.d(TAG, "StartTime=====" + teleStartTime);
|
||||
|
||||
if (U3dPlugin.isNeedRecordOutCall) {
|
||||
// isOutgoingCall = true;
|
||||
U3dPlugin.onBegainOutgoingCall();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TelephonyManager.CALL_STATE_IDLE: // 挂掉电话
|
||||
if(isComingCall) {
|
||||
U3dPlugin.onEndincomeCall(incomeNumber);
|
||||
// incomeNumber = "";
|
||||
isComingCall = false;
|
||||
} else {
|
||||
if (U3dPlugin.isNeedRecordOutCall) {
|
||||
U3dPlugin.onEndgoingCall();
|
||||
// isOutgoingCall = false;
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "挂掉电话===================!");
|
||||
break;
|
||||
|
||||
}
|
||||
super.onCallStateChanged(state, incomingNumber);
|
||||
} catch (IllegalStateException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41b4e79026479440ca9684104f56b83b
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.coolape.tianrun;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
import android.media.MediaPlayer.OnPreparedListener;
|
||||
import android.media.MediaPlayer.OnErrorListener;
|
||||
import android.media.MediaPlayer.OnSeekCompleteListener;
|
||||
import android.net.Uri;
|
||||
|
||||
public class MyMediaPlayer {
|
||||
public static volatile MediaPlayer player = null;
|
||||
static String onPrepareOrgs = "";
|
||||
|
||||
public void prepare(Context context, String audioSource, String orgs) {
|
||||
onPrepareOrgs = orgs;
|
||||
try {
|
||||
Uri uri = Uri.parse(audioSource);
|
||||
if (player == null) {
|
||||
player = MediaPlayer.create(context, uri);
|
||||
player.setLooping(false);
|
||||
} else {
|
||||
if (player.isPlaying()) {
|
||||
stop();
|
||||
}
|
||||
player.reset();
|
||||
if (audioSource.startsWith("http")) {
|
||||
player.setDataSource(context, uri);
|
||||
} else {
|
||||
player.setDataSource(audioSource);
|
||||
}
|
||||
player.prepareAsync();
|
||||
}
|
||||
player.setOnPreparedListener(new OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer player) {
|
||||
player.setLooping(false);
|
||||
int len = player.getDuration();
|
||||
U3dPlugin.UnitySendMessage("onMediaPrepared", len + "",
|
||||
onPrepareOrgs);
|
||||
}
|
||||
});
|
||||
player.setOnCompletionListener(new OnCompletionListener() {
|
||||
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer player) {
|
||||
pause();
|
||||
U3dPlugin.UnitySendMessage("onMediaComplet", "true",
|
||||
onPrepareOrgs);
|
||||
}
|
||||
});
|
||||
player.setOnErrorListener(new OnErrorListener() {
|
||||
|
||||
@Override
|
||||
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
|
||||
U3dPlugin.UnitySendMessage("onMediaError", "false",
|
||||
onPrepareOrgs);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
player.setOnSeekCompleteListener(new OnSeekCompleteListener() {
|
||||
|
||||
@Override
|
||||
public void onSeekComplete(MediaPlayer arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
U3dPlugin.UnitySendMessage("onMediaSeek", "true",
|
||||
onPrepareOrgs);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
if (player != null) {
|
||||
return player.getCurrentPosition();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (player != null && player.isPlaying()){
|
||||
player.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void play() {
|
||||
if (player != null && !player.isPlaying()){
|
||||
player.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (player != null)
|
||||
return;
|
||||
if (player.isPlaying()) {
|
||||
player.stop();
|
||||
}
|
||||
try {
|
||||
// mp.prepareAsync();
|
||||
// player.prepare();
|
||||
player.reset();
|
||||
// player.seekTo(0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void seek(int progress) {
|
||||
if (player != null)
|
||||
player.seekTo(progress);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (player != null) {
|
||||
player.stop();
|
||||
player.release();
|
||||
}
|
||||
player = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 454367b24531b47b59738a9ba52727ee
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.coolape.tianrun;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.czt.mp3recorder.MP3Recorder;
|
||||
import com.newland.PhoneUtils;
|
||||
import com.unity3d.player.UnityPlayer;
|
||||
|
||||
public class U3dPlugin {
|
||||
static String TAG = "U3d";
|
||||
public CLTeleInterface teleInterface;
|
||||
public static String u3dListener = "";
|
||||
public static String recordFileName = "";
|
||||
public static Boolean isNeedRecordOutCall = false;
|
||||
public static Boolean isConnectedRecordOutCall = false;
|
||||
public static Boolean isWaiting4IncomeCall = false;
|
||||
public static CLOutgoingCallListener outgoingCallRecver = new CLOutgoingCallListener();
|
||||
public static String onEndIncomeCallOrgs = "";
|
||||
public static String onEndCallOrgs = "";
|
||||
public static U3dPlugin self;
|
||||
// static MediaRecorder mediaRecorder;
|
||||
private static MP3Recorder mRecorder;
|
||||
private static File file;
|
||||
public static MyMediaPlayer mediaPlayer;
|
||||
public static int DefaultAudioSource = -1;
|
||||
|
||||
public void init(String _u3dListener) {
|
||||
self = this;
|
||||
u3dListener = _u3dListener;
|
||||
mediaPlayer = new MyMediaPlayer();
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
teleInterface = new CLTeleInterface(UnityPlayer.currentActivity);
|
||||
teleInterface.teleListen();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
if (mRecorder != null) {
|
||||
mRecorder.stop();
|
||||
mRecorder = null;
|
||||
}
|
||||
file = null;
|
||||
}
|
||||
|
||||
public void waitingIncomeCall(String _onEndIncomeCallOrgs) {
|
||||
onEndIncomeCallOrgs = _onEndIncomeCallOrgs;
|
||||
// isWaiting4IncomeCall = true;
|
||||
}
|
||||
|
||||
public void begainCall(String _recordFileName, String _onEndCallOrgs) {
|
||||
onEndCallOrgs = _onEndCallOrgs;
|
||||
recordFileName = _recordFileName;
|
||||
isNeedRecordOutCall = true;
|
||||
}
|
||||
|
||||
public static void onBegainOutgoingCall() {
|
||||
if (isNeedRecordOutCall) {
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recordCall(recordFileName);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void onEndincomeCall(String incomingPhoneNo) {
|
||||
// if (isWaiting4IncomeCall) {
|
||||
// isWaiting4IncomeCall = false;
|
||||
UnitySendMessage("onEndincomeCall", incomingPhoneNo, onEndIncomeCallOrgs);
|
||||
// }
|
||||
}
|
||||
|
||||
public static void onEndgoingCall() {
|
||||
if (isNeedRecordOutCall) {
|
||||
endRecordCall();
|
||||
UnitySendMessage("onEndOutGoingCall", "0", onEndCallOrgs);
|
||||
recordFileName = "";
|
||||
isNeedRecordOutCall = false;
|
||||
isConnectedRecordOutCall = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void recordCall(String fileName) {
|
||||
if (fileName == null || fileName.isEmpty())
|
||||
return;
|
||||
try {
|
||||
file = new File(fileName);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
if (mRecorder == null) {
|
||||
mRecorder = new MP3Recorder(file);
|
||||
}
|
||||
mRecorder.setRecordFile(file);
|
||||
// int sdkVer = PhoneUtils.getSDKVersionNumber();
|
||||
if (DefaultAudioSource < 0) {
|
||||
// if (sdkVer >= 23) {
|
||||
// DefaultAudioSource = MediaRecorder.AudioSource.MIC;
|
||||
// } else {
|
||||
DefaultAudioSource = MediaRecorder.AudioSource.VOICE_CALL;
|
||||
// }
|
||||
}
|
||||
// 获得声音数据源
|
||||
mRecorder.setAudioSource(DefaultAudioSource);
|
||||
mRecorder.start();
|
||||
|
||||
Log.d(TAG, "开始录音!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
endRecordCall();
|
||||
if (mRecorder == null) {
|
||||
mRecorder = new MP3Recorder(file);
|
||||
}
|
||||
file = new File(fileName);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
if (mRecorder == null) {
|
||||
mRecorder = new MP3Recorder(file);
|
||||
}
|
||||
mRecorder.setRecordFile(file);
|
||||
|
||||
DefaultAudioSource = MediaRecorder.AudioSource.MIC;
|
||||
// int sdkVer = PhoneUtils.getSDKVersionNumber();
|
||||
mRecorder.setAudioSource(DefaultAudioSource);
|
||||
mRecorder.start();
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void endRecordCall() {
|
||||
// if (mediaRecorder != null) {
|
||||
// mediaRecorder.stop();
|
||||
// mediaRecorder.release();
|
||||
// mediaRecorder = null;
|
||||
// }
|
||||
try {
|
||||
if (mRecorder != null) {
|
||||
mRecorder.stop();
|
||||
// mRecorder = null;
|
||||
|
||||
file = null;
|
||||
Log.d(TAG, "结束录音!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static String audioSource;
|
||||
static String orgs;
|
||||
|
||||
public void prepareMedia(String _audioSource, String _orgs) {
|
||||
audioSource = _audioSource;
|
||||
orgs = _orgs;
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaPlayer.prepare(UnityPlayer.currentActivity, audioSource,
|
||||
orgs);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void mediaPlay() {
|
||||
mediaPlayer.play();
|
||||
}
|
||||
|
||||
public void mediaStop() {
|
||||
mediaPlayer.stop();
|
||||
}
|
||||
|
||||
public void mediaPause() {
|
||||
mediaPlayer.pause();
|
||||
}
|
||||
|
||||
static int seekPosition = 0;
|
||||
|
||||
public void mediaSeek(int progress) {
|
||||
seekPosition = progress;
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mediaPlayer.seek(seekPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void mediaDestroy() {
|
||||
mediaPlayer.destroy();
|
||||
}
|
||||
|
||||
public int getMediaProgress() {
|
||||
return mediaPlayer.getProgress();
|
||||
}
|
||||
|
||||
public static void UnitySendMessage(String CallbackFunc, String retCode,
|
||||
String orgs) {
|
||||
if (u3dListener.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put("code", retCode);
|
||||
jsonObj.put("orgs", orgs);
|
||||
UnityPlayer.UnitySendMessage(u3dListener, CallbackFunc,
|
||||
jsonObj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cab5480656f834957a7195cdc9f55ea4
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user