I'm using Xamarin-Forms-Labs ISoundService in Xamarin to play audio in a Timer.
Every 30 seconds I have it play an audio file (each file is different)
I can get it to play subsequent files if the file size is small (less than 5k) but if it larger is keeps replaying the "larger audio" file in place of the subsequent clips.
Any thoughts how I can resolve this? Am I "stopping" the audio properly. Should I async stop since it is async play?
I appreciate the time and expertise
Xamarin-Forms-Labs ISoundService
https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Platform/XLabs.Platform/Services/Media/ISoundService.cs
My code
var audioFile = intervalSettingsAudioDict[currentInterval];
Console.WriteLine(audioFile);
soundService = DependencyService.Get<ISoundService>();
if (soundService.IsPlaying){
soundService.Stop();
}
soundService.Volume = 1.0;
soundService.PlayAsync(audioFile);
I think the problem is that the default behavior of DependencyService.Get() is to act as a Singleton: http://forums.xamarin.com/discussion/22174/is-a-dependencyservice-implementation-class-treated-as-a-singleton.
I solved it using the following:
var SoundService = DependencyService.Get<ISoundService>(DependencyFetchTarget.NewInstance);
This worked on iOS, but I'm still troubleshooting an unrelated problem on Android.
HTH.
Related
I am using AudioKit in my project. By using the process suggested in the mixing nodes playground example, I am playing the multiple audios. My requirement is to upload the mixed audio to the server and displayed and played some other screens. I followed this suggestion. How to get and save the mixed of multiple audios in to single audio in swift but it's not working.
Give suggestions to get the mixed audio output for uploading to the server.
AudioKit provides a node recorder that can be attached to any node in your signal chain (though it seems to prefer being connected to mixer nodes).
First set up a place for the recording to be kept:
let file = try AKAudioFile()
Then assign a recorder to record to that file
let recorder = try AKNodeRecorder(node: nodeYouWantToRecord, file: file)
Start recording:
try recorder.record()
Stop recording at a later time:
recorder.stop()
Then save your file:
file.exportAsynchronously(name: "nameString",
baseDir: .documents,
exportFormat: .caf) { [weak self] _, _ in
// optional do something after exporting
}
Check out how this playground saves the AudioKit output: https://audiokit.io/playgrounds/Basics/Mixing%20Nodes/
I have an application using AVFoundation that plays use an mp3 sound file as a sound effect. It's recorded length is 90 seconds long. However, I play it repeatedly, on and off dependant upon varying things, for different lengths of time by utilising the tickingSounds.play() and tickingSounds.stop(). It seems however once I get to 90 seconds that it won't play anymore. I am assuming the play() command resumes from where I last stopped it?
My question is how do I reset it play position or am I missing something else?
You should set:
numberOfLoops
Set the Property numberOfLoops to -1 and it would go into infinite loop.
numberOfLoops
The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.
#property NSInteger numberOfLoops Discussion A value of 0, which is the default, means to play the sound once. Set a positive integer value to specify the number of times to return to the start and play again. For example, specifying a value of 1 results in a total of two plays of the sound. Set any negative integer value to loop the sound indefinitely until you call the stop method.
Availability Available in iOS 2.2 and later. Declared In AVAudioPlayer.h
I am using processing to play image sequences (amongst other stuff) and have an issue in that when the image sequences are too big or I have too many loading at sketch startup I run out of memory (even after tweaking settings). If there is a way round the above where I can load everything on sketch startup that would be ideal however I have come to the conclusion this is not possible meaning I will have to load items before I used them.
This takes some time (around 8 seconds) and I would like to play a loading video or similar whilst this is going on.
Is there anyway to do this? At the moment the whole sketch just freezes while the app cycles the for loop loading the new image sequence and then continues. Starting a video just before does not work as it simple freezes because Draw() is no longer looping.
Tiny bit of my code below.
//loadRed
void loadRed() {
for (int i = 0; i < numFrames; i += 2) {
String imageName = "f1red"+ nf(i, 4) + ".jpg";
images[i] = loadImage(imageName);
println("Loading - " + imageName);
}
}
Any help is appreciated. Will
Have found a solution to this so going to link here hopefully might help somebody out in the future!
http://processing.org/tutorials/data/
Scroll down to Threads and this will allow asynchronous functions to run.
Hope this helps someone. Will
I am using an external soundfont to play MusicStrings and everything is working find. When I use player.saveMidi(etc, etc) the files are saved with the original MIDI soundfont.
Soundbank soundbank = MidiSystem.getSoundbank(new File("SGM-V2.01.sf2"));
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
synth.loadAllInstruments(soundbank);
Player player = new Player(synth);
Pattern pattern = new Pattern("C5majw C5majw C5majw");
player.play(pattern); // works fine with external soundbank
player.saveMidi(pattern, filename); //Doesn't save with external soundbank instruments
Is there any workaround or built in feature that supports this functionality?
Thanks!
Keep in mind that MIDI is a set of musical instructions. Regardless of whether you load a soundbank into the Java program, when you save as MIDI, you're only saving musical instructions. (By "musical instructions", I mean things like "NOTE ON" or "INSTRUMENT CHANGE" but not actual musical sound data)
It sounds like what you want to do is render your music into a WAV file using the sounds from the soundbank that you have loaded. To do this, you'll want to use the Midi2WavRenderer available here: http://www.jfugue.org/code/Midi2WavRenderer.java
I'd like to be able to open a file on Windows Phone 7, in an XNA game, without reading the entire file into memory. I'm trying to stream audio from WAV files, to be passed to DynamicSoundEffectInstance for playback.
The method I have now uses TitleContainer.OpenStream() to open the WAV file, and then reads it on a background thread using ThreadPool.QueueUserWorkItem(). However, this causes a hitch at the beginning, and today I verified that TitleContainer.OpenStream() returns a MS.Internal.InternalMemoryStream object, which would suggest that it's reading the entire file into memory in OpenStream().
This is corroborated by the fact that it seems to take effectively no time (or, only a memcpy()'s worth of time) to do the Read(), and that Stream.BeginRead() (which is included on WP7 as part of the Async CTP) calls its callback before returning.
Is there any way to open a file on WP7 XNA without reading the entire thing into memory? If not, this is completely ridiculous.
There does not appear to be a way to do this. However, since I know the size of the chunks I want to read (32kB), I can split the files into chunks offline and read them one chunk at a time.