This is on Windows 7 and happens every day if I don’t start the Xamarin Bonjour service before Visual Studio and opening a Xamarin.iOS project. It’s not that big a deal but something must be switching the Xamarin Bonjour Service from Automatic. I set it to automatic a few times but it gets reset to Manual. Once it’s running it stays running for the rest of the day.

bonjour-initialization-failure


If you get this make sure the Bonjour Service is running. If it’s not, open the services MMC. You can do this from Task Manager but make sure on the Processes tab you click the Show processes from all users button as the service may not start. Then on the services Tab in Task Manager, at the bottom right then when the Services MMC opens scroll to the bottom. If you don’t see Started then right click on the service and click Start.

bonjour-service

Hopefully you should be able to select iPhone 6.1 in the combo box and all will be well. If not see this tip on Visual Studio to Mac Connectivity.

It’s not that difficult but there’s not an awful lot about it. I haven’t tried it with .MP3 files but what I’ve done works with .wav.

First create a project folder containing the sound files. Each file should be set to Content in the property/build Action.

sounds

Then define AvAudioPlayer to play the file. I created three in the class:

public static AVAudioPlayer [] player = new AVAudioPlayer[3];
private static int playIndex {get;set;}
....
       public static void PlaySound(string filename)
        {
            playIndex++;
            if (playIndex == 3)
            {
                playIndex = 0;
            }
            if (player[playIndex] != null)
            {
                player[playIndex].Stop();
            }
            try
            {
                var file = Path.Combine("sounds", filename);
                var Soundurl = NSUrl.FromFilename(file);
                player[playIndex] = AVAudioPlayer.FromUrl(Soundurl);
                var onePlay = player[playIndex];
                onePlay.CurrentTime = onePlay.Duration*2;
                onePlay.NumberOfLoops = 1;
                onePlay.Volume = 1.0f;
                onePlay.FinishedPlaying += DidFinishPlaying;
                onePlay.PrepareToPlay();
                onePlay.Play();
            }
            catch (Exception e)
            {
                LogLine("PlaySound: Error: " + e.Message, true);
            }
        }

        public static void DidFinishPlaying(object sender , AVStatusEventArgs e)
        {
            if (e.Status)
            {
                // your code
            }

        }

The playIndex int variable tracks which is the next AvAudioPlayer to be used. Note that the file must specify the directory used – my files are in sounds. The player[] variables exist at the class level not locally because you don’t want the garbage collector to zap them once it exits the PlaySound method.

The AVAudioPlayer.FinishedPlaying event handler (delegate in Apple’s terms) lets you catch when it finishes playing. The AvStatusEventArgs.Status is a bool indicating if it has finished.

Because in my App, two possibly three sounds could play simultaneously, I used three AvAudioPlayers. Without them, you have to stop the current sound playing.

I’m a software developer in London UK, creating Apps with Xamarin and these are my thoughts based on my day to day experiences developing with it. Need a contractor for Xamarin (offsite) or onsite in London or C#? Contact Me.

(August 2014)
I’m just coming up to complete my first App which uses multi-threading, TCP/IP and runs very responsively on an iPhone 4! It’s for Taxi drivers and uses a propietary packet protocol to talk to a server over a TCP/IP port.

It pops up a dialog saying do you want to update your help and if you view the Output then 447MB later of downloads (on the Mac), it starts updating. But next time you run Visual Studio the same thing happens?

It’s not you, it’s the version of the help is 6.0 even though you are on 6.1 (according to the Xamarin Bug Log).  The quick fix is to download the help manually.  As Xamarin engineer Jose Miguel Torres say in the bug report:

“Open XCOde and go to Xcode menu –> Preferences… Then click on Downloads tab and switch from components to Documentation.There should be the iOS 6.1 DocSet entry and the most probably is that it is not installed. Click on Check and Install button from the Xcode dialog and wait for the iOS 6.1 DocSet to be installed. ”

xcodefix

After that, you should see the Mac Server Log

[2013-09-01 10:22:44.2] Using https://developer.apple.com/rss/com.apple.adc.documentation.AppleiPhone6.1.atom
[2013-09-01 10:22:44.9] API Docs installed version: 44.30.0.0
[2013-09-01 10:22:44.9] API Docs official version: 44.30.0.0
[2013-09-01 10:22:44.9] Command [StatusSdk: CommmandUrl=StatusSdk] finished (9)

No more update requests.