Write me a simple Xamarin app that will give me a message on a screen if an iOS phone ringer is on and if the sound is a low volume or not
Budget: $10 – $30 USD
Just need a modified version of the New Project > Multiplatform > Blank app, that will check the phone's ringer and see if it's on and if the sound is turned up. Only working solutions will be accepted for the award.
Here is the code I currently have. I just need a person to check into it and get it working:
using System;
using System.Threading.Tasks;
using AudioToolbox;
using AVFoundation;
using Foundation;
using Test.Interfaces;
using Test.iOS;
[assembly: Xamarin.Forms.Dependency(typeof(SoundMethods))]
namespace Test.iOS
{
public class SoundMethods : ISoundMethods
{
public async Task<string> IsDeviceSilent()
{
AVAudioSession.SharedInstance().SetActive(true);
var outputVolume = AVAudioSession.SharedInstance().OutputVolume;
if ((int)(outputVolume * 100) == 0)
return "Phone volume is set to silent. Please adjust volume higher if you want the phrases and meanings to be read aloud.";
else if (outputVolume * 100 < 30)
return "Phone volume set low. Please adjust volume higher if you want the phrases and meanings to be read aloud.";
var soundFilePath = NSBundle.MainBundle.PathForResource("Audio/mute", "caf");
var sound = new SystemSound(new NSUrl(soundFilePath, false));
DateTime startTime = DateTime.Now;
var silentText = "";
sound.AddSystemSoundCompletion(async () =>
{
var endTime = DateTime.Now;
var timeDelta = (endTime - startTime).Milliseconds;
if (timeDelta < 120)
{
silentText = "Silent Mode On. Please turn off the Silent Mode switch at the top left side of the phone if you want to listen to the phrases and meanings using the phone speaker.";
}
else {
silentText = "";
}
});
sound.PlaySystemSound();
await Task.Delay(500);
return silentText;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Test.Interfaces
{
public interface ISoundMethods
{
// void ShowToast(string msg);
// string GetIdentifier();
Task<string> IsDeviceSilent();
}
}
Here is the code I currently have. I just need a person to check into it and get it working:
using System;
using System.Threading.Tasks;
using AudioToolbox;
using AVFoundation;
using Foundation;
using Test.Interfaces;
using Test.iOS;
[assembly: Xamarin.Forms.Dependency(typeof(SoundMethods))]
namespace Test.iOS
{
public class SoundMethods : ISoundMethods
{
public async Task<string> IsDeviceSilent()
{
AVAudioSession.SharedInstance().SetActive(true);
var outputVolume = AVAudioSession.SharedInstance().OutputVolume;
if ((int)(outputVolume * 100) == 0)
return "Phone volume is set to silent. Please adjust volume higher if you want the phrases and meanings to be read aloud.";
else if (outputVolume * 100 < 30)
return "Phone volume set low. Please adjust volume higher if you want the phrases and meanings to be read aloud.";
var soundFilePath = NSBundle.MainBundle.PathForResource("Audio/mute", "caf");
var sound = new SystemSound(new NSUrl(soundFilePath, false));
DateTime startTime = DateTime.Now;
var silentText = "";
sound.AddSystemSoundCompletion(async () =>
{
var endTime = DateTime.Now;
var timeDelta = (endTime - startTime).Milliseconds;
if (timeDelta < 120)
{
silentText = "Silent Mode On. Please turn off the Silent Mode switch at the top left side of the phone if you want to listen to the phrases and meanings using the phone speaker.";
}
else {
silentText = "";
}
});
sound.PlaySystemSound();
await Task.Delay(500);
return silentText;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Test.Interfaces
{
public interface ISoundMethods
{
// void ShowToast(string msg);
// string GetIdentifier();
Task<string> IsDeviceSilent();
}
}