I want to record call voice during the call time on BlackBerry 10 OS. For this I used Telephony Phone and Call State Listener. I start as found Call State "Connected" and stop when call "Disconnected".
But at start time recorder records only 160Byte of data each time.
and at stop time recorder shows "Already unprepared".
For this I use recorder.prepare() but it still didn't work for me. Please suggest and help me. Here is the code
void ApplicationHeadless::onCallUpdated(const Call &call)
{
QMetaObject MetaCallTypeObject = CallType::staticMetaObject;
QMetaEnum CallTypeEnum = MetaCallTypeObject.enumerator(
MetaCallTypeObject.indexOfEnumerator("Type"));
QMetaObject MetaCallStateObject = CallState::staticMetaObject;
QMetaEnum CallStateEnum = MetaCallStateObject.enumerator(
MetaCallStateObject.indexOfEnumerator("Type"));
CallType::Type CurrentCallType = call.callType();
CallState::Type CurrentCallState = call.callState();
QString conn = "Connected";
QString dcon = "Disconnected";
QDateTime now = QDateTime::currentDateTime();
bb::multimedia::AudioRecorder recorder;
if (conn.compare(CallStateEnum.valueToKey(CurrentCallState)) == 0) {
recorder.setOutputUrl(QUrl("/tmp/" + now.toString() + ".m4a"));
recorder.setOutputUrl(QUrl("file://" + QDir::currentPath() + "/data/recording121.m4a"));
recorder.record();
}
if (dcon.compare(CallStateEnum.valueToKey(CurrentCallState)) == 0) {
recorder.reset();
}
}
Thanks in advance..
Related
We used linphone for the VoIP app and faced issues in conference call duration. Duration not increased after merge call successfully.
Every time displays 00:00 but the call is generated successfully.We used below code for conference call
LinphoneAddress* linphoneAddress = linphone_core_interpret_url([LinphoneManager
getLc], [username cStringUsingEncoding:[NSString defaultCStringEncoding]]);
if (linphoneAddress == NULL) {
return;
}
linphone_core_enter_conference(LC);
LinphoneCall *call = linphone_core_invite_address(LC, linphoneAddress);
-(NSString *)getCallDuration
{
LinphoneCore *lc = [LinphoneManager getLc];
int duration =
linphone_core_get_current_call(lc) ?
linphone_call_get_duration(linphone_core_get_current_call(lc)) :
0;
NSString *str_duration = [LinphoneUtils
durationToString:duration];
return str_duration;
}
So anyone has any solution then please help us.
Thank you.
Please help if anybody has idea what happened with this case.
I have BroadcastReceiver which register to ForegroundService. This BroadcastReceiver will listen to Intent.ACTION_SCREEN_ON and called startLocationUpdates() if it receive any.
fun startLocationUpdates(context: Context, entity: LockEntityDB?) {
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
mSettingsClient = LocationServices.getSettingsClient(context)
mLocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
super.onLocationResult(locationResult)
val location = locationResult?.lastLocation
locationResult?.let {
saveLocation(context, it.lastLocation)
locationUpdatesCount(context)
}
//something will do with entityDb
}
}
mOneTimeLocationRequest = LocationRequest().apply {
interval = 5 * 1000
fastestInterval = 1000
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
numUpdates = 1
}
val builder = LocationSettingsRequest.Builder()
builder.addLocationRequest(mOneTimeLocationRequest!!)
mLocationSettingsRequest = builder.build()
mSettingsClient
?.checkLocationSettings(mLocationSettingsRequest)
?.addOnSuccessListener {
mFusedLocationClient?.requestLocationUpdates(mOneTimeLocationRequest, mLocationCallback, null)
}
?.addOnFailureListener { e ->
kTimberLog(context, "loc " + e.toString())
}
}
So the idea if user turn on the phone, it will send Intent.ACTION_SCREEN_ON and FusedLocationProviderClient will update actual user location.
The problem is, when user try to turn on the phone after 5-6x FusedLocationProviderClient never give any locationResult anymore.
The more weirdest part all this locationResult for the 6th times and so on will start reappearing when user open the MainActivity.
Additional info : I m testing this code on 3 emulator : Nexus 5 API 23, PIXEL 3 API 29, Galaxy Nexus API 29. It works fine for Nexus 5 API 23.
Anybody know what is the reason of this behavior? Thank you very much
After struggling for few days, I found the solution here :
https://developer.android.com/training/location/request-updates#continue-user-initiated-action
After adding this line into my manifest, everything looks working fine
<service
android:name="MyBackgroundService"
android:foregroundServiceType="location" ... >
...
I hope can help somebody who are stuck in same problem
I recently started using Unity3D and made a few levels. The only problem I have right now is how can I get a live counter?
So my character dies when he hits and certain object.
I want my character to get 3 lives maximum, and get -1 live when he hits that object.
And that it keeps the data when he dies so you wouldn't get lives back if you restart the app.
And after a certain amount of minutes he gets +1 live.
Thank you :)
While your game running. just create a variable counterTime to count time, whenever counterTime pass certain amount of time you want reset counterTime to 0 and increase your life.
When user quit your app, save last time to PlayerPref, eg:
PlayerPref.SaveString("LastTime", DateTime.Now);
When user comback game, just check duration between last time and now to calculate total life need added. eg:
DateTime lastTime = DateTime.Parse(PlayerPref.GetString("LastTime"));
TimeSpan timeDif= DateTime.Now - lastTime;
int duration = timeDif.TotalSeconds;
You can use PlayerPrefs.SetInt , PlayerPrefs.GetInt for storing and reading your player's hp in file storage. Read more about it here:
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
As for Giving player +1 hp after a few minutes you can store DateTime.Now in a PlayerPrefs variable whenever you give your player some hp and use TimeSpan and TotalMinutesPassed:
TimeSpan passedTime = DateTime.Now - lastStoredDateTime;
int totalMinutesPassed = passedTime.TotalMinutes;
Should go sth like this i guess(didnt test this code just showing a general idea) :
void SetPlayerLives(int lives)
{
playerLives = lives;
PlayerPrefs.SetInt("player-lives",playerLives);
}
//TODO: also sth like => int GetPlayerLives() function
void CheckLiveRegen() //call this function whenever you want to check live regen:
{
int LIVE_REGEN_MINUTES = 5; //regen 1 live every 5 minutes
DateTime lastStoredDateTime = DateTime.Parse(PlayerPrefs.GetString("last-live-regen", DateTime.Now.ToString()));
TimeSpan passedTime = DateTime.Now - lastStoredDateTime;
double totalMinutesPassed = passedTime.TotalMinutes;
if(totalMinutesPassed >= LIVE_REGEN_MINUTES)
{
int val = (int) totalMinutesPassed / LIVE_REGEN_MINUTES;
// Add val to your player lives! + store new lives value
SetPlayerLives(playerLives+val);
//update last-live-regen value:
PlayerPrefs.SetString("last-live-regen", DateTime.Now.ToString());
}
}
Note: DateTime , TimeSpan classes have some bugs (specially in android platform) in versions older than 2017.4 (LTS) Make sure you log values and check if functions are working properly.
https://forum.unity.com/threads/android-datetime-now-is-wrong.488380/
check out the following link to understand how to create a life counter in unity
http://codesaying.com/life-counter-in-unity/
In order to calculate the time that was lapsed since you last shut down the game, you should save the last time playerprefs in the function OnApplicationPause and calcuate the timelapsed in the Awake Function.
void Awake () {
if(!PlayerPrefs.HasKey("Lives")){
PlayerPrefs.SetString("LifeUpdateTime", DateTime.Now.ToString());
}
lives = PlayerPrefs.GetInt("Lives", maxLives);
//update life counter only if lives are less than maxLives
if (lives < maxLives)
{
float timerToAdd = (float)(System.DateTime.Now - Convert.ToDateTime(PlayerPrefs.GetString("LifeUpdateTime"))).TotalSeconds;
UpdateLives(timerToAdd);
}
}
void UpdateLives(double timerToAdd ){
if (lives < maxLives)
{
int livesToAdd = Mathf.FloorToInt((float)timerToAdd / lifeReplenishTime);
timerForLife = (float)timerToAdd % lifeReplenishTime;
lives += livesToAdd;
if (lives > maxLives)
{
lives = maxLives;
timerForLife = 0;
}
PlayerPrefs.SetString("LifeUpdateTime", DateTime.Now.AddSeconds(-timerForLife).ToString());
}else{
PlayerPrefs.SetString("LifeUpdateTime", DateTime.Now.ToString());
}
}
void OnApplicationPause(bool isPause)
{
if (isPause)
{
timeOfPause = System.DateTime.Now;
}
else
{
if(timeOfPause == default(DateTime)){
timeOfPause = System.DateTime.Now;
}
float timerToAdd = (float)(System.DateTime.Now - timeOfPause).TotalSeconds;
timerForLife += timerToAdd;
UpdateLives(timerForLife);
}
}
}
I love Google Forms I can play with them for hours. I have spent days trying to solve this one, searching for an answer. It is very much over my head. I have seen similar questions but none that seemed to have helped me get to an answer. We have a café where I work and I created a pre-order form on Google Forms. That was the easy part. The Café can only accept pre-orders up to 10:30am. I want the form to open at 7am and close at 10:30am everyday to stop people pre ordering when the café isn't able to deal with their order. I used the very helpful tutorial from http://labnol.org/?p=20707 to start me off I have added and messed it up and managed to get back to the below which is currently how it looks. It doesn't work and I can't get my head around it. At one point I managed to turn it off but I couldn't turn it back on!! I'm finding it very frustrating and any help in solving this would be amazing. To me it seems very simple as it just needs to turn on and off at a certain time every day. I don't know! Please help me someone?
FORM_OPEN_DATE = "7:00";
FORM_CLOSE_DATE = "10:30";
RESPONSE_COUNT = "";
/* Initialize the form, setup time based triggers */
function Initialize() {
deleteTriggers_();
if ((FORM_OPEN_DATE !== "7:00") &&
((new Date()).getTime("7:00") < parseDate_(FORM_OPEN_DATE).getTime ("7:00"))) {
closeForm("10:30");
ScriptApp.newTrigger("openForm")
.timeBased("7:00")
.at(parseDate_(FORM_OPEN_DATE))
.create(); }
if (FORM_CLOSE_DATE !== "10:30") {
ScriptApp.newTrigger("closeForm")
.timeBased("10:30")
.at(parseDate_(FORM_CLOSE_DATE))
.create(); }
if (RESPONSE_COUNT !== "") {
ScriptApp.newTrigger("checkLimit")
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create(); } }
/* Delete all existing Script Triggers */
function deleteTriggers_() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
/* Allow Google Form to Accept Responses */
function openForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(true);
informUser_("Your Google Form is now accepting responses");
}
/* Close the Google Form, Stop Accepting Reponses */
function closeForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(false);
deleteTriggers_();
informUser_("Your Google Form is no longer accepting responses");
}
/* If Total # of Form Responses >= Limit, Close Form */
function checkLimit() {
if (FormApp.getActiveForm().getResponses().length >= RESPONSE_COUNT ) {
closeForm();
}
}
/* Parse the Date for creating Time-Based Triggers */
function parseDate_(d) {
return new Date(d.substr(0,4), d.substr(5,2)-1,
d.substr(8,2), d.substr(11,2), d.substr(14,2));
}
I don't think you can use .timebased('7:00'); And it is good to check that you don't have a trigger before you try creating a new one so I like to do this. You can only specify that you want a trigger at a certain hour like say 7. The trigger will be randomly selected somewhere between 7 and 8. So you really can't pick 10:30 either. It has to be either 10 or 11. If you want more precision you may have to trigger your daily triggers early and then count some 5 minute triggers to get you closer to the mark. You'll have to wait to see where the daily triggers are placed in the hour first. Once they're set they don't change.
I've actually played around with the daily timers in a log by creating new ones until I get one that close enough to my desired time and then I turn the others off and keep that one. You have to be patient. As long as you id the trigger by the function name in the log you can change the function and keep the timer going.
Oh and I generally created the log file with drive notepad and then open it up whenever I want to view the log.
function formsOnOff()
{
if(!isTrigger('openForm'))
{
ScriptApp.newTrigger('openForm').timeBased().atHour(7).create()
}
if(!isTrigger('closeForm'))
{
ScriptApp.newTrigger('closeForm').timeBased().atHour(11)
}
}
function isTrigger(funcName)
{
var r=false;
if(funcName)
{
var allTriggers=ScriptApp.getProjectTriggers();
var allHandlers=[];
for(var i=0;i<allTriggers.length;i++)
{
allHandlers.push(allTriggers[i].getHandlerFunction());
}
if(allHandlers.indexOf(funcName)>-1)
{
r=true;
}
}
return r;
}
I sometimes run a log entry on my timers so that I can figure out exactly when they're happening.
function logEntry(entry,file)
{
var file = (typeof(file) != 'undefined')?file:'eventlog.txt';
var entry = (typeof(entry) != 'undefined')?entry:'No entry string provided.';
if(entry)
{
var ts = Utilities.formatDate(new Date(), "GMT-6", "yyyy-MM-dd' 'hh:mm:ss a");
var s = ts + ' - ' + entry + '\n';
myUtilities.saveFile(s, file, true);//this is part of a library that I created. But any save file function will do as long as your appending.
}
}
This is my utilities save file function. You have to provide defaultfilename and datafolderid.
function saveFile(datstr,filename,append)
{
var append = (typeof(append) !== 'undefined')? append : false;
var filename = (typeof(filename) !== 'undefined')? filename : DefaultFileName;
var datstr = (typeof(datstr) !== 'undefined')? datstr : '';
var folderID = (typeof(folderID) !== 'undefined')? folderID : DataFolderID;
var fldr = DriveApp.getFolderById(folderID);
var file = fldr.getFilesByName(filename);
var targetFound = false;
while(file.hasNext())
{
var fi = file.next();
var target = fi.getName();
if(target == filename)
{
if(append)
{
datstr = fi.getBlob().getDataAsString() + datstr;
}
targetFound = true;
fi.setContent(datstr);
}
}
if(!targetFound)
{
var create = fldr.createFile(filename, datstr);
if(create)
{
targetFound = true;
}
}
return targetFound;
}
I make one window service in c#
to run exe on particular time., but it could open that exe,
Below is code
private static string checkdatentime()
{
currentdate = DateTime.Now;
string value = "1";
for (int i = 0; i < xml_date.Count; i++)
{
value = "2";
if (currentdate.Date < xml_date[i].Date)
{
value = "3";
break;
// go out side for loop;
}
else if (currentdate.Date > xml_date[i].Date)
{
value = "4";
//Do nothing means loops continues
}
else
{
value = "5";
//if both date are same
if (currentdate.Date == xml_date[i].Date)
{
value = "99";
currentTime = currentdate.ToString("hh:mm");
TriggerTime = newItem.TriggerTime.ToString("hh:mm");
if (currentTime == TriggerTime)
{
value = "6";
//Run EXE
System.Diagnostics.Process.Start("E:\\SqlBackup_Programs\\console-backup\\Backup_Console_App 22July Latest\\Backup_Console_App\\Backup_Console_App\\bin\\Debug\\Backup_Console_App");
return value;
}
}
}
}
return value;
}
NOTE: here I return value because to verify is my code runs correct or not and write VALUE on text file, so on same time I am getting VALUE=6, means there is no problem in code,
But still service cant open this exe,
by same code i made console application and its runs perfectly, so why not services??
Is this any problem with command,
System.Diagnostics.Process.Start();
kindly help me!!
I got the answer, I had checked the option "Allow to interact with the Desktop" in the Windows service properties
And now its Working