wxMediaCtrl Load - from memory instead of file

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
TexasJimbo
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun May 04, 2008 6:41 pm

wxMediaCtrl Load - from memory instead of file

Post by TexasJimbo »

The load method of wxMediaCtrl takes a file name argument.
I want to know if there is a way to somehow redirect this to memory.

I am storing my mp3 files in a database.
In order to play a clip, I would have to extract from the database and write to disk the individual clip, then call the wxMediaCtrl::Load method to load the file in order to play it.
Since I have to extract the file from the database - I will already have the contents in a memory buffer...I would rather load from the memory buffer because it would be faster if I could skip writing to disk only to have to read it again...

Is this possible?
Could someone please provide a brief code clip on how I would do this if it were possible?

Thanks in advance.
Jim
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxMediaCtrl Load - from memory instead of file

Post by catalin »

There are wxMediaCtrl::Load( const wxURI& uri ) and wxMediaCtrl::LoadURI( const wxString& fileName ) and undocumented constructor and Create() that take wxURI argument.
These should work with something like "memory:myfile.mp3". See Virtual File System.
I've never used it and I can't give you a code snippet, but I did read about this being used so I can only advice you to try it.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxMediaCtrl Load - from memory instead of file

Post by doublemax »

Good idea, catalin, but i don't think this will work. At least under Windows, the filename is directly passed to the underlying ActiveMovie/WMP control which doesn't know about wxWidgets filesystems.

I think this is not possible at all with wxMediaCtrl.
Use the source, Luke!
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxMediaCtrl Load - from memory instead of file

Post by catalin »

doublemax wrote:i don't think this will work. At least under Windows, the filename is directly passed to the underlying ActiveMovie/WMP control which doesn't know about wxWidgets filesystems.
May be, I really don't know how wx-VFS works, but shouldn't something like wxFileSystem::AddHandler( new wxMemoryFSHandler ) register somehow a relevant uri handler? I did not check any code, just a quick, late night thought..
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxMediaCtrl Load - from memory instead of file

Post by doublemax »

May be, I really don't know how wx-VFS works, but shouldn't something like wxFileSystem::AddHandler( new wxMemoryFSHandler ) register somehow a relevant uri handler?
Yes, but this works only inside wxWidgets and for classes that are written to support it.

But wxWidgets has no own audio/video codecs etc. wxMediaCtrl just embeds an ActiveX control under windows and Windows itself can't deal with paths like "memory:file.mp3" or something like this.
Use the source, Luke!
TexasJimbo
Knows some wx things
Knows some wx things
Posts: 30
Joined: Sun May 04, 2008 6:41 pm

Re: wxMediaCtrl Load - from memory instead of file

Post by TexasJimbo »

Thanks for the replies. I suspected I could not do what I wanted to do. I also searched for a class that implemented simple functionality of loading and playing a mp3 audio clip from a buffer so I could bypass wxMediaCtrl - but couldn't find anything that was simple...I don't really understand the techs that go with audio programming (like sample rates, etc) and wanted to keep it simple...like here is the buffer already loaded with mp3 data now just play it.. :D Oh well! Thanks again!
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxMediaCtrl Load - from memory instead of file

Post by doublemax »

Depending on your platform and licence requirements, i'm sure there are several solutions.

If your application is non-commercial, check http://www.fmod.org
Use the source, Luke!
papayrus
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 204
Joined: Tue Jan 25, 2011 4:55 pm
Location: USA

Re: wxMediaCtrl Load - from memory instead of file

Post by papayrus »

How about this? Unless I am way off here. It is not wxWidgets but it plays an MP3.

Code: Select all

mciSendString(TEXT("open sounds\\dualtrax&nagz-neverland.mp3"),NULL,0,NULL);
    mciSendString(TEXT("play sounds\\dualtrax&nagz-neverland.mp3"), NULL, 0, 0);
then to close it

Code: Select all

mciSendString(TEXT("stop sounds\\dualtrax&nagz-neverland.mp3"), NULL, 0, 0);
    mciSendString(TEXT("close sounds\\dualtrax&nagz-neverland.mp3"), NULL, 0, 0);
Post Reply