Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Which control i should use to play sound?? (http://www.programmingforums.org/showthread.php?t=13684)

Tajinder Singh Aug 1st, 2007 5:43 AM

Which control i should use to play sound??
 
Hi all...

My question is much like previous one but with little difference..

This time i am developing an application which browses file having .wav or .avi extention....

Pls also tell me in which control i can play selected sound...

Regards...

Seif Aug 1st, 2007 8:11 AM

What libraries are you currently using for your application ?

Tajinder Singh Aug 2nd, 2007 8:49 AM

Hi .. Following is code behind three buttons like Load, Play n Stop:-

void Sound::LoadSound()
{
char path[255];
GetCurrentDirectory(255, path);
CFileDialog dialog(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"WAV Files (*.wav)|*.wav||");
INT_PTR ptr= dialog.DoModal();
SetCurrentDirectory(path);
if (ptr==IDOK)
{
UpdateData();
CString str=dialog.GetPathName();
m_snd_ext = dialog.GetFileExt();

m_snd_filename=str;
PlaySnd();
UpdateData(FALSE);
}
}

void Sound::PlaySnd()
{
m_valid_snd = PlaySound(m_snd_filename,NULL,SND_ASYNC|SND_FILENAME|SND_LOOP);
if(m_valid_snd)
{
this->GetDlgItem(IDC_SND_PLAY)->EnableWindow(FALSE);
this->GetDlgItem(IDC_SND_STOP)->EnableWindow(TRUE);
}
}

void Sound::StopSound()
{
PlaySound(NULL,NULL,SND_PURGE);
this->GetDlgItem(IDC_SND_STOP)->EnableWindow(FALSE);
this->GetDlgItem(IDC_SND_PLAY)->EnableWindow(TRUE);
}

One may select a sound (.wav file)which may be corrupted.
Its better to check the file in advance then Call PlaySound().

Can we have check on corrupted wav file ??

DaWei Aug 2nd, 2007 9:46 AM

Have a look:
Quote:

Originally Posted by Rules - Code Tags
Code Tags
When posting code please put all code between the tags. This makes reading source code alot easier for everyone trying to read the code. If you haven't used code tags in a post, moderators may add them in for you, but it would make our job a lot easier were you to use them yourself. There are addition ways to put your code in tags that makes it easy this will add syntax highlighting which makes things easier on the people trying to help you.


Tajinder Singh Aug 3rd, 2007 2:36 AM

Following is code behind three buttons like Load, Play n Stop:-

code behind LoadSound Button...
:

void Sound::LoadSound()
{
        char path[255];
        GetCurrentDirectory(255, path);
        CFileDialog dialog(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"WAV Files (*.wav)|*.wav||");
        INT_PTR ptr= dialog.DoModal();
        SetCurrentDirectory(path);
        if (ptr==IDOK)
        {
                UpdateData();
                CString str=dialog.GetPathName();
                m_snd_ext = dialog.GetFileExt();
               
                m_snd_filename=str;
                PlaySnd();
                UpdateData(FALSE);
        }
}


code behind PlaySnd Button...
:

void Sound::PlaySnd()
{
        m_valid_snd = PlaySound(m_snd_filename,NULL,SND_ASYNC|SND_FILENAME|SND_LOOP);
        if(m_valid_snd)
        {
                this->GetDlgItem(IDC_SND_PLAY)->EnableWindow(FALSE);
                this->GetDlgItem(IDC_SND_STOP)->EnableWindow(TRUE);
        }
}


Code behind StopSound button...
:

void Sound::StopSound()
{
        PlaySound(NULL,NULL,SND_PURGE);
        this->GetDlgItem(IDC_SND_STOP)->EnableWindow(FALSE);
        this->GetDlgItem(IDC_SND_PLAY)->EnableWindow(TRUE);
}

One may select a sound (.wav file)which may be corrupted.
Its better to check the file in advance and then Load it or Call PlaySound().

Can we have check on corrupted wav file ??

Tajinder Singh Aug 3rd, 2007 2:37 AM

Thansk Dawei for your suggestion....

Tajinder Singh Aug 14th, 2007 10:26 AM

Updated now


All times are GMT -5. The time now is 2:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC