Page 1 of 1

Libvlc with C++

Posted: 28 Nov 2014 14:16
by Magarf
Hello everyone,

Well, I am very new to this, so pardon me if I am asking some very easy/naive questions...
What I am basically trying to do is to play a video file through the VLC media player from a C++ program that I have written on Visual studio 2010. Once I run the program I want it to display a window that allows me to browse and choose the video I want to play, then the video would play in VLC.
I figured a starting point might be playing the video with VLC from C++ (by giving it the specific URL) first and then try to do the browsing part.

But now I have two questions:
1- Would that browsing part be doable in VLC/Visual studio? Or for VLC to work through C++ you have to provide the URL always in the code?
2- I found a code that should be doing that very simple task (playing the video with VLC from C++ by giving it the specific URL), the code would compile without any errors but when I try to run it, it crashes with the following error:
" Unhandled exception at 0x00905a4d in vlcplayer.exe: 0xC0000005: Access violation reading location 0x00905a4d."

Now this the code I am using:

// vlcplayer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <vlc/vlc.h>

using namespace std;

int main(int argc, char **argv)
{
libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;

inst = libvlc_new(0, NULL);

// create a new item
m = libvlc_media_new_path(inst, "Wildlife.wmv");

// 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);

Sleep(10);

// stop playing
libvlc_media_player_stop(mp);

// free the media_player
libvlc_media_player_release(mp);

libvlc_release(inst);


return 0;
}

After many trials, I think the the problem is with this line :
inst = libvlc_new(0, NULL);
Loading the VLC media player is not working correctly or this statement returns null.

It would also insert a breakpoint at line 555 in file crtexe.c which is:
mainret = main(argc, argv, envp);

P.S: I am using VLC Player version 2.0.6

Would you have any ideas or suggestions about how I can solve that?
I would really appreciate your help...

Thanks.
Best regards,
Maha

Re: Libvlc with C++

Posted: 01 Dec 2014 10:06
by Jo2003
To be honest I haven't understood all of your needs.

Having a look to the C example you should always check if the things you are creating with new are really created:

Code: Select all

... libvlc_instance_t *inst; inst = libvlc_new(0, NULL); if (inst != NULL) { ... }
When running this simple test program the needed libraries / plugins are reachable be the program (e.g. libvlc.dll and libvlccore.dll are in same folder as the exe file and the plugins folder is also located there)?

Best regards,
Jörg