Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
The following code fails (audioPlayer == null) but returns an null error (loadError == null).
audioPlayer = AVAudioPlayer.FromUrl(new NSUrl(validParthToTheMusic), out loadError);
After having looked carefully to the sample I found the problem. By adding 'false' to the second argument of NSUrl constructor it works properly (audioPlayer == null and loadError != null or audioPlayer != null and loadError == null).
audioPlayer = AVAudioPlayer.FromUrl(new NSUrl(validParthToTheMusic, false), out loadError);
Can you give us an example of the value for `validParthToTheMusic` ?
And where's the file it load is actually located ?
Sorry for the lack of precision, after a check the bug seems to happen only on the iPhoneSimulator.
My file is loaded as Content.
Here is an example of path:
/Users/pierre/Library/Application Support/iPhone Simulator/6.1/Applications/16A89A50-94EE-4CAF-A4EF-B56B8DD54ED7/AudioTestsiOS.app/app_data/assets/audio/ae.wav"
My guess* is that your `NSUrl` instance is invalid, i.e. it's handle property is 0x0 (IntPtr.Zero). E.g.
string file = Path.Combine (NSBundle.MainBundle.ResourcePath, "Hand.wav");
on iOS devices, while it returns:
"/Users/poupou/Library/Application Support/iPhone Simulator/6.1/Applications/81F5B81E-B279-416D-BB63-671FB8B407FF/monotouchtest.app/Hand.wav"
on the iOS simulator.
The first one can be used with `initWithString:` (native), which is `NSUrl(string)` while the second can not.
Using `NSUrl(string,bool)` calls `initFileURLWithPath:isDirectory:` which works in both case (note the difference between initWith*String* and init*WithPath*).
So what this means it that you're effectively calling `initWithContentsOfURL:error:` (AVAudioPlayer.FromUrl) with a null `NSUrl` which is not allowed (and undefined). Sadly it looks like the native returns `nil` without setting the `NSError` parameter to anything useful.
* I can duplicate something like this (even if I can't be sure it's 100% identical to yours).
c.c. Larry for updating documentation (based on above). Note that  is currently bad.
Note that `Class.ThrowOnInitFailure` which should check for `Handle == IntPtr.Zero`, does not work in this case. I filled bug #14399 about it.
Documentation updated in 5a5880ae920dfac98d58fb6f5246de912165bdd7