I'm currently using Microsoft Visual C# 2010. I figured I would get that out of the way so that the main issue can be addressed.
Now to the issue at hand.
My long-term goal is to make a portable (as in it can be installed on any computer) music player with a play, pause, stop, and volume function that has a list of songs that can be loaded into the main player with the controls.
As of this moment, I've only succeeded in having a song play with no control whatsoever.
Currently, I've tried making a form, which worked just fine if I wanted to just hand over the music I want the user to play and make them load everything. After a few days of searching, I was unable to apply what I saw in any meaningful way.
The video, at least the one I can find, that I initially tried was this one.
I found another that had a more list-based window, but I can't seem to find it. Regardless, the principles are roughly the same.
I've also tried XACT, and could get it to work as far as playing was concerned, but the key that I used to trigger the event would cause multiple instances to play on top of each other, and I couldn't get it to pause or stop.
I also had the issue of where a single key press would create multiple instances at almost the same time resulting in a chorused effect. DayNightExperiment { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; KeyboardState currentKeyState; AudioEngine engine; SoundBank soundBank; WaveBank waveBank; Cue cue; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 1200; graphics.PreferredBackBufferHeight = 750; } protected override void Initialize() { engine = new AudioEngine("Content\\soundexperiment.xgs"); soundBank = new SoundBank(engine, "Content\\Sound Bank.xsb"); waveBank = new WaveBank(engine, "Content\\Wave Bank.xwb"); base.Initialize(); } protected override void Update(GameTime gameTime) { Cycle += 1 * (float)gameTime.ElapsedGameTime.TotalSeconds; currentKeyState = Keyboard.GetState(); currentMouseState = Mouse.GetState(); cue = soundBank.GetCue("Sunlight"); if (IsKeyPressed(Keys.P, "PRESS")) cue.Play(); engine.Update(); base.Update(gameTime); }
A quick note: the "IsKeyPressed" business is part of a code my friend showed me to basically force the game to only register one key stroke, and out of respect for him, I will not post the finer details of that code here.
And speaking of games, I've been working in the format of a game to try and make this music player. I'm not sure if that's important, but I figured I would mention it anyways.
Concerning this method of going about things, I've searched online for a few days now in an attempt to remedy and figure out the issues I'm having, but so far, no such luck.
With this failure, I moved on and back to an old idea I had, which is to use the SoundEffect method to create this player.
So far, I've again only succeeded in getting a sound to play, and only just got it to stop looping infinitely. I also recently had some success with placing a SoundEffectInstance inside an if statement (which is something that I have been unable to do up to this point. Using cues, I could place those in an if statement, but again, ran into the issue of multiple instances playing on top of each other upon key presses.)
Right now, I currently have this using the SoundEffect DIM { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SoundEffect S1; SoundEffect S2; SoundEffectInstance SEI_1; SoundEffectInstance SEI_2; KeyboardState currentKeyState; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { S1 = Content.Load<SoundEffect>("Descent Into Madness"); S2 = Content.Load<SoundEffect>("Sunlight"); SEI_1 = S1.CreateInstance(); SEI_2 = S2.CreateInstance(); spriteBatch = new SpriteBatch(GraphicsDevice); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { if (SEI_1.State == SoundState.Stopped) { SEI_1.Play(); } if (SEI_1.State == SoundState.Playing && currentKeyState.IsKeyDown(Keys.D1)) { SEI_1.Pause(); } base.Update(gameTime); }
All in all, I'm not partial to any method. I just want something that will work.
The more practical idea seems to be using the first method, a media player, which uses Windows Media Player, however I must admit I've only been coding for about two months now in C# and can't quite grasp all the concepts that are being thrown at me each time I tried to use that method.
In the end, after about two weeks of trying this on my own, I figured it would be a good idea to get some input on this conundrum. If anyone can provide any sort of idea on how to achieve this, or has a different method of doing things, I am very much open to suggestion, and again, being a beginner, if you can keep your explanations in simple terms, I would really appreciate it.
Thank you all for your time if you're reading this and especially thank you if you so choose to try and help me with this issue.
-H2012