upgrade
This commit is contained in:
216
Assets/trCRM/Scripts/call/CallListner.cs
Normal file
216
Assets/trCRM/Scripts/call/CallListner.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
using UnityEngine.Android;
|
||||
|
||||
public class CallListner : CLBehaviour4Lua
|
||||
{
|
||||
public static CallListner self;
|
||||
const string className = "com.coolape.tianrun.U3dPlugin";
|
||||
#if UNITY_ANDROID
|
||||
AndroidJavaObject _plugin;
|
||||
public AndroidJavaObject plugin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_plugin == null)
|
||||
{
|
||||
_plugin = new AndroidJavaObject(className);
|
||||
}
|
||||
return _plugin;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public CallListner()
|
||||
{
|
||||
self = this;
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
[System.Runtime.InteropServices.DllImport("__Internal")]
|
||||
private static extern void _init(string goName);
|
||||
#endif
|
||||
|
||||
public void init()
|
||||
{
|
||||
setLua();
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("init", gameObject.name);
|
||||
#elif UNITY_IOS
|
||||
_init(gameObject.name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
string[] permissions = new string[]
|
||||
{
|
||||
"android.permission.RECORD_AUDIO",
|
||||
"android.permission.CALL_PHONE",
|
||||
"android.permission.WRITE_EXTERNAL_STORAGE",
|
||||
"android.permission.READ_EXTERNAL_STORAGE",
|
||||
"android.permission.READ_PHONE_STATE",
|
||||
"android.permission.READ_CALL_LOG",
|
||||
"android.permission.WRITE_CALL_LOG",
|
||||
};
|
||||
|
||||
public void checkUserPermission()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
for (int i = 0; i < permissions.Length; i++)
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission(permissions[i]))
|
||||
{
|
||||
Permission.RequestUserPermission(permissions[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool hadUserPermission()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
for (int i = 0; i < permissions.Length; i++)
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission(permissions[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public void ready2Call(string soundRecordFileName, string onEndCallOrgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("begainCall", soundRecordFileName, onEndCallOrgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void waite4Callback(string onEndIncomeCallOrgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("waitingIncomeCall", onEndIncomeCallOrgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void prepareMedia(string audioPath, string orgs)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
// object[] paras = new object[] {audioPath, orgs, plugin};
|
||||
|
||||
plugin.Call("prepareMedia", audioPath, orgs);
|
||||
// ThreadEx.exec2(_prepareMedia, paras);
|
||||
#endif
|
||||
}
|
||||
public void _prepareMedia(object paras)
|
||||
{
|
||||
object[] objs = paras as object[];
|
||||
string audioPath = objs[0].ToString();
|
||||
string orgs = objs[1].ToString();
|
||||
#if UNITY_ANDROID
|
||||
AndroidJavaObject _plugin = objs[2] as AndroidJavaObject;
|
||||
Debug.Log("audioPath==" + audioPath);
|
||||
Debug.Log("orgs==" + orgs);
|
||||
Debug.Log(_plugin);
|
||||
|
||||
|
||||
_plugin.Call("prepareMedia", audioPath, orgs);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void playMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaPlay");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void pauseMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaPause");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void stopMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaStop");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void seekMedia(int progress)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaSeek", progress);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void destroyMedia()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("mediaDestroy");
|
||||
#endif
|
||||
}
|
||||
|
||||
public int getMediaProgress()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
return plugin.Call<int>("getMediaProgress");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
#if UNITY_ANDROID
|
||||
plugin.Call("onDestroy");
|
||||
#endif
|
||||
destroyMedia();
|
||||
}
|
||||
|
||||
|
||||
//====================================================
|
||||
//电话接通
|
||||
void onConectedOutGoingCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onConectedOutGoingCall"), data);
|
||||
}
|
||||
|
||||
//当通话结速
|
||||
void onEndOutGoingCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onEndOutGoingCall"), data);
|
||||
}
|
||||
|
||||
void onEndincomeCall(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onEndincomeCall"), data);
|
||||
}
|
||||
|
||||
void onMediaPrepared(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaPrepared"), data);
|
||||
}
|
||||
|
||||
void onMediaComplet(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaComplet"), data);
|
||||
}
|
||||
void onMediaError(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaError"), data);
|
||||
}
|
||||
|
||||
void onMediaSeek(string data)
|
||||
{
|
||||
Utl.doCallback(getLuaFunction("onMediaSeek"), data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user