I am trying to play sounds on a secondary soundcard using NAudio in a Unity project.
It works successfuly using the Play button in the editor, but not in the executable build.
Here is the error i get :
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Windows.Forms.Form..ctor () [0x00000] in <0b0c181c86c84da989ad80998d3a0a84>:0
at NAudio.Wave.WaveWindow.OnMdiChildActivate (System.EventArgs e) [0x00000] in <554b80148c284b99953f098db496ebd4>:0
at (wrapper remoting-invoke-with-check) NAudio.Wave.WaveWindow..ctor(NAudio.Wave.WaveInterop/WaveCallback)
at NAudio.Wave.WaveCallbackInfo.Connect (NAudio.Wave.WaveInterop+WaveCallback callback) [0x00009] in <554b80148c284b99953f098db496ebd4>:0
at NAudio.Wave.WaveOut..ctor (NAudio.Wave.WaveCallbackInfo callbackInfo) [0x0004e] in <554b80148c284b99953f098db496ebd4>:0
at NAudio.Wave.WaveOut..ctor () [0x00014] in <554b80148c284b99953f098db496ebd4>:0
at MainVideoScript.playSound (System.Int32 deviceNumber) [0x0002e] in <0d2c0b09fee74d5099fd910768d58ea9>:0
I am running on Windows 10, and the Target platform=Windows, so why the platform doesn't support what I am trying to do? What can I change?
Here is the code i am trying to run:
string soundPath = System.IO.Path.Combine(Application.streamingAssetsPath, #"clic2.wav");
waveReader = new NAudio.Wave.WaveFileReader(soundPath);
var wave = new NAudio.Wave.WaveOut();
wave.DeviceNumber = deviceNumber;
wave.Init(waveReader);
wave.Play();
I am using 2019.2.8f1
You need to make sure the Api compatibility Level is correct in Edit \ Project Settings \ Player
Related
I'm using Unity 2019.3.6f1. I have created a simple DLL for connecting to Azure and uploading a file. However, when I call this DLL to attemp connecting to the Azure blob storage I get the following stack trace:
NotImplementedException: The method or operation is not implemented.
System.Net.Http.HttpClientHandler.get_MaxConnectionsPerServer () (at
<7ebf3529ba0e4558a5fa1bc982aa8605>:0)
Azure.Core.Pipeline.ServicePointHelpers.SetLimits
(System.Net.Http.HttpMessageHandler messageHandler) (at
:0)
Azure.Core.Pipeline.HttpClientTransport.CreateDefaultClient () (at
:0)
Azure.Core.Pipeline.HttpClientTransport..ctor () (at
:0)
Azure.Core.Pipeline.HttpClientTransport..cctor () (at
:0) Rethrow as
TypeInitializationException: The type initializer for
'Azure.Core.Pipeline.HttpClientTransport' threw an exception.
Azure.Core.ClientOptions..ctor () (at
:0)
Azure.Storage.Blobs.BlobClientOptions..ctor
(Azure.Storage.Blobs.BlobClientOptions+ServiceVersion version) (at
:0)
Azure.Storage.Blobs.BlobServiceClient..ctor (System.String
connectionString, Azure.Storage.Blobs.BlobClientOptions options) (at
:0)
Azure.Storage.Blobs.BlobServiceClient..ctor (System.String
connectionString) (at :0)
Cineon.UnityToAzureConnection+d__1.MoveNext () (at
<5252723c79f94a8cb77bb25e3b9f0396>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () (at
<437ba245d8404784b9fbab9b439ac908>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0
(System.Object state) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at
:0)
UnityEngine.UnitySynchronizationContext:ExecuteTasks()
Here is my DLL code (in line with this Microsoft quickstart guide):
public class UnityToAzureConnection
{
private readonly static string m_connectionString = "CENSORED";
public static async void CreateConnection(string _path, string _fileName)
{
BlobServiceClient blobServiceClient = new BlobServiceClient(m_connectionString);
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync("imagetest");
BlobClient blobClient = containerClient.GetBlobClient(_fileName);
using (FileStream _fs = File.Open(Path.Combine(_path, _fileName), FileMode.Open))
{
await blobClient.UploadAsync(_fs, true);
}
}
}
I simply call this DLL's CreateConnection method and pass in my "Application.dataPath" and a filename. However, I then get the above exception.
I have pulled all other needed DLL's from the project build folder into the plugin folder, so am unsure why this is occuring.
Any assistance would be greatly appreciated.
Please note that I am just starting to move out of my comfort zone here, so I'm hoping that my post is to StackOverflow's standard of questions.
[P.S.] Obviously "CENSORED" isn't my actual connection string, just keeping sensitive info hidden.
UPDATE 29/05/2021 I have confirmed that my connection code DOES work when used in a simple .net console app (however, I did have to adjust the containername to be all lowercase). This error only occurs in Unity. Again, any and all help would be appreciated.
As I mentioned here, try it once.
If you have a lower version of Unity, Azure.Core ver. 1.19.0 may be better.
https://forum.unity.com/threads/attempting-to-connec-to-azure-blobs-results-in-notimplementedexception.1117705/
I have experienced the same exception in BlobServiceClient constructor in my mobile project.
The problem was in the version of Azure.Storage.Blobs package. I used the most recent version 12.12.0, and it caused the exception.
When I downgraded Azure.Storage.Blobs package to 12.9.1 all things worked fine.
Hello i am trying to build an windows store app in Unity3D(Unity 5.6.0f3).
When following these steps:
https://developer.microsoft.com/en-us/windows/mixed-reality/holograms_230
at the scanning step when you need to build the app i get the following 2 errors in unity:
==
Could not start compilationWin32Exception: ApplicationName='C:\Program Files\Unity\Editor\Data\Tools\Roslyn\CoreRun.exe', CommandLine='"C:\Program Files\Unity\Editor\Data\Tools\Roslyn\csc.exe" /noconfig #Temp/UnityTempFile-5ed7a9a146122744fb2017a810d85b49', CurrentDirectory=''
System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start ()
(wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
UnityEditor.Utils.Program.Start (System.EventHandler exitCallback) (at C:/buildslave/unity/build/Editor/Mono/Utils/Program.cs:44)
UnityEditor.Utils.Program.Start () (at C:/buildslave/unity/build/Editor/Mono/Utils/Program.cs:28)
UnityEditor.Scripting.Compilers.MicrosoftCSharpCompiler.StartCompilerImpl (System.Collections.Generic.List`1 arguments, System.String argsPrefix) (at C:/buildslave/unity/build/Editor/Mono/Scripting/Compilers/MicrosoftCSharpCompiler.cs:168)
UnityEditor.Scripting.Compilers.MicrosoftCSharpCompiler.StartCompiler () (at C:/buildslave/unity/build/Editor/Mono/Scripting/Compilers/MicrosoftCSharpCompiler.cs:190)
UnityEditor.Scripting.Compilers.ScriptCompilerBase.BeginCompiling () (at C:/buildslave/unity/build/Editor/Mono/Scripting/Compilers/ScriptCompilerBase.cs:40)
UnityEditor.HostView:OnGUI()
==
Error building Player because scripts have compile errors in the editor
==
Does somebody know the solution to this problem?
I'm trying to attach RestSharp to Unity3d.
Original RestSharp mono lib works fine in Editor, but on device its crashing with callstack
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: options
at System.Security.Cryptography.X509Certificates.X509CertificateCollection.GetEnumerator () [0x00000] in <filename unknown>:0
at System.Text.RegularExpressions.Regex.validate_options (RegexOptions options) [0x00000] in <filename unknown>:0
at System.Text.RegularExpressions.Regex..ctor (System.String pattern, RegexOptions options) [0x00000] in <filename unknown>:0
at RestSharp.RestClient..ctor () [0x00000] in <filename unknown>:0
at RestSharp.RestClient..ctor (System.String baseUrl) [0x00000] in <filename unknown>:0
That means, exception appears inside of ctor RestClient(string), which is a wrapper around default ctor. And inside of default ctor, there is
public RestClient()
{
#if WINDOWS_PHONE
this.UseSynchronizationContext = true;
#endif
this.ContentHandlers = new Dictionary<string, IDeserializer>();
this.AcceptTypes = new List<string>();
this.DefaultParameters = new List<Parameter>();
// register default handlers
this.AddHandler("application/json", new JsonDeserializer());
this.AddHandler("application/xml", new XmlDeserializer());
this.AddHandler("text/json", new JsonDeserializer());
this.AddHandler("text/x-json", new JsonDeserializer());
this.AddHandler("text/javascript", new JsonDeserializer());
this.AddHandler("text/xml", new XmlDeserializer());
this.AddHandler("*+json", new JsonDeserializer());
this.AddHandler("*+xml", new XmlDeserializer());
this.AddHandler("*", new XmlDeserializer());
this.FollowRedirects = true;
}
At this point, i dont see where next step with Regex ctor appears. Any ideas?
We have encountered the same issue while building a standalone Windows project with Unity 5.2.1. In the editor it all works fine, until you create a build.
I believe the problem has something to do with the 'structuredSyntaxSuffixWildcardRegex' used in the 'AddHandler' method. While I don't know exactly why it fails, I do know a previous version of RestSharp does work for us.
I guess you're also using the latest RestSharp version, so could you give RestSharp v105.1.0 a try?
It seemed to stop functioning from Restshap v105.2.1, I am going through the commits to see a possible culprit. I will fork and fix it if I have found a solution.
Also I must inform you that in our case GZIP decompression also wasn't working due to missing Mono.Posix libraries. This problem occurred when the server returned a gzipped response and the RestClient allowed it. We had to work around that by using 'Fabman08's fix which made decompression configurable.
I have forked the RestSharp repository in an attempt to fix the above and other Unity related issues. It's located at: https://github.com/eamonwoortman/RestSharp.Unity.
Your and other issues have already been fixed and were tested against a 64bit standalone Windows build.
Could you verify if these fixes also work on your iOS project? Make sure you build the RestSharp.Net35.Unity project.
If I run this code on the device, it returns "got it":
if (Directory.Exists (NSBundle.MainBundle.BundlePath + "/ARCSDev")) {
Console.WriteLine ("got it");
} else {
Console.WriteLine ("can't find it");
}
Which means the directory is in the main bundle.
I need to use that file in this method call:
private void generateChart (int chartNumber, string palette)
{
string filePath = NSBundle.MainBundle.BundlePath + "/ARCSDev";
Console.WriteLine("Filepath - " + filePath);
Loader loader = new Loader (filePath);
loader.LoadChart (Convert.ToString (chartNumber));
The above code works fine on the simulator, but not on the device.
I get the following stack trace when the error occurs on the device:
System.InvalidOperationException: Operation is not valid due to the current state of the object
at System.Linq.Enumerable.Max[TileIndexRecord] (IEnumerable`1 source, System.Func`2 selector) [0x00000] in <filename unknown>:0
at MyCompany.Data.Arcs.Loader.ExtractWriteableBitmap (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette, Double dpi, MyCompany.Data.Arcs.Raschts.ChartIndexFile indexFile, MyCompany.Data.Arcs.Raschts.RasterChartFile chartFile) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:571
at MyCompany.Data.Arcs.Loader.GetHiResImage (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:362
at ARCSViewer.SecondViewController.generateChart (Int32 chartNumber, System.String palette) [0x0004e] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:118
at ARCSViewer.SecondViewController.ViewDidAppear (Boolean animated) [0x00007] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:84
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at ARCSViewer.Application.Main (System.String[] args) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Main.cs:17
The directory contains unix executable files and radiance files.
Can anyone explain whats going on? The file is definitely in the right place (the bundle) as I've tested the code that checks for existence with other files that I know to be there as well..
It might be an issue of case sensitivity, the simulator is case-insensitive while the device is case sensitive. Check your files to see if you're accessing all of them with the right case (i.e. not only the directory).
The permissions on the devices are very different (far more restricted) from the simulator. There's a lot of place you do not have access for various reasons (e.g. changing some files would break the application digital signature which would disallow your application from running anymore).
Also if your application does not follow Apple guidelines on where (and when) to store data your application will be rejected (if you target the appstore).
There's a nice article from Xamarin on how to work with the iOS file system.
I solved the problem, several parts of my application use code like below:
fs = new FileStream(fileName, FileMode.Open);
I needed to change every occurrence of FileStream() to the following:
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
As my files are in the bundle and don't need to make use of write operations, this limits the file stream to only read operations and allowed the files to be read in properly.
Whenever I try to create a new audio context in monodroid, it fallls over telling me that openal32.dll is missing; which naturally doesn't make sense, being as this is monodroid, and openal is included as part of OpenTK.
I can only assume i'm doing something wrong, but i've used OpenTK/OpenAL before under windows and have managed just fine with similar code.
anyway here is the offending code:
public Audio()
{
if (Loaded == false)
{
Loaded = true;
try
{
try {Console.WriteLine ("Current: " + AudioContext.CurrentContext.ToString());} catch { Console.WriteLine ("no current context"); }
try {Console.WriteLine ("Default: " + AudioContext.DefaultDevice);} catch { Console.WriteLine ("no default device"); }
Context = new AudioContext();
ValidContext = true; //we have a valid audio context!
}
catch (Exception ex)
{
Console.WriteLine ("Loading the audio context failed.");
Console.WriteLine (ex.ToString ());
Console.WriteLine (ex.Message);
ValidContext = false; //Loading the audio context failed :(
}
}
}
And here is the output:
I/monodroid-gc(24762): environment supports jni NewWeakGlobalRef
D/AndroidGameView(24762): SurfaceCreated
D/libEGL (24762): egl.cfg not found, using default config
D/libEGL (24762): loaded /system/lib/egl/libGLES_android.so
I/mono-stdout(24762): no current context
I/mono-stdout(24762): no default device
I/mono-stdout(24762): Loading the audio context failed.
I/mono-stdout(24762): System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Audio.AudioContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for OpenTK.Audio.AudioDeviceEnumerator ---> System.DllNotFoundException: openal32.dll
I/mono-stdout(24762): at (wrapper managed-to-native) OpenTK.Audio.OpenAL.Alc:MakeContextCurrent (intptr)
I/mono-stdout(24762): at OpenTK.Audio.OpenAL.Alc.MakeContextCurrent (ContextHandle context) [0x00000] in <filename unknown>:0
I/mono-stdout(24762): at OpenTK.Audio.AudioDeviceEnumerator..cctor () [0x00000] in <filename unknown>:0
I/mono-stdout(24762): --- End of inner exception stack trace ---
I/mono-stdout(24762): at OpenTK.Audio.AudioContext..cctor () [0x00000] in <filename unknown>:0
I/mono-stdout(24762): --- End of inner exception stack trace ---
I/mono-stdout(24762): at Hardware.Audio..ctor () [0x00000] in <filename unknown>:0
I/mono-stdout(24762): An exception was thrown by the type initializer for OpenTK.Audio.AudioContext
I/ARMAssembler(24762): generated scanline__00000177:03545444_00009001_00000000 [159 ipp] (215 ins) at [0x4fc138:0x4fc494] in 4168381 ns
openal32.dll is not included as part of OpenTK. OpenTK just has bindings for OpenAL. Just like opengl32.dll, which is included as part of your graphics card drivers, openal32.dll must be installed through audio card drivers (or a software implementation of it).
After a quick search, it looks like you need to compile a software implementation of OpenAL for Android: http://pielot.org/2010/12/14/openal-on-android/
Edit: It looks like Android prefers to use the newer OpenSL ES. If you've got a bit of time on your hands, you could try to get OpenTK's generator to generate OpenSL ES bindings for you.
This other StackOverflow question has a few other options for using OpenSL.