XNA SoundEffect fails to be loaded from file - xna

I got a dictionary to store SoundEffects in, like:
public static Dictionary<string, SoundEffect> Hangok = new Dictionary<string, SoundEffect>();
I load sounds from files (normal .wav format), like:
GStatic.Hangok.Add(Azonosító, SoundEffect.FromStream(File.OpenRead(Azonosító)));
, where Azonosító was the filename.
All is just fine, files are loaded, except one; an exception is created:
Operation is not valid due to the current state of the object.
, what is not much of information for me. Could anyone explain this error message OR tell me why SoundEffect.FromStream fails to read? Why? When? Workaround?
Thanks in advance:
Péter

I use the ContentManager to load in SoundEffect's. Place the wav file in the content project and it should just load in.
E.g.
SoundEffect s = Content.Load<SoundEffect>("name");

Not a complete, but working solution to this problem. "Answering my question" only, because it may be useful for other developers, who also have no idea what the problem may be.
try
{
GStatic.Hangok.Add(Azonosító, SoundEffect.FromStream(File.OpenRead(Azonosító)));
}
catch
{
GStatic.Hangok.Add(Azonosító, new SoundEffect(File.ReadAllBytes(Azonosító), 11025, AudioChannels.Mono));
}
And well: I got no idea WHY you can not load that file in the normal way and why you can load the way like in the exception handler. Having a file in mono should not be that big problem. If someone knows, please drop a note/comment.

Related

Sentry error - IndexSizeError: The index is not in the allowed range

I am getting this error from Sentry repetitively in ios - safari 14.0 in react project.
There is no code trace and no other information than this but it repeats in almost every URL.
I have already searched for the options everywhere. I have tried debugging but I can't replicate it, and so I can't resolve it.
Does anyone know what does this error means? Or how can I add debug information in Sentry?
I have been looking for the solution for a while and couldn't get it. I know it's a bit lack of information to provide but that's why I am asking this. if someone can tell me how to deal with sentry errors if you don't know why it is repeating so often, it will be really helpful.
A similar issue still exists.
Faced this in Safari when Draft.js is updating the editor state.
The error which I see: IndexSizeError: The index is not in the allowed range.
For me, playing around with Paragraph Directioncontext menus items after right-clicking on the Editor selection reproduced the error.
My Solution/hack:
Add it to any JS file executing before the Editor file.
const nativeSelectionExtend = Selection.prototype.extend;
Selection.prototype.extend = function (...args) {
try {
return nativeSelectionExtend.apply(this, args);
} catch (error) {
console.log('Selection error.', error);
}
};
It works properly for me. Maybe will be useful for somebody as well.
Thanks to https://github.com/shpakkdv

Swift 4 app crashes when open file from icloud

I have a problem that my app crashes when it is opening a file from iCloud. If I open this file from my app with a Document Picker, everything is fine. But if I try to open from outside my app, for example from iCloud or safari download it crashes. If I open it from local storage "my iphone" it is also working. It is interesting because it was good one week ago :)
So in AppDelegate, I've implemented the following method:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {}
According to the logs the crash occurs because the file does not exist.
file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/Desktop/twic1121.pgn
This is the result if I print the URL from the parameter. I think this means that the file is there.
But if i do this: print(fm.fileExists(atPath: url.path)) then this is false.
So it is obvious that after let dataFromFile = fm.contents(atPath: url.path)
this is nil.
I have no idea what could be the problem here. So the real question here is why this is nil?
It appears that the error can be many things, all not related to the class you are applying the code (AppDelegate) nor the methods you are calling.
My guess is that the URL you are calling is not correctly built (not pointing to the correct object you are trying to point to). For many reasons.
See if one of this reasons fix your issue:
(1) The end of the URL you are calling had the suffix "pgn". If you are looking to load a picture, maybe the suffix is wrong. In that case it could have been some known and supported format like "png", "jpeg" or "jpg".
(2) The "%20"symbol at the middle of your code also lifts a flag. Does not seem to be a correct URL object of swift. Maybe the URL you are using is not represented in the correct way.
(3) com~apple~CloudDocs also lifts a flag, since it would unlikely have a "~" symbol in a URL passed. This also strongly suggests that maybe the URL you are using is not represented in the correct way.
I think your URL is not pointing to where you are trying to point to, resulting in the "does exist" method return false and the loading resulting in nil.
If all of this does not fix your issue, post more details of the code. Specially what method you are calling to build/create this URL object you are using, that points to: file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/Desktop/twic1121.pgn

