Jump to content

C# and wav file and new to it

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

I am new to C#, very new, i started actually right after getting done learning queries and stuff from SQL 2005, two questions, first i am writing out a simple program where you click on a button and it plays the wav file with the path already within the program so it plays the wav file. problem is, i am new so i dont know what is the command to do that, i have the entire program entered below. The second thing is, i want to Learn C#, JAVA (since they are close related or similiar), SQL, and maybe something else, what other language though? the reason is i want to get into the programming field as a professional, right now i am a softwar test engineer still learning programming so please any advice, tutorials, documentation on C# would greatly help including SQL and java.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "Hi Everybody!";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            SoundPlayer simplesound = new SoundPlayer(@"d:\additional\daboo.wave");
            simplesound.Play();
        }

    }
}

Thank you in advance

Edited by Jordan, 18 June 2008 - 12:45 PM.


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You need to add "using System.Media" namespace at the top or create your class as:

System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(....);

You can also check the MSDN reference on this class for more information: SoundPlayer Class (System.Media)

At this point I don't think you should worry about learning another language. Learn C# as best as you can.

#3
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Great Thanks jordan,

By the way is there any good online resources that can help improve my C# skills? SQL maybe as well since these are very popular in the programming industry? thanks again for that, it hurt my brain trying to figure it out and you solved it in 2 min, %!#!#% please help me obi wan, need to learn the ways. (yes i am a nerd)

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
There are a lot of good tutorials here: http://forum.codecal...harp-tutorials/
I'd also recommend picking up a book on C#. The fastest way for me to learn is to think of a project idea and set a goal towards creating it.

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Some of them are my tutorials. :)

There are many decent books out there, and it's always nicer to have a hard copy than to always refer to the internet. Plus, you can read it in the toilet. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
thanks you two for the information, i will continue to practice and enhance my skills, however i have a big problem, well questions/problem added onto this question. The thing is, now that i have it compiled to a .exe, the path to the file name does not follow the program or application, so when the person i emailed it to does not play the wav file, what can i do to include the wav file/audio file or any other file that should come with the application, should i tell it in the program to add new directory or make new directory and move the audio file? how do you do that etc?

Thanks in advance

#7
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
You need to put the wav file in the /bin/debug folder and it will be included in the project. If you like you can make a sub-folder from there. Make sure you are using a relative path name for the file so that your project still points to the file in question. Then you can just send the whole project all together.

#8
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
But be careful when writing things like databases that are put in the debug folder - the IDE automatically deletes and recreates it every time you run it if you edit it using code, to make it easier to test. You may need to set the output option to Do Not Copy. Other than that, it's really simple to include files. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#9
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Thank you Gaylo565 and Xav, but i have a question about that, for gaylo565 since you said put the audio file in the /bin/debug folder, what path do i type in the program since usually it would be in the C:/new folder/audio.wav? what is the correct path i would have to type in the program in order for the wav file to be included in the project or the exe when i send it to someone?

for Xav thank you for all the info, question regarding to what you said about databases, if it will recreate or delete the database, what is the code i type in and where do i type it in to copy a database or steps to add a database and have it not DO NOT COPY? or better yet, if i have a database on a server for say, and the program is really just a shell or manipulates it such as add or remove from the database, if i want the database on a different server/PC and the program people are running it on their own stations, it a UNC path work or what is best?

#10
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts

Siten0308 said:

... you said put the audio file in the /bin/debug folder, what path do i type in the program since usually it would be in the C:/new folder/audio.wav? what is the correct path i would have to type in the program in order for the wav file to be included in the project or the exe when i send it to someone?
you want to use a relative path so that No matter where the user puts your project it can still find its files...like so:
string strFileDestination = Directory.GetCurrentDirectory() + @"\filename.wav" ;
You will want to make sure and include a using I/O statement at the top of your class, with all the other using statements, in order to support relative file names....It should look like this:
using.System.IO;
if you are working with multiple files you can set just the Current Directory (it happens to be your bin\debug folder) to a string and don't add the file name till your method call.

Edited by gaylo565, 23 June 2008 - 07:29 AM.


#11
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Thanks for the info, but still i am confused. i have set the location you said: \bin\debug however that means its is going to look like this:
C:\Users\sbalderrama\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\wav
which is going to be long than short, is there a way to tell a program or program the app to get file from folder and throught it on a certain directory when the person executes the the application .exe,

example, since my program uses wav, if i can include the .exe witht he wav files in one folder, then when the person exe the app, it will get the wav files and through them into a simple directory and create a new folder for all wav files into a simple folder on the c drive?

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Explore the System.IO namespace, in particular the File and Directory classes. There are many useful functions for moving files, creating directories and so on.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums