I'm trying to play a simple beep sound in my playbook application when a countdown expires. I manage to get the countdown to work correctly and but I can't get my sound to work.
This is how i'm playing my sound.
[Embed(source="sounds/beep.mp3")] private var CustomSound:Class;
...
...
...
var sound : Sound = new CustomSound() as Sound;
sound.play();
If it is only a beep sound, you could do the following:
// play some sound
var fx:AudioEffectsManager = new AudioEffectsManager();
fx.play(AudioEffect.ALARM_BATTERY);
just replace the
AudioEffect.ALARM_BATTERY
by the sound of your choice.
Related
I have I have been wasting at least a day trying to make this work. I am trying to play an mp3 file that i placed in Resources/raw once a notification is received. I do not know exactly how to get the Uri. My questions please are:
1.To play a custom file do you have to place it in Resources/raw or can it be also in Assets/Sounds under the Xamarin Android project.
2.How do i get the Uri correctly based on where the mp3 file resides.
This is my code:
private void createNotificationChannel()
{
var channelName = GetString(Resource.String.noti_chan_urgent);
var channelDescription = GetString(Resource.String.noti_chan_urgent_description);
// set the vibration patterm for the channel
long[] vibrationPattern = { 100, 200, 300, 400, 500, 400, 300, 200, 400 };
// Creating an Audio Attribute
var alarmAttributes = new AudioAttributes.Builder().SetUsage(AudioUsageKind.Alarm).Build();
// Create the uri for the alarm file
var alarmUri = Android.Net.Uri.Parse("MyApp.Android/Resources/raw/alarm.mp3"); // this must be wrong because its not working
// create chan1 which is the urgent notifications channel
var chan1 = new NotificationChannel(PRIMARY_CHANNEL_ID, channelName, NotificationImportance.High)
{
Description = channelDescription
};
// set the channel properties
chan1.EnableLights(true);
chan1.LightColor = Color.Red;
chan1.EnableVibration(true);
chan1.SetVibrationPattern(vibrationPattern);
chan1.SetSound(alarmUri, alarmAttributes);
chan1.SetBypassDnd(true);
chan1.LockscreenVisibility = NotificationVisibility.Public;
var manager = (NotificationManager)GetSystemService(NotificationService);
manager.CreateNotificationChannel(chan1);
}
}
I figured it out and I hope this will help someone better than getting a downvote for a question, this is how you do it:
(Note: Make sure you put your mp3 file in your Xamarin Android project under Resources/raw/soundFile.mp3 and build the file as Android Resource).
Then create the Uri like this:
Android.Net.Uri alarmUri = Android.Net.Uri.Parse(${ContentResolver.SchemeAndroidResource}://{Context.PackageName}/{Resource.Raw.soundFile}");
Create the Alarm Attributes like this:
var alarmAttributes = new AudioAttributes.Builder()
.SetContentType(AudioContentType.Sonification)
.SetUsage(AudioUsageKind.Notification).Build();
And finally setSound on the channel itself ONLY from Android Oreo onwards (not on the notification, create the channel at application launch):
chan1.SetSound (alarmUri, alarmAttributes);
uri = Android.Net.Uri.Parse(
"android.resource://" + Application.Context.PackageName + "/raw/sound2");
only change I had to make. to Fredsomofspeech answer.
android 9.
visualstudio 2019 xamarin.forms mobile ios android. sound2.mp3
was running a file android could not play, so make sure download a mp3 file for testing verified to work.
I was wondering if it is possible to programmatically change the default notification sound on an Android phone based on what time it is. For instance, I would like the default notification sound to change to Silent after 11PM and then back to a sound at 8AM. I have a working knowledge of Java, but have never done any Android development. Thanks in advance for any help.
Without going too much into detail, I would approach this problem by first creating an AlarmService which will run periodically and change default Ringtone according to your desired time of the day via RingtoneManager
AlarmManager setting up periodical invocations of "RingToneChanger.class" , something like this:
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute
Then within triggered RingToneChanger.class, ringtone can be changed like this:
if(isNoon) {
RingtoneManager.setActualDefaultRingtoneUri(Context context, RingtoneManager. TYPE_NOTIFICATION , Uri lunchtimeNotificationSound);
} else {
RingtoneManager.setActualDefaultRingtoneUri(Context context, RingtoneManager. TYPE_NOTIFICATION , Uri defaultNotificationsound);
}
Hope it helps. else please don't hesitate to ask.
I'm building an AIR application. Basically, what I'm looking to do is using navigateToUrl() to open a browser window, assign it a "name" and then, send variables to that newly opened window using the POST method.
EDIT : I need the window to be visible, this is why I absolutely need to use the navigateToUrl() function
I already know that I CAN'T DO something like this, that the AIR application will send the variables using the GET method...
var vars:URLVariables = new URLVariables();
vars.myVar = "Hello my friend";
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
req.method = "POST":
req.data = vars;
navigateToURL(req);
Considering the amount of variables I have to send (multiline texts) I absolutely need to send my variables using the POST method else Internet Explorer is truncating the query string... Works fine in Firefox and Safari but unfortunately, we will always have (hope not!) to deal with IE..
So I was thinking something like this :
import flash.net.navigateToURL;
private var _timer:Timer;
protected function loadPage():void
{
var req:URLRequest = new URLRequest("http://example.com/my-page.php");
navigateToURL(req, "myPageName");
_timer = new Timer(3000, 1);
_timer.addEventListener(TimerEvent.TIMER, postVars);
_timer.start();
}
protected function postVars(event:TimerEvent):void
{
// I'm looking to send variables using the POST method to "myPageName"
// and possibly using URLVariables()??
_timer.stop();
}
Any idea Flex coders? THANKS!
I think what you're going to need to do is open up a page you have control over, then use ExternalInterface to inject the values into a hidden form and then execute the post operation in that page form.submit(), etc.
This can happen almost instantly and it will all appear very seamless to the end user.
I'm making a audio recorder with Adobe Flex (Microphone, NetStream), I want to get the current audio wave from Microphone to display in the visualization area, any idea how can i get the data?
You'll need to be using Flash Player 10 as I think that's the first time you actually got access to to the Microphone apis.
Then there's a simple function you can call which will get the microphone data:
private var soundBytes:ByteArray = new ByteArray;
SoundMixer.computeSpectrum(soundBytes, false);
I usually call the computeSpectrum code in an enter frame handler and draw out the wave form from there.
Edit: I don't want to mislead you. I think the above code is for a pre-recorded audio file. If you want to user the microphone in flash 10. You do it like this:
private var _mic:Microphone;
_mid = Microphone.getMicrophone();
_mic.addEventListener( SampleDataEvent.SAMPLE_DATA, onSampleData );
protected function onSampleData( event:SampleDataEvent ):void {
while( event.data.bytesAvailable ){
var n:Number = event.data.readFloat();
}
}
I am trying to build a flash player for my company's Shoutcast server, and have seen a few articles about it on the 'net, including this SO question here.
However, I can't seem to get the audio stream to actually play. It seems to be connecting alright, but calling stream.play() doesn't seem to do anything.
I have tried the code in the SO question I have linked to, and have also tried something similar to this (sorry i don't remember the exact syntax):
public function stream() {
private var url:URLREQUEST = "my.domain.com";
private var sStream:Sound = new Sound();
sStream.load(url);
sStream.play();
}
If anyone has any revelations for me I'd appreciate it.
I just posted a solution on this thread:
How to stream a shoutcast radio broadcast in Flash (Shoutcast Flash Player)
Did you try this - (corrected some typos in the code you posted)?
public function stream()
{
private var url:URLRequest = new URLRequest("my.domain.com/song.mp3");
private var sStream:Sound = new Sound();
sStream.load(url);
sStream.play();
}