sound stop Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

sound stop

Post by luisbriosso »

hi once again!

I recently posted an issue in which I said that I wasnt able to stop sound...

problem is that I am able to close main window and stop sound, but if I close the Dialog in which I show the media file, then sound keeps playing...

the hint I was given was to do the following...

void MyFrame::OnClose(wxCloseEvent& WXUNUSED(event)) {
if (mediactrl->GetState() == wxMEDIASTATE_PLAYING)
dialog->Stop();
dialog->Destroy();
}

so, question is... how do I make an event that refers to a closure of a Dialog and not to a class (My Frame) ?
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

use wxEvtHandler::Connect

Code: Select all

wxDialog dlg;

  dlg.Connect( wxID_ANY,
    wxEVT_CLOSE,
    wxCloseEventHandler(MyFrame::OnQuit) );
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

just learned to post thing more neat :)

I tried that but wasnt able...

I found other things here and did this...

Code: Select all

void MyFrame::Connect(wxDialog *myDialog)
{
// connect events
my->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, (wxObjectEventFunction)OnQuit);

}

//then on OnQuit

void MyFrame::OnQuit(wxCloseEvent& WXUNUSED(event))

{
if (mediactrl->GetState() == wxMEDIASTATE_PLAYING)
mediactrl->Stop();
//this->Destroy();
//iguDialog->Destroy();

}
whats the error?
how do I implement protocol suggestion?

dlg->Conect( wxID_ANY, wxEVT_CLOSE, wxCloseEventHandler(MyFrame::OnQuit) );

and what else should I define?

thanks again!
this forum is amazing!

Luis
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
Could you post some more code? Especially where do you create the media control and what events should be connected to which handler.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

upcase:

here they are the main parts of the code

Code: Select all

void OnQuit(wxCloseEvent &event);
	void Connect(wxDialog *iguDialog);
	wxMediaCtrl *mediaCtrl;
	wxDialog *myDialog;
	
	EVT_CLOSE(MyFrame::OnQuit)

	mediaCtrl = new wxMediaCtrl();
	myDialog = new wxDialog(this, -1, "dialog", wxPoint(300,100), wxSize(400,400), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX | wxMINIMIZE_BOX | wxTHICK_FRAME ,"dialogBox");

    myDialog->SetBackgroundColour(wxColour(0, 0, 0));
    mediaCtrl->Create(myDialog, ID_MEDIA, fd.GetPath(), wxPoint(0, 0), wxSize(1024,768));
     
void MyFrame::OnQuit(wxCloseEvent& WXUNUSED(event))  

{ 
 	if (mediaCtrl->GetState() == wxMEDIASTATE_PLAYING) 
       mediaCtrl->Stop();
	
}

void MyFrame::Connect(wxDialog *myDialog)
{
    
       myDialog->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW, (wxObjectEventFunction)OnQuit);

}
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

try this:

Code: Select all

myDialog->Connect( myDialog->GetId(), wxEVT_CLOSE_WINDOW,
wxCloseEventHandler(MyFrame::OnQuit) );
Hope that works.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

doesn
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Where is the code that actually closes the dialog (wxDialog::Close||Destroy)?
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

i dont close it, i just do this...

mediaCtrl->Stop();


what do you suggest?


thanks in advance!
Luis
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

luisbriosso wrote:i dont close it, i just do this...

mediaCtrl->Stop();


what do you suggest?


thanks in advance!
Luis
Close the dialog. That may be the source of the problem......
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

this is what I
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

The close event fires when the event is raised/emitted ( wxWindow::Close() ). So you will or should close the dialog before you call mediaCtrl->Stop().

Also if you really want the music to stop playing you can try deleting the pointer, and then re-instantiate it (mediaCtrl) if you need access it again.

Code: Select all

 if (mediaCtrl->GetState() == wxMEDIASTATE_PLAYING) {
        delete mediaCtrl;
        this->Destroy();
    } 

// mediaCtrl = new wxMediaCtrl( ... ); // if needed again
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

thanks protocol, but I
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Is the event firing at all?
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
luisbriosso
Knows some wx things
Knows some wx things
Posts: 44
Joined: Tue Mar 28, 2006 9:44 pm
Location: Montevideo, Uruguay

Post by luisbriosso »

Closing this trail as investigated other possibilities that got mediactrl out of the project...
Post Reply