summaryrefslogtreecommitdiffstats
path: root/vlcwrapper/VLCLoader.cpp
blob: 813817f52591c4d919890e07d4dd1fd31c4d107f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "VLCLoader.h"
#include <QDebug>

VLCLoader *VLCLoader::s_instance = 0;

VLCLoader::VLCLoader()
{
	m_instance = 0;
	m_exception = new libvlc_exception_t();
	const char * const vlc_args[] = {
		"-I", "dummy",
		"--ignore-config",
		"--reset-plugins-cache",
		"--no-media-library",
		"--no-one-instance",
		"--no-osd",
		"--no-stats",
		"--no-video-title-show"
	};
	libvlc_exception_init(m_exception);
	m_instance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, m_exception);
	checkError();
}
VLCLoader::~VLCLoader()
{
	libvlc_release(m_instance);
	checkError();
	delete m_exception;
}
bool VLCLoader::checkError() const
{
	if (libvlc_exception_raised(m_exception)) {
		const char* error = libvlc_exception_get_message(m_exception);
		if (error)
			m_lastError = error;
		else
			m_lastError = QString();
		libvlc_exception_clear(m_exception);
		qDebug() << m_lastError;
		return false;
	} else {
		m_lastError = QString();
	}
	return true;
}
QString VLCLoader::lastError() const
{
	return m_lastError;
}
VLCLoader* VLCLoader::instance()
{
	if (!s_instance) {
		s_instance = new VLCLoader();
		if (!s_instance->lastError().isEmpty()) {
			delete s_instance;
			s_instance = 0;
		}
	}
	return s_instance;
}
libvlc_instance_t* VLCLoader::vlc()
{
	return m_instance;
}
libvlc_exception_t* VLCLoader::exception()
{
	return m_exception;
}
bool VLCLoader::toggleMute()
{
	libvlc_audio_toggle_mute(m_instance, m_exception);
	return checkError();
}
bool VLCLoader::setMute(bool muted)
{
	libvlc_audio_set_mute(m_instance, muted, m_exception);
	return checkError();
}
bool VLCLoader::setVolume(int volume)
{
	libvlc_audio_set_volume(m_instance, volume, m_exception);
	return checkError();
}
bool VLCLoader::isMuted() const
{
	bool retVal = libvlc_audio_get_mute(m_instance, m_exception) == 1;
	return checkError() && retVal;
}
int VLCLoader::volume() const
{
	int retVal = libvlc_audio_get_volume(m_instance, m_exception);
	if (checkError())
		return retVal;
	return -1;
}