How to play and stop mp3 asynchronously 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
marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

How to play and stop mp3 asynchronously

Post by marcusbarnet » Fri Oct 25, 2019 6:51 pm

I'm struggling with no success to find a way to play mp3 files asynchronously and to stop them depending on user's actions.
I do not want to stop the program's flow since the mp3 are like a voice over to support the user during the use of the application.

I'm using C++ and Ubuntu 18.04 and WxWidgets 3.1.

I tried to use libvlc and to write a class to play and stop the mp3; I've read that libvlc already integrates asynchronous methods but if I try to play a file, the program stops until the mp3 is not finished. So I decided to use threads.
It works, but when I try to stop the mp3, I get a segmentation fault.

This is my current code (rePlay is the class to play the music, firstpanel.cpp is the first panel where I play the music and secondpanel.cpp is the second panel where I want to send the signal to stop the music).
At the moment, the music correctly starts in firstpanel, but when I try to stop it from the second panel, I get the segment fault error.
I hope you can help me! I do not need to use libvlc necessarily, amy other solution is OK.

Code: Select all

// replay.h
#include <vlc/vlc.h>

class rePlay
{
    public:
        rePlay();
        virtual ~rePlay();
        void play_mp3(const char*);
        void stop_mp3();
    protected:
        libvlc_instance_t *inst;
        libvlc_media_player_t *mp;
        libvlc_media_t *m;
    private:
};

// rePlay.cpp

#include "rePlay.h"
#include <vlc/vlc.h>

rePlay::rePlay()
{
    //ctor
}

rePlay::~rePlay()
{
    //dtor
}

void rePlay::play_mp3(const char* path){

  // load the vlc engine
    inst = libvlc_new(0, NULL);
    printf("apro il file %d\n", inst);
    // create a new item
    m = libvlc_media_new_path(inst, path);
    // create a media play playing environment
    mp = libvlc_media_player_new_from_media(m);
    // no need to keep the media now
    libvlc_media_release(m);
    // play the media_player
    libvlc_media_player_play(mp);
    printf("Done.\n");
}

void rePlay::stop_mp3(){
  // stop playing
    libvlc_media_player_stop(mp);
    // free the media_player
    libvlc_media_player_release(mp);
    libvlc_release(inst);
}

// firstpanel.h

class firstpanel: public wxPanel
{
	public:
		firstpanel(wxWindow* parent, Isola02Frame*, wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~firstpanel();
		void checkValue(wxCommandEvent& event);
		void check_cf(wxTimerEvent& event);
                rePlay *mp3_apertura_porta = new rePlay();    // <-- I DECLARED THE pointer here
		//(*Declarations(firstpanel)
		wxStaticText* assistenza;
		wxStaticText* first_panel;
		wxStaticText* identificazione;
		wxTextCtrl* tessera;
		//*)
...
}

// firstpanel.cpp
 std::thread second = std::thread([this]() noexcept {
        this->mp3_apertura_porta->play_mp3("/home/robodyne/Project/audio/scegli-rifiuto.mp3"); });
        second.join();

// secondpanel.cpp

void secondpanel::OnBitmapButton2Click(wxCommandEvent& event)
{
 firstpanel *ptr;
 ptr->mp3_apertura_porta->stop_mp3();
}

// secondpanel.h
class secondpanel: public wxPanel
{
   	public:

