Click here to Skip to main content
16,015,047 members
Home / Discussions / C#
   

C#

 
GeneralRe: when is finally?! [modified] Pin
Henry Minute14-Nov-10 14:20
Henry Minute14-Nov-10 14:20 
GeneralRe: when is finally?! Pin
Jeff Connelly15-Nov-10 4:38
Jeff Connelly15-Nov-10 4:38 
GeneralRe: when is finally?! Pin
Jacob D Dixon15-Nov-10 10:34
Jacob D Dixon15-Nov-10 10:34 
GeneralRe: when is finally?! Pin
Jeff Connelly15-Nov-10 10:49
Jeff Connelly15-Nov-10 10:49 
Questionpixel related question Pin
inayathussaintoori13-Nov-10 4:48
inayathussaintoori13-Nov-10 4:48 
AnswerRe: pixel related question Pin
Abhinav S13-Nov-10 7:01
Abhinav S13-Nov-10 7:01 
GeneralRe: pixel related question Pin
inayathussaintoori13-Nov-10 7:15
inayathussaintoori13-Nov-10 7:15 
QuestionPlay multiple sounds with SoundPlayer and SDK DirectSound Pin
Mc_Topaz13-Nov-10 0:57
Mc_Topaz13-Nov-10 0:57 
For a simple game I'm developing I would like to play background music and sound effects.

I have tried a different methods to play two sounds at the same time with .NET SoundPlayer class, but with no result. At best, with use of .NET BackgroundWorker class, I could get the background music to play with no sound effect. Or only sound effects and no background music.

Anyway, I googled and searched for some solutions and found SDK library which I have implemented in my test application.

This is my test application:
* A Windows Form Application with two buttons
* Background music button, (btnBackgroundTrack_Click)
* Sound effect button, (btnEffectTrack_Click)
* The two music tracks are stored as UnmanagedMemoryStream type objects in a resource file
* "Resource.Background", the background music .wav-file, plays for 48 seconds
* "Resource.Item", the sound effect .wav-file, plays less than 1 second

This is my code:

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;
using Microsoft.DirectX.DirectSound;

public partial class Form1 : Form
{
    BackgroundWorker effectPlayer;
    SoundPlayer effect;

    public Form1()
    {
        InitializeComponent();

        effectPlayer = new BackgroundWorker();
        effectPlayer.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);

        effect = new SoundPlayer(Resource.Item);
    }

    void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        effect.PlaySync();
    }

    private void btnBackgroundTrack_Click(object sender, EventArgs e)
    {
        Device device = new Device(DSoundHelper.DefaultPlaybackDevice);
        device.SetCooperativeLevel(this, CooperativeLevel.Normal);
        SecondaryBuffer secondaryBuffer = new SecondaryBuffer(Resource.Background, device);
        secondaryBuffer.Play(0, BufferPlayFlags.Default);
    }

    private void btnEffectTrack_Click(object sender, EventArgs e)
    {
        if(!effectPlayer.IsBusy)
            effectPlayer.RunWorkerAsync();
    }
}


This solution kinda works. The background music is played when I hit the "background" button, and if I hit the effect button it's plays as well.

Problem 1: If I click the effect button very fast and often while the background music is playing, all sounds from the program is termenated.
Problem 2: I would like the the background music to repeat it self when it's over.

Any solutions?
Questiongiving authorization to the user Pin
Erdinc2712-Nov-10 23:55
Erdinc2712-Nov-10 23:55 
AnswerRe: giving authorization to the user Pin
Eddy Vluggen13-Nov-10 9:01
professionalEddy Vluggen13-Nov-10 9:01 
GeneralRe: giving authorization to the user Pin
Erdinc2713-Nov-10 9:50
Erdinc2713-Nov-10 9:50 
GeneralRe: giving authorization to the user Pin
Eddy Vluggen13-Nov-10 11:21
professionalEddy Vluggen13-Nov-10 11:21 
QuestionSkins Pin
Anil Kumar.Arvapalli12-Nov-10 18:45
Anil Kumar.Arvapalli12-Nov-10 18:45 
AnswerRe: Skins Pin
thatraja12-Nov-10 19:11
professionalthatraja12-Nov-10 19:11 
AnswerRe: Skins Pin
Kanasz Robert13-Nov-10 6:02
professionalKanasz Robert13-Nov-10 6:02 
GeneralRe: Skins Pin
Anil Kumar.Arvapalli13-Nov-10 23:19
Anil Kumar.Arvapalli13-Nov-10 23:19 
QuestionUse Automation To Open Solution Pin
Kevin Marois12-Nov-10 11:36
professionalKevin Marois12-Nov-10 11:36 
AnswerRe: Use Automation To Open Solution Pin
Eddy Vluggen13-Nov-10 8:59
professionalEddy Vluggen13-Nov-10 8:59 
QuestionHttpWebRequest/Response check for connectivity Pin
softwarejaeger12-Nov-10 1:48
softwarejaeger12-Nov-10 1:48 
AnswerRe: HttpWebRequest/Response check for connectivity Pin
Dave Kreskowiak12-Nov-10 3:45
mveDave Kreskowiak12-Nov-10 3:45 
QuestionHow to Improve Qulity of Print Pin
Anubhava Dimri11-Nov-10 23:23
Anubhava Dimri11-Nov-10 23:23 
AnswerRe: How to Improve Qulity of Print Pin
OriginalGriff11-Nov-10 23:48
mveOriginalGriff11-Nov-10 23:48 
GeneralRe: How to Improve Qulity of Print Pin
Anubhava Dimri12-Nov-10 0:13
Anubhava Dimri12-Nov-10 0:13 
GeneralRe: How to Improve Qulity of Print Pin
Pete O'Hanlon12-Nov-10 0:37
mvePete O'Hanlon12-Nov-10 0:37 
GeneralRe: How to Improve Qulity of Print Pin
Anubhava Dimri12-Nov-10 17:21
Anubhava Dimri12-Nov-10 17:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.