void libvlc_exception_clear( libvlc_exception_t *p_exception ) { if( NULL == p_exception ) return; p_exception->b_raised = 0; libvlc_clearerr (); }
void VlcLib::print_error() { // Outputs libvlc error message if there is any if(libvlc_errmsg()) { Debug::error() << "[libvlc] " << "Error:" << libvlc_errmsg(); libvlc_clearerr(); } }
VlcError *VlcError::create() noexcept { VlcError *e = nullptr; if (libvlc_errmsg()) e = new VlcError(); libvlc_clearerr(); return e; }
// Method for checking VLC exceptions bool VLCVideoWrapper::checkVLCError (const std::string& message) { bool error(false); // check if there was an error if (libvlc_errmsg() != NULL) { // printing out what/where the exception happend (message should contain this info!) SWARNING << "VLC error occured while : " << message << ". Error: " << libvlc_errmsg() << std::endl; error = true; } libvlc_clearerr(); return error; }
void VlcVideoWidget::VlcEventHandler(const libvlc_event_t *event, void *widget) { // Return on certain events switch (event->type) { case libvlc_MediaPlayerTitleChanged: case libvlc_MediaMetaChanged: case libvlc_MediaSubItemAdded: case libvlc_MediaDurationChanged: case libvlc_MediaParsedChanged: case libvlc_MediaFreed: return; default: break; } VlcVideoWidget* w = reinterpret_cast<VlcVideoWidget*>(widget); w->statusAccess.lock(); switch (event->type) { // Media player events case libvlc_MediaPlayerMediaChanged: { w->DetermineVideoSize(); break; } case libvlc_MediaPlayerOpening: { w->DetermineVideoSize(); break; } case libvlc_MediaPlayerBuffering: { w->DetermineVideoSize(); w->status.buffering = true; w->status.playing = false; w->status.paused = false; w->status.stopped = false; w->status.change = PlayerStatus::MediaState; break; } case libvlc_MediaPlayerPlaying: { w->DetermineVideoSize(); w->status.buffering = false; w->status.playing = true; w->status.paused = false; w->status.stopped = false; w->status.change = PlayerStatus::MediaState; break; } case libvlc_MediaPlayerPaused: { w->status.buffering = false; w->status.playing = false; w->status.paused = true; w->status.stopped = false; w->status.change = PlayerStatus::MediaState; break; } case libvlc_MediaPlayerStopped: { w->status.buffering = false; w->status.playing = false; w->status.paused = false; w->status.stopped = true; w->status.time = 0.0; w->status.change = PlayerStatus::MediaState; break; } case libvlc_MediaPlayerEncounteredError: { std::string err = "Unknown error"; if (libvlc_errmsg()) { err = libvlc_errmsg(); libvlc_clearerr(); } w->status.error = QString("Media player encountered error: ") + err.c_str(); w->status.change = PlayerStatus::PlayerError; break; } case libvlc_MediaPlayerTimeChanged: { w->DetermineVideoSize(); w->status.time = event->u.media_player_time_changed.new_time; w->status.change = PlayerStatus::MediaTime; break; } case libvlc_MediaPlayerPositionChanged: { w->DetermineVideoSize(); w->status.position = event->u.media_player_position_changed.new_position; w->status.change = PlayerStatus::MediaTime; break; } case libvlc_MediaPlayerSeekableChanged: { w->DetermineVideoSize(); w->status.isSeekable = (event->u.media_player_seekable_changed.new_seekable > 0 ? true : false); w->status.change = PlayerStatus::MediaProperty; break; } case libvlc_MediaPlayerPausableChanged: { w->DetermineVideoSize(); w->status.isPausable = (event->u.media_player_pausable_changed.new_pausable > 0 ? true : false); w->status.change = PlayerStatus::MediaProperty; break; } case libvlc_MediaPlayerLengthChanged: { w->DetermineVideoSize(); w->status.lenght = event->u.media_player_length_changed.new_length; w->status.change = PlayerStatus::MediaTime; break; } // Media events case libvlc_MediaStateChanged: { if (event->u.media_state_changed.new_state == libvlc_Buffering) { w->DetermineVideoSize(); w->status.buffering = true; w->status.playing = false; w->status.paused = false; w->status.stopped = false; w->status.change = PlayerStatus::MediaState; } if (event->u.media_state_changed.new_state == libvlc_Ended) { w->status.doStop = true; w->status.doNotPlayAfterRestart = true; w->status.doRestart = true; w->status.buffering = false; w->status.playing = false; w->status.paused = false; w->status.stopped = true; w->status.time = 0.0; w->status.change = PlayerStatus::MediaState; } break; } // Default default: break; } w->statusAccess.unlock(); }
bool VlcVideoWidget::OpenSource(const QString &videoUrl) { if (!Initialized()) return false; // We need to prepend file:// if this is a path on disk. QString source = videoUrl; AssetAPI::AssetRefType sourceType = AssetAPI::ParseAssetRef(source); if ((sourceType == AssetAPI::AssetRefLocalPath || sourceType == AssetAPI::AssetRefLocalUrl)) { if (source.startsWith("file://", Qt::CaseInsensitive)) source = source.mid(7); vlcMedia_ = libvlc_media_new_path(vlcInstance_, source.toUtf8().constData()); } else vlcMedia_ = libvlc_media_new_location(vlcInstance_, source.toUtf8().constData()); if (vlcMedia_ == 0) { LogError("VlcVideoWidget: Could not load media from '" + videoUrl + "'"); return false; } libvlc_event_manager_t *em = libvlc_media_event_manager(vlcMedia_); libvlc_event_attach(em, libvlc_MediaMetaChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaSubItemAdded, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaDurationChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaParsedChanged, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaFreed, &VlcEventHandler, this); libvlc_event_attach(em, libvlc_MediaStateChanged, &VlcEventHandler, this); libvlc_state_t state = libvlc_media_get_state(vlcMedia_); if (state != libvlc_Error) { // Reset playback Stop(); hasVideoOut_ = false; libvlc_media_player_set_media(vlcPlayer_, vlcMedia_); statusAccess.lock(); status.Reset(); status.source = videoUrl; status.change = PlayerStatus::MediaSource; statusAccess.unlock(); return true; } else { std::string err = "Unknown error"; if (libvlc_errmsg()) { err = libvlc_errmsg(); libvlc_clearerr(); } LogError("VlcVideoWidget: " + err); } return false; }