		secondpanel(wxWindow* parent, Isola02Frame*, wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~secondpanel();

       	//(*Declarations(secondpanel)
       	wxBitmapButton* BitmapButton2;
       	wxBitmapButton* BitmapButton3;
       	wxBitmapButton* BitmapButton4;
       	wxBitmapButton* BitmapButton5;
       	wxBitmapButton* BitmapButton6;
       	wxBitmapButton* plastica;
       	wxStaticText* selezione_tipologia;
       	//*)

	protected:
        Isola02Frame *pointer;
		//(*Identifiers(secondpanel)
		static const long ID_BITMAPBUTTON1;
		static const long ID_BITMAPBUTTON2;
		static const long ID_BITMAPBUTTON3;
		static const long ID_BITMAPBUTTON4;
		static const long ID_BITMAPBUTTON5;
		static const long ID_BITMAPBUTTON6;
		static const long ID_STATICTEXT1;
		//*)

	private:

		//(*Handlers(secondpanel)
		void OnplasticaClick(wxCommandEvent& event);
		void OnBitmapButton2Click(wxCommandEvent& event);
		//*)

		DECLARE_EVENT_TABLE()
};


ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4359
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to play and stop mp3 asynchronously

Post by ONEEYEMAN » Fri Oct 25, 2019 9:11 pm

Hi,
What version of libvlc do you use?
Can you post a backtrace?
wxWidgets has a library called "media" and a sample called "media". Did you try it?

Thank you.

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Fri Oct 25, 2019 9:28 pm

I can't access my laptop right now, but it should be the last version since I installed the library few weeks ago by using apt-get.

I didn't launch the mediaplayer example because when I saw it I realized that it comes with a gui to control the music file.

I just need to run the mp3 in background (it is a voice over) and to stop it when the user wants to stop the mp3.

P.s. what I have to do in order to post the back trace?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4359
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to play and stop mp3 asynchronously

Post by ONEEYEMAN » Fri Oct 25, 2019 9:33 pm

Hi,
You should install the gdb (Linux debugger) and run the software under debugger.
When it crashes - run the "bt" command and post the result.

Something like:

Code: Select all

apt-get gdb
gdb <my_program>
gdb> run
Segmentation fault
gdb> bt
Response from the command execution removed for clarification.

Thank you.

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 6:44 am

Thank you for your support!

This is the output:

Code: Select all

[New Thread 0x7fffafd23700 (LWP 9736)]
hey

Thread 1 "Isola02" received signal SIGSEGV, Segmentation fault.
0x0000555555689484 in secondpanel::OnBitmapButton2Click (this=0x555555f32840, event=...)
    at /home/isola/Documents/Isola02/secondpanel.cpp:96
96	 ptr->mp3_apertura_porta->stop_mp3();
(gdb) bt
#0  0x0000555555689484 in secondpanel::OnBitmapButton2Click(wxCommandEvent&) (this=0x555555f32840, event=...)
    at /home/isola/Documents/Isola02/secondpanel.cpp:96
#1  0x00005555559c892b in wxEvtHandler::ProcessEventIfMatchesId(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ()
#2  0x00005555559c8eaf in wxEvtHandler::SearchDynamicEventTable(wxEvent&) ()
#3  0x00005555559c914f in wxEvtHandler::TryHereOnly(wxEvent&) ()
#4  0x00005555559c91ea in wxEvtHandler::ProcessEventLocally(wxEvent&) ()
#5  0x00005555559c926d in wxEvtHandler::ProcessEvent(wxEvent&) ()
#6  0x00005555557c095b in wxWindowBase::TryAfter(wxEvent&) ()
#7  0x00005555559cad97 in wxEvtHandler::SafelyProcessEvent(wxEvent&) ()
#8  0x00005555556de65e in wxgtk_button_clicked_callback ()
#9  0x00007ffff58fd346 in  () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#10 0x00007ffff59189ff in g_signal_emit_valist () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#11 0x00007ffff591912f in g_signal_emit () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#12 0x00007ffff6eb4add in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#13 0x00007ffff6eb4b35 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#14 0x00007ffff58fd10d in g_closure_invoke () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#15 0x00007ffff591012e in  () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#16 0x00007ffff5918715 in g_signal_emit_valist () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#17 0x00007ffff591912f in g_signal_emit () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#18 0x00007ffff6eb2f90 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#19 0x00007fffef469dae in ffi_call_unix64 () at /usr/lib/x86_64-linux-gnu/libffi.so.6
#20 0x00007fffef46971f in ffi_call () at /usr/lib/x86_64-linux-gnu/libffi.so.6
#21 0x00007ffff58fdced in g_cclosure_marshal_generic_va () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#22 0x00007ffff58fd346 in  () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#23 0x00007ffff59189ff in g_signal_emit_valist () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#24 0x00007ffff591912f in g_signal_emit () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#25 0x00007ffff6f6fa36 in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#26 0x00007ffff5900008 in g_cclosure_marshal_VOID__BOXEDv () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#27 0x00007ffff58fd346 in  () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#28 0x00007ffff59189ff in g_signal_emit_valist () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#29 0x00007ffff591912f in g_signal_emit () at /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#30 0x00007ffff6f6cd0e in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
#31 0x00007ffff6f6e2fb in  () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---q
the problem is related to the secondpanel.cpp file when I call:

Code: Select all

void secondpanel::OnBitmapButton2Click(wxCommandEvent& event)
{
 firstpanel *ptr;
 ptr->mp3_apertura_porta->stop_mp3();
}
I think it's because I can't call stop_mp3() from another panel since the variable scope is different, but I do not know how to solve it.

Edit: however, the mediaplayer sample doesn't compile correctly:

Code: Select all