Sound Effect Won't Play (XCode/Swift)

So I am following through an old tutorial and I think with the changes in xcode and swift this code is now no longer usable, but i am not sure. Would love some help.
Declaring constant for the audio effect
let cannonSound = SKAction.playSoundFileNamed("cannon.wav", waitForCompletion: false)
Calling the audio effect within my funtion
let hotdogSequence = SKAction.sequence([cannonSound, moveHotdog, deleteHotdog])
hotdog.run(hotdogSequence)
For more info I am using SpriteKit in Xcode and this code is contained within GameScene.swift file.
Update:
The error I receive is
2017-03-30 00:52:43.631 Ballpark Weiner[95999:1983181] SKAction: Error loading sound resource: "cannon.wav"
The game doesn't crash just no sound plays
This message usually means that the file cannot be found in your project or might be corrupt.
You should check that the file is actually copied into your project and is spelled correctly. Its case sensitive so if the actual file is called "Cannon.wav" it will not work.
Hope this helps

Using reopened standard file descriptors in an iOS app with background capabilities?

I would like to be able to redirect my logging statements to a file so that I can retrieve them when my app runs standalone (i.e. is not attached to Xcode). I have discovered (thank you Stackoverflow) that freopen can be used to accomplish this.
If I create a new Xcode project and add the code to redirect stderr then everything works as expected.
However, when I add the redirection code to my existing, bluetooth project I am having trouble. The file is being created and I can retrieve it using iTunes or Xcode's Devices window, but it is of size 0. If I explicitly close the file then the text that I wrote actually makes it into the file. It is as though iOS is not flushing the file when the app is terminated. I suspect that the trouble stems from the fact that I have enabled background processing. Can anyone help me to understand this?
Here is my code:
let pathes = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true);
let filePath = NSURL(fileURLWithPath: pathes[0]).URLByAppendingPathComponent("Test.log")
freopen(filePath.path!, "a", stderr);
fputs("Hello, Samantha!\r\n", stderr);
struct StderrOutputStream: OutputStreamType {
static let stream = StderrOutputStream()
func write(string: String) {fputs(string, stderr)}
}
var errStream = StderrOutputStream.stream
print("Hello, Robert", toStream: &errStream)
fclose(stderr) // Without this the text does not make it into the file.
I'd leave this as a comment, but have you looked into NSFileHandle? It sounds like you just need a way to append data to the end of a text file, correct?
Once you have a handle with something like NSFileHandle(forWritingToURL:), you can use .seekToEndOfFile() and .writeData(_:). As a side note, you'll need to convert your String to Data before writing it.
Admittedly, this will probably end up being more lines of code, and you'll almost certainly need to take threading into consideration.

Is it possible to save a mp3 file downloaded from server without converting it to ByteArray? (AS3)

After searching around the net, I couldn't find a method to download a mp3 from a server, save it in the local storage (iPad) and then load and play it other than converting it to byteArray, saving it as .mp3 and then load it and read it back to mp3 to be able to play it in the flash application.
The problem is, although this method works fine, the uncompressed files (in byteArray format) saved in the local storage are too heavy and I suspect that the app is wasting memory.
My question is, is there any form of saving the mp3 directly, without any conversion, like a properly playable mp3? I can't use methods like download() or save() from FileReference.
Lots of thanks!!
SOLUTION!! (WORKING PERFECTLY):
I continued looking for a method to do it around the net, and some forums gave me a clue to do whick I was searching. It was finally pretty simple, but I spent almost 2 weeks to find it out... here is my code:
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
queue.append( new DataLoader("http://" + **url**, {name:**"example.mp3"**format:"binay"}));
queue.load();
// Complete Event:
private function completeHandler():void {
var file:File = new File(**your location**); // appData
var fr:FileStream = new FileStream();
fr.open(file.resolvePath(nameIn), FileMode.WRITE);
fr.writeObject(LoaderMax.getContent("example.mp3"));
fr.close();
fr = null;
// Now the mp3 is saved in local storage, we load it as Sound object so we can play it.
var loader:MP3Loader;
loader = new MP3Loader(**your location**, {autoPlay:false}) ;
loader.addEventListener(Event.COMPLETE, function():Sound {
loader.content.play(); // This line is the only one not checked, but I am completely sure you can do something like this to play the sound. For example, I introduce the loader.content in a Array of Sound and later I am capable to play any sound I want.
loader.dispose(true); // This is very important to free memory. You should do the same thing with queue when all items are downloaded.
});
loader.load();
}
I expect this help a lot of people!!

Resources