libVLC in pb (Windows Only)

Share your advanced PureBasic knowledge/code with the community.
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

libVLC in pb (Windows Only)

Post by CELTIC88 »

:D hola

libVLC is the core engine and the interface to the multimedia framework on which VLC media player is based.

libVLC is modularized into hundreds of plugins, which may be loaded at runtime. This architecture provides great flexibility to developers (both VLC devs and devs consuming the library). It allows developers to create a wide range of multimedia applications using the VLC features.....
more ...https://www.videolan.org/vlc/libvlc.html

API Documentation https://videolan.videolan.me/vlc/group__libvlc.html

Requirements
vlc media player https://www.videolan.org/vlc/

vlc.pb
https://www.mediafire.com/file/jkqzr8sf ... b.zip/file

Image

:wink:
interested in Cybersecurity..
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: libVLC in pb

Post by Mijikai »

Thank you CELTIC88, thats pretty cool im sure it will help me coding a subbing tool 8)
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: libVLC in pb

Post by Marc56us »

Very interesting.
I've dreamed several times to use the VLC API instead of Fmodex for my little webradio program (function: network stream in VLC), but I gave up because of the amount of documentation.
:wink:
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libVLC in pb

Post by infratec »

A lot of work.
Thank you very much!

At the first try of the example, I saw nothing.
Then I noticed, that vlc_loadlibvlc() returns nothing.

So I modified it a bit:

Code: Select all