 g++ mediaplayer.cpp `wx-config --cflags` `wx-config --libs` -o mediaplayer
 --
mediaplayer.cpp:90:2: error: #error "Not all required elements are enabled.  Please modify setup.h!"
 #error "Not all required elements are enabled.  Please modify setup.h!"
  ^~~~~
mediaplayer.cpp:205:24: error: ‘wxMediaEvent’ has not been declared
     void OnMediaLoaded(wxMediaEvent& event);
                        ^~~~~~~~~~~~
mediaplayer.cpp:245:22: error: ‘wxMediaEvent’ has not been declared
     void OnMediaPlay(wxMediaEvent& event);
even if I do not need it since I do not need the GUI controls for the mp3, I just need to be able to start and play a sound in background.

vjedlicka
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Aug 10, 2019 11:55 am

Re: How to play and stop mp3 asynchronously

Post by vjedlicka » Sat Oct 26, 2019 7:05 am

Variable ptr in your code is not initialized.

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play and stop mp3 asynchronously

Post by doublemax » Sat Oct 26, 2019 7:24 am

Here's sample code for a minimal media player using libvlc with wxWidgets:
https://git.videolan.org/?p=vlc.git;a=b ... player.cpp

No threads are needed.
Use the source, Luke!

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 7:25 am

I usually use this procedure to declare variables and I get only a warning since they works fine at runtime so I wasnt thinking that the problem could be that.

How can I correctly initialize the ptr?
Can you give me an example please?

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play and stop mp3 asynchronously

Post by doublemax » Sat Oct 26, 2019 7:34 am

Like i already explained a few times, it's bad to call a method from one panel from another panel. You'll always run into these kind of problem. Now panel2 needs to know that panel1 exists and it needs a pointer to it. These kind of dependencies should ring an alarm bell in your head.

Use their parent as "manager" class.
Use the source, Luke!

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 11:49 am

doublemax wrote:
Sat Oct 26, 2019 7:24 am
Here's sample code for a minimal media player using libvlc with wxWidgets:
https://git.videolan.org/?p=vlc.git;a=b ... player.cpp

No threads are needed.
I tried to compile it, but I receive lots of errors:

Code: Select all

g++ doc_libvlc_wx_player.cpp `wx-config --libs` `wx-config --cxxflags` `pkg-config --cflags gtk+-2.0 libvlc` `pkg-config --libs gtk+-2.0 libvlc` -o wx_player
doc_libvlc_wx_player.cpp:14:14: fatal error: gtk/win_gtk.h: No such file or directory
     #include <gtk/win_gtk.h>
then I've found this topic viewtopic.php?t=44227 where the OP had my same problem, but I didn't solved it.
However, I need a class which I can call from different panels to start and stop the music, i.e., i start the mp3 from firstpanel and I stop it from the secondpanel. I do not need an GUI to control the mp3, i just need to start and stop the music from code depending on user actions.

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 11:58 am

doublemax wrote:
Sat Oct 26, 2019 7:34 am
Like i already explained a few times, it's bad to call a method from one panel from another panel. You'll always run into these kind of problem. Now panel2 needs to know that panel1 exists and it needs a pointer to it. These kind of dependencies should ring an alarm bell in your head.

Use their parent as "manager" class.
I know, but I wasn't able to figure out how to do that.

I tried in this way:

Code: Select all

//fisrtpanel.h
class firstpanel: public wxPanel
{
   	public:
		firstpanel(wxWindow* parent, Isola02Frame*, wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~firstpanel();
		void checkValue(wxCommandEvent& event);
		void check_cf(wxTimerEvent& event);
		rePlay *mp3_apertura_porta;
		rePlay* getPlayer() {
		    return mp3_apertura_porta;
		     }
		     
// secondpanel.h
class secondpanel: public wxPanel
{
   	public:

		secondpanel(wxWindow* parent, Isola02Frame*, wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~secondpanel();
		rePlay* mp3_apertura_porta = nullptr;
        void setPlayer(rePlay* player) {
		mp3_apertura_porta = player;
	    }
	  
 // isola02App.cpp
 #include "Isola02App.h"
#include <stdio.h>
#include <stdlib.h>
#include "firstpanel.h"
#include "secondpanel.h"

//(*AppHeaders
#include "Isola02Main.h"
#include <wx/image.h>
//*)

wxIMPLEMENT_APP(Isola02App);

bool Isola02App::OnInit()
{
    Isola02Frame* frame = new Isola02Frame(L"Isola02Frame");
    pointer = frame;
    frame->Show(true);
    wxInitAllImageHandlers();
    m_timer.Bind(wxEVT_TIMER, &Isola02App::reset, this);
    firstpanel *p1;
    p1->mp3_apertura_porta = new rePlay();
    secondpanel *p2;
    p2->setPlayer(p1->getPlayer());
    return true;
}		     
		     
But it doesn't run and immediately gives segmentation fault:

Code: Select all

gdb Isola02 
GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from Isola02...done.
(gdb) run
Starting program: /home/isola/Documents/Isola02/bin/Debug/Isola02 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffeb714700 (LWP 14115)]
[New Thread 0x7fffeaf13700 (LWP 14116)]
[New Thread 0x7fffe917e700 (LWP 14117)]
[New Thread 0x7fffe897d700 (LWP 14118)]
14:02:40: Debug: Adding duplicate image handler for 'PNG file'
14:02:40: Debug: Adding duplicate image handler for 'JPEG file'
14:02:40: Debug: Adding duplicate image handler for 'TIFF file'
14:02:40: Debug: Adding duplicate image handler for 'GIF file'
14:02:40: Debug: Adding duplicate image handler for 'PNM file'
14:02:40: Debug: Adding duplicate image handler for 'PCX file'
14:02:40: Debug: Adding duplicate image handler for 'IFF file'
14:02:40: Debug: Adding duplicate image handler for 'Windows icon file'
14:02:40: Debug: Adding duplicate image handler for 'Windows cursor file'
14:02:40: Debug: Adding duplicate image handler for 'Windows animated cursor file'
14:02:40: Debug: Adding duplicate image handler for 'TGA file'
14:02:40: Debug: Adding duplicate image handler for 'XPM file'

Thread 1 "Isola02" received signal SIGSEGV, Segmentation fault.
0x000055555568529b in Isola02App::OnInit (this=0x555555e49ab0) at /home/isola/Documents/Isola02/Isola02App.cpp:31
31	    p1->mp3_apertura_porta = new rePlay();
(gdb) db
Undefined command: "db".  Try "help".
(gdb) bt
#0  0x000055555568529b in Isola02App::OnInit() (this=0x555555e49ab0) at /home/isola/Documents/Isola02/Isola02App.cpp:31
#1  0x00005555559289dd in wxEntry(int&, wchar_t**) ()
#2  0x0000555555685140 in main(int, char**) (argc=1, argv=0x7fffffffdf28) at /home/isola/Documents/Isola02/Isola02App.cpp:21


DavidHart
Site Admin
Site Admin
Posts: 3998
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to play and stop mp3 asynchronously

Post by DavidHart » Sat Oct 26, 2019 1:57 pm

I tried to compile it, but I receive lots of errors:
g++ doc_libvlc_wx_player.cpp `wx-config --libs` `wx-config --cxxflags` `pkg-config --cflags gtk+-2.0 libvlc` `pkg-config --libs gtk+-2.0 libvlc` -o wx_player
doc_libvlc_wx_player.cpp:14:14: fatal error: gtk/win_gtk.h: No such file or directory
From your earlier backtrace:
#31 0x00007ffff6f6e2fb in () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
you were previously compiling against GTK+3. Now you are trying to use GTK+2, which is not installed.

Either install it: sudo apt install libgtk2.0-dev
or try to build that sample code against GTK+3, changing 2 to 3 in those pkg-config calls.

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 4:10 pm

DavidHart wrote:
Sat Oct 26, 2019 1:57 pm
I tried to compile it, but I receive lots of errors:
g++ doc_libvlc_wx_player.cpp `wx-config --libs` `wx-config --cxxflags` `pkg-config --cflags gtk+-2.0 libvlc` `pkg-config --libs gtk+-2.0 libvlc` -o wx_player
doc_libvlc_wx_player.cpp:14:14: fatal error: gtk/win_gtk.h: No such file or directory
From your earlier backtrace:
#31 0x00007ffff6f6e2fb in () at /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
you were previously compiling against GTK+3. Now you are trying to use GTK+2, which is not installed.

Either install it: sudo apt install libgtk2.0-dev
or try to build that sample code against GTK+3, changing 2 to 3 in those pkg-config calls.
unfortunately, that backtrace has nothing to do with the wx_player compilation since the backtrace comes from my own program and reports the error related to my class and I already have installed the gtk2.0-dev; however, I would like to focus on my program's problem and how to solve it since I would prefer to use my code.
I think the media player example doesn't suit my needs since I would like to have a general class which I can use from different panels to play and stop the mp3 without any GUI controls.

I'm trying to figure out how to solve the problem by following the doublemax's suggestion, but I have no success so far.

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to play and stop mp3 asynchronously

Post by doublemax » Sat Oct 26, 2019 4:27 pm

Move the player code to the main frame, add public methods for play/pause/stop etc. Then you can access it from all panels.
Use the source, Luke!

marcusbarnet
Experienced Solver
Experienced Solver
Posts: 71
Joined: Sat Jul 27, 2019 3:45 pm

Re: How to play and stop mp3 asynchronously

Post by marcusbarnet » Sat Oct 26, 2019 7:27 pm

doublemax, thank you a lot!
I follwed you suggestion and now it works.

I used the same pointer you told me to add during the creation of the panels last Sunday and I moved the functions to the main frame.

Code: Select all

// main class
class Isola02Frame : public wxFrame
{
public:
    Isola02Frame(const wxString& title);
    void ShowPage(int);

    void play_mp3(const char*);
    void stop_mp3();
    bool set_stop(bool);

protected:
     wxSimplebook* notebook;
     libvlc_instance_t *inst;
     libvlc_media_player_t *mp;
     libvlc_media_t *m;
     bool stop = false;
};
//isola02main.cpp
void Isola02Frame::ShowPage( int page )
{
  notebook->ChangeSelection(page);
}

bool Isola02Frame::set_stop(bool stop){
return stop;
}

void Isola02Frame::play_mp3(const char* path){


    // load the vlc engine
    inst = libvlc_new(0, NULL);
    printf("apro il file %d\n", inst);
    // create a new item
    m = libvlc_media_new_path(inst, path);
    // create a media play playing environment
    mp = libvlc_media_player_new_from_media(m);
    // no need to keep the media now
    libvlc_media_release(m);
    // play the media_player
    libvlc_media_player_play(mp);
    printf("playing.\n");



}

void Isola02Frame::stop_mp3(){

    stop = true;
    libvlc_media_player_stop(mp);
    // free the media_player
    libvlc_media_player_release(mp);
    libvlc_release(inst);

}

//firstpanel.cpp
 pointer->play_mp3("/home/robodyne/Project/audio/scegli-rifiuto.mp3");
 
 //secondpanel.cpp
 void secondpanel::OnBitmapButton2Click(wxCommandEvent& event)
{
pointer->stop_mp3();
}
I set the variables as protected as you suggested me, now it compiles and runs fine.
Really, doublemax, thank you, I learnt a new thing.

Post Reply