#include "VLCLoader.h" #include 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; }