Hello guys. I have an application ( size ~3MB ) , with 5 forms. In my principal form i want , like when the program starts , a SoundPlayer to sing.

Ok , look what i did:

first , i loaded my picture ( in resources - Audio - save it )
after that , in my principal program , before public Form1() , i made this:

private SoundPlayer Welcome = new SoundPlayer(Properties.Resources.welcome);

Ok , in my public Form1() , i made this:
Welcome.Play();

When i debug my program ( start my program ) my sound didn't sing normally , it sounds like a scratch ( bzzzzzzzzzzz ).

But , if I made a timer , and i set it as 500ms , and in public Form1() I enable it , and in my timertick function , i do this:

Welcome.Play();

It sounds good !

So , can somebady help me :( ?

Nobody knows why ?

Try moving the sound playback from the form constructor to an event handler for Form.Load--I'm not sure if this will fix it, but I've run into other kinds of problems related to doing too much in form constructors.

Can you show me one example ... ? Please ?

thanks

I have set at Events , Load , and i put:

private void Form1_Load_1(object sender, EventArgs e)
        {
            Welcome.Play();
        }

And same thing :( it scratch ... , bzzzzzzzz

And look , if i choose Mouse_Click event , and i do Playback at Welcome , it works ... it didn't scratch ... why :( ?

As I know use constructor for solve this. Try moving the sound playback from the form constructor to an event handler for (Form.Load).I am not sure if this will fix it. It supports you to for sound problem.

i really don't know how can i do that ... if you can show me ...

:|

This might be a garbage collection issue... could you post a ZIP file with the form that uses the SoundPlayer and the Resources class?

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;
using System.Media;

namespace Browser
{
    public partial class Form1 : Form
    {
        //private System.Media.SoundPlayer tada = new System.Media.SoundPlayer(Properties.Resources.tada);
        private SoundPlayer Feed = new SoundPlayer(Properties.Resources.Windows_Feed_Discovered);
        private SoundPlayer Clicked = new SoundPlayer(Properties.Resources.Windows_Navigation_Start);
        private SoundPlayer Youtube = new SoundPlayer(Properties.Resources.ohmygod);
        private SoundPlayer Clamb = new SoundPlayer(Properties.Resources.aboutme);
        private SoundPlayer Welcome = new SoundPlayer(Properties.Resources.welcome);
        public Form1()
        {
            InitializeComponent();
            label1.Text = System.DateTime.Now.ToLongTimeString();            
            timer2.Enabled = true;
            Welcome.Play();
        }
private void timer1_Tick(object sender, EventArgs e)
        { // Timer - 1 second ( 1000ms )
            label1.Text = System.DateTime.Now.ToLongTimeString();
        }
short t2tick = 1,stop = 0;
        private void timer2_Tick(object sender, EventArgs e)
        {
            t2tick++;
            switch (t2tick)
            {
                case 0: pictureBox1.BackgroundImage = Properties.Resources._1st; break;
                case 1: pictureBox1.BackgroundImage = Properties.Resources._2st; break;
                case 2: pictureBox1.BackgroundImage = Properties.Resources._3st; break;
                case 3: pictureBox1.BackgroundImage = Properties.Resources._4st; break;
                case 4: pictureBox1.BackgroundImage = Properties.Resources._5st; break;
                case 5: pictureBox1.BackgroundImage = Properties.Resources._6st; break;
                case 6: pictureBox1.BackgroundImage = Properties.Resources._7st; break;
                case 7: { pictureBox1.BackgroundImage = Properties.Resources._8st; stop++; t2tick = 0; if (stop == 2) { pictureBox1.Hide(); timer1.Enabled = true; } break; }
            }
        }

And resources: http://img717.imageshack.us/img717/8274/resourcesu.png

Well, this is bizarre.

Maybe call SoundPlayer.Load (see here) before you play the sound. It really shouldn't be necessary, but I think it's worth a try.

Other than that, I'm stumped. I found a post on MSDN that seems to be describing something very similar to what you're experiencing... unfortunately, the detailed article that it refers to appears to be missing. :(

Now the sound sounds like: tztztztztzzzzzzzzzzzzz

Have you tried putting Welcome.Play(); in the Form_Shown event instead?
This runs after the constructor and Form_Load.

Nope , still don't work

Did you try using PlaySync instead? Or testing IsLoadCompleted before playing?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.