Procedure.i vlc_loadlibvlc(libvlcpath.s)
	Protected cd.s = GetCurrentDirectory()
	SetCurrentDirectory(GetPathPart(libvlcpath))
	vlc_libisloaded = libvlc_loadapi(OpenLibrary(#PB_Any, GetFilePart(libvlcpath)))
	SetCurrentDirectory(cd)
	
	ProcedureReturn vlc_libisloaded 
	
EndProcedure
And modified the example:

Code: Select all

IncludeFile "vlc.pb"

CompilerIf Not #PB_Compiler_Thread
  CompilerError "You have to enable thread save!"
CompilerEndIf

If vlc_loadlibvlc("C:\Program Files\VideoLAN\VLC\libvlc.dll") ; select vlc dll
  OpenWindow(0, 0, 0, 800, 700, "")
  CanvasGadget(1, 0, 0, 800, 700)
  vlc = vlc_createplayer(GadgetID(1), #True)
  vlc_setvolume(vlc, 80)
  ; vlc_play(vlc,"https://www.youtube.com/watch?v=sOlP10fDclE&ab_channel=ClassicMrBean") ; not work for youtube video
  vlc_addplaylist(vlc,"https://www.youtube.com/watch?v=sOlP10fDclE&ab_channel=ClassicMrBean")
  vlc_playplaylist(vlc)
  While WaitWindowEvent() <> #PB_Event_CloseWindow
  Wend
  vlc_freeplayer(vlc)
Else
  Debug "Was not able to load libvlc.dll"
EndIf
So I was able to see that the dll was not loaded, but the path was correct.
Then I remebered that I used PB x86. So the dll was not usable.
I started it with PB x64 and ...
it worked.

Btw.: the CompilerIf should be placed in vlc.pb, which should be a vlc.pbi :wink:

Oh and you should use

Code: Select all

CompilerIf #PB_Compiler_IsMainFile
  EnableExplicit
CompilerEndIf
In your files, else you 'force' a user to use EnableExplicit. :mrgreen:
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: libVLC in pb

Post by vwidmer »

I get a "Invalid memory access" on

Procedure.s vlc_stringformat(fmt,va_list)
Protected sret.s
Protected c = snprintf(0,0,fmt,va_list)
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: libVLC in pb

Post by collectordave »

Hi

How do I get this to work on the MAC?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: libVLC in pb

Post by fsw »

collectordave wrote: Sun Sep 05, 2021 3:42 pm How do I get this to work on the MAC?
Maybe this helps: viewtopic.php?f=13&t=70862

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: libVLC in pb

Post by Kwai chang caine »

Works perfectly here :D
Thanks a lot my friend for sharing this great job 8)
ImageThe happiness is a road...
Not a destination
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: libVLC in pb

Post by collectordave »

Finally got it to work on macOS Big Sur!

Used vlc 2.2.8 and changed a few bits.

Now I just need to sort out Play, Pause, Stop.

I am only using this to play my audio files which are right old mix.

I think the sequence I need is to:-

1. Create Player
2. Play the song
3. When stopping
Stop the player
Free the player

Then wind back to step 1 to play the next song.

If I have some success I will post back here.

Hopefully I can wait for InitSound() on Big Sur to be fixed.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: libVLC in pb

Post by collectordave »

Got it working playing my .ogg and .mp3 and added to my audio player.

Just want to read Artist and title from the meta data if possible.

Tried:-

Code: Select all

 vlc_play(Myvlc,"File:///" + FileName)
  
  
  Debug "Meta Data"
  Debug vlc_getmeta(Myvlc,#libvlc_meta_Artist)
  Debug "End Meta"

The song plays straight away no bother but I get no meta data.

What am I missing?

PS if I change the line to

Debug vlc_getmeta(Myvlc,#libvlc_meta_Title)

It returns the Filename
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: libVLC in pb

Post by collectordave »

Lovely.

Spurred on by InitSound() not working on Big Sur

Tried this and got it working for playing MP3, .ogg and FLAC.

Downloaded VLC 2.2.8 then pulled out the libs and plugins etc.

Had to change one bit in the libvlc.pb

I now have the player start,Stop, Pause etc and volume control and a status line to display time played.

Very scrappy GUI as just trying it out.

Code still has my debug statements in as well.

Works on MAC Big Sur.

I think you will need to change the CreatePlayer() procedure to get it to work on windows and or linux.

The whole thing can be downloaded here:-https://www.mediafire.com/file/zsi4cxg4 ... t.zip/file

This includes the libs etc

In the download there is a TI Media.db file this can be deleted just me trying to get other things working.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Re: libVLC in pb

Post by Inner »

I'm guessing this is for MacOS?

https://paste.pics/157d4a2e48de397a37963f8d9972a8ce

Judging from the error above, or should I download from somewhere :?: the Windows .libs and replace them.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: libVLC in pb

Post by collectordave »

"Works on MAC Big Sur."

I have not done the same for windows .

I downloaded VLC 2.2.8. and extracted the libs and plugins.

Replace these with the ones for the version of windows/vlc you are using and modify the createplayer routine.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
RSrole
User
User
Posts: 32
Joined: Fri Apr 29, 2022 8:27 pm

Re: libVLC in pb

Post by RSrole »

This example is excellent! Thank you for providing it.

I've got it working for a basic video player, but I need to get the video and audio data so I can output to a SDI video card. The libvlc api makes that possible with a set callbacks routine. However I'm getting crashes in the first callback. I'm sure that I don't properly know how to define the call back.

The C (c++?) call back looks like this:
static void *lock(void *data, void **p_pixels)
{
struct ctx *ctx = data;

SDL_LockMutex(ctx->mutex);
SDL_LockSurface(ctx->surf);
*p_pixels = ctx->surf->pixels;
return NULL; /* picture identifier, not needed here */
}

I may or may not use SDL for this project. Most importantly I need the pixel data. Anyone know how to translate this to Purebasic?

Thanks,
Russ
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libVLC in pb

Post by infratec »

Don't know anything about the SDL stuff, but my general solution would look like this:

Code: Select all

ProcedureC.i lock(*Data, *p_pixels)
  Protected *ctx.ctx
  
  *ctx = *Data
  
  SDL_LockMutex(*ctx\mutex)
  SDL_LockSurface(*ctx\surf)
  PokeI(*p_pixels, *ctx\surf\pixels)
  
  ProcedureReturn #Null
  
EndProcedure
Last edited by infratec on Fri Apr 29, 2022 10:04 pm, edited 1 time in total.
Post Reply