Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I designd a WinForm, using C#. I want play a media, so I used VLC. I invoked it by P/invoke.
At first, all are right. But after I play a movie for a while. All event didn't work, include the butten for closing window.
Here is the code
#include "stdafx.h"
#include "MagicPlayer.h"
#include <vlc\vlc.h>

libvlc_instance_t *inst = 0;
libvlc_media_t *m = 0;
libvlc_media_player_t *mp = 0;
libvlc_time_t movie_time = 0;

int VLC_load(void *handle)
{
	inst = libvlc_new(0, NULL);        /* Load the VLC engine */
	if (inst == NULL)
		return 1;
	mp = libvlc_media_player_new(inst);
	libvlc_media_player_set_hwnd(mp, handle); /* Make the video played in the window */
	return 0;
}

int VLC_pause()
{
	if (inst == NULL)
		return 1;
	if (mp == 0)
		return 1;
	if (m == 0)
		return 1;
	if (libvlc_media_player_get_state(mp) == libvlc_Playing)
	{
		movie_time = libvlc_media_player_get_time(mp);
		libvlc_media_player_pause(mp);
		return 0;
	}
	else if (libvlc_media_player_get_state(mp) == libvlc_Paused)
	{
		libvlc_media_player_pause(mp);
		return 0;
	}
	
	return 0;
}

int VLC_play(char *file_name)
{
	if (inst == NULL)
		return 1;
	if (mp == NULL)
		return 1;
	m = libvlc_media_new_path(inst, file_name);
	libvlc_media_player_set_media(mp, m);
	if (m == NULL)
		return 2;
	return libvlc_media_player_play(mp);
}

int VLC_go_back_to_last_stop()
{
	if (mp == NULL)
		return 1;
	if (libvlc_media_player_get_state(mp) == libvlc_Playing){
		libvlc_media_player_pause(mp);
		libvlc_media_player_set_time(mp, movie_time);
		return 0;
	}
	
	return 0;
}

int VLC_release()
{
	if (mp != 0)
		libvlc_media_player_release(mp);
	if (m != 0)
		libvlc_media_release(m);
	if (inst != 0)
		libvlc_release(inst);
	return 0;
}
Posted
Updated 18-May-14 12:34pm
v2
Comments
enhzflep 19-May-14 0:42am    
Other people appear to have done it successfully, perhaps some of them have helpful tips.
I found seemingly good results after doing a google search for "vlc in winforms app"

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900