Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Cannot add sound source, it exists already:

muchiachio
Registered User
Quote
2013-05-16 20:40:22

Hello everyone,

I'm trying to load same audio path and name to ISoundSource and I always get "Cannot add sound source, it exists already: [My-Audio-Name]"
And I don't want to have a counter for unique numbers in AddSoundSourceFromIOStream method, one of the reasons is "Unknown wave header file".

Here is the code:

Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
ISoundSource source = engine.AddSoundSourceFromIOStream(stream, path);
source.StreamMode = StreamMode.AutoDetect;

engine.Play2D(source, false, false, true);
engine.Play2D(source, false, false, true); // Error

// This is working, but its not using my stream, and using Factory is not a good idea for me, unless it can be overriden by different sounds paths
// engine.Play2D(path);
// engine.Play2D(path);


Any help would be appreciated


niko
Moderator
Quote
2013-05-18 07:07:28

When you use the same stream instance to play the same file streaming multiple times, this will only work when you are lucky, because of course it is physically not possible to read and seek in a file using the same instance of a file stream more than once at the same time. File positions will not be correct after the streams get out of sync.


muchiachio
Registered User
Quote
2013-05-18 09:06:08

It's not about the stream instance. I used it as an example and I understand that it can not play the same stream. It's about IrrKlang not being able to have same sound name. Maybe this code snippet will be more helpful to see where I'm coming from.


FileStream streamOne = new FileStream(mp3AudioPath, FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream streamTwo = new FileStream(mp3AudioPath, FileMode.Open, FileAccess.Read, FileShare.Read);

if (streamOne.Equals(streamTwo))
Console.WriteLine("Streams are equal");
else
{
Console.WriteLine("Streams are not equal");

ISoundSource sourceOne = engine.AddSoundSourceFromIOStream(streamOne, mp3AudioPath);
ISoundSource sourceTwo = engine.AddSoundSourceFromIOStream(streamTwo, mp3AudioPath); // Error, not because streams are the same but because mp3AudioPath is the same.

engine.Play2D(sourceOne, false, false, false);
Thread.Sleep(3000);
engine.Play2D(sourceTwo, false, false, false); // Does not play because sourceTwo is null
}



FileStream streamOne = new FileStream(mp3AudioPath, FileMode.Open, FileAccess.Read, FileShare.Read);
FileStream streamTwo = new FileStream(mp3AudioPath, FileMode.Open, FileAccess.Read, FileShare.Read);

if (streamOne.Equals(streamTwo))
Console.WriteLine("Streams are equal");
else
{
Console.WriteLine("Streams are not equal");

ISoundSource sourceOne = engine.AddSoundSourceFromIOStream(streamOne, "RandomName"); // I changed the sound name to some unique value, but I dont want to do that, because I see that Play2D(mp3AudioPath); Play2D(mp3AudioPath); works fine with same paths and doesnt give any errors
ISoundSource sourceTwo = engine.AddSoundSourceFromIOStream(streamTwo, mp3AudioPath); // Error, not because streams are the same but because mp3AudioPath is the same.

engine.Play2D(sourceOne, false, false, false);
Thread.Sleep(3000);
engine.Play2D(sourceTwo, false, false, false); // Plays the sound but its name is not the same as first and it gives "Unknown wave header in file" because file here is "RandomName"
}

Maybe IrrKlang just can not do that through Play2D(ISoundSource...) method?



niko
Moderator
Quote
2013-05-18 11:57:09

Ah, you are right there. irrKlang assumes a sound source is a unique thing, identifyable by the sound source name. This is by design, so it's not possible to work around this other by using a different for a different sound source.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact