Reputation: 469
I'm working on a small project that will later help me create a game. What I'm trying to achieve is the ability to play a game from a path on the player's computer. The path is known but I couldn't find any way to achieve playing a song that's not from the content path.
I'm also not talking about changing the content path's root directory, as the song won't load with LoadContent, it will load while the game is already on. If I can't do that I'll have to go back to developing games with Windows Forms which I'm not a fan of..
Upvotes: 0
Views: 266
Reputation: 27225
You can create an instance of Song
from a file on disk (a plain MP3 file, instead of something that has been through the content pipeline) using the Song.FromUri
method (MSDN).
Of course, there are some caveats with that method - see this answer for details and an alternate way of creating Song
objects from files on disk (using reflection).
(Finally, it's worth pointing out that the methods you were using with WinForms can probably be safely used in an XNA game, if you'd like to stick with those.)
Upvotes: 1
Reputation: 1377
System.IO.FileStream fs = new System.IO.FileStream(@"C:\Myfile.wav", System.IO.FileMode.Open);
SoundEffect mysound = SoundEffect.FromStream(fs);
fs.Dispose();
@"C:\Myfile.wav" can be a relative or absolute path. Not sure about MP3's or others.
Worst case scenario, just embed the FMod Ex soundsystem into your XNA game.
Upvotes: 3