// Initialization bool MediaPlayer::initialize( const std::string &url ) { LDEBUG( "vlc", "Initialize: url=%s", url.c_str() ); // Create media from url libvlc_media_t *m=libvlc_media_new_path( instance(), url.c_str() ); if (!m) { LERROR( "vlc", "Cannot initialize new media from url: url=%s", url.c_str() ); return false; } // Add common parameters libvlc_media_add_option( m, "verbose=1000" ); libvlc_media_add_option( m, "no-osd" ); libvlc_media_add_option( m, "ffmpeg-hw" ); // Create a media player playing environement _mp = libvlc_media_player_new_from_media(m); if (!_mp) { libvlc_media_release (m); LERROR( "vlc", "Cannot create media player from url: url=%s", url.c_str() ); return false; } // No need to keep the media now libvlc_media_release (m); { // Set WindowID VideoDescription desc; if (getVideoDescription( desc )) { #ifndef _WIN32 libvlc_media_player_set_xwindow( _mp, desc.winID ); #else libvlc_media_player_set_hwnd( _mp, desc ); #endif } } { // Attach to stop asyn events libvlc_event_manager_t *mgr=libvlc_media_player_event_manager( _mp ); libvlc_event_attach( mgr, libvlc_MediaPlayerEndReached, vlcCallback, this ); } return true; }
static bool media_play() { int64_t ms_media_length; int s_length; libvlc_media_parse(media_handle); s_length = (int)(ceil(libvlc_media_get_duration(media_handle)/1000)); current_media_duration = s_length; if(s_length == -1) return false; libvlc_media_player_set_hwnd(mediaplay,(void *)hwnd_handle); libvlc_media_player_play(mediaplay); sleep(s_length); libvlc_media_player_stop(mediaplay); libvlc_media_release(media_handle); return true; }
void VlcMediaPlayer::play() { if (!_vlcMediaPlayer) return; if (_videoWidget) { _currentWId = _videoWidget->request(); } else { _currentWId = 0; } /* Get our media instance to use our window */ if (_currentWId) { #if defined(Q_OS_WIN32) libvlc_media_player_set_hwnd(_vlcMediaPlayer, _currentWId); #elif defined(Q_OS_MAC) libvlc_media_player_set_nsobject(_vlcMediaPlayer, (void *)_currentWId); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(_vlcMediaPlayer, _currentWId); #endif } libvlc_media_player_play(_vlcMediaPlayer); VlcError::errmsg(); }
void Mwindow::openFile() { /* The basic file-select box */ QString fileOpen = QFileDialog::getOpenFileName(this, tr("Load a file"), "~"); /* Stop if something is playing */ if (vlcPlayer && libvlc_media_player_is_playing(vlcPlayer)) stop(); /* Create a new Media */ libvlc_media_t *vlcMedia = libvlc_media_new_path(vlcInstance, qtu(fileOpen)); if (!vlcMedia) return; /* Create a new libvlc player */ vlcPlayer = libvlc_media_player_new_from_media (vlcMedia); /* Release the media */ libvlc_media_release(vlcMedia); /* Integrate the video in the interface */ #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(vlcPlayer, (void *)videoWidget->winId()); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(vlcPlayer, videoWidget->winId()); #endif /* And start playback */ libvlc_media_player_play (vlcPlayer); /* Update playback button */ playBut->setText("Pause"); }
void VLCHolderWnd::LibVlcDetach() { if( VP() ) libvlc_media_player_set_hwnd( VP()->get_mp(), 0); MouseHook( false ); }
void CameraWnd::playFile(QString file) { //the file has to be in one of the following formats /perhaps a little bit outdated) /* [file://]filename Plain media file http://ip:port/file HTTP URL ftp://ip:port/file FTP URL mms://ip:port/file MMS URL screen:// Screen capture [dvd://][device][@raw_device] DVD device [vcd://][device] VCD device [cdda://][device] Audio CD device udp:[[<source address>]@[<bind address>][:<bind port>]] */ /* Create a new LibVLC media descriptor */ _m = libvlc_media_new_path(_vlcinstance, file.toAscii()); //_m = libvlc_media_new (_vlcinstance, file.toAscii(), &_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. //raise(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. libvlc_media_player_set_media (_mp, _m); //libvlc_media_player_set_media (_mp, _m, &_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. //raise(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. // /!\ Please note /!\ // // passing the widget to the lib shows vlc at which position it should show up // vlc automatically resizes the video to the ?given size of the widget // and it even resizes it, if the size changes at the playing /* Get our media instance to use our window */ #if defined(Q_OS_WIN) //libvlc_media_player_set_drawable(_mp, reinterpret_cast<unsigned int>(_videoWidget->winId())); //libvlc_media_player_set_drawable(_mp, reinterpret_cast<unsigned int>(_videoWidget->winId()), &_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0. libvlc_media_player_set_hwnd(_mp, _videoWidget->winId() ); // for vlc 1.0 #elif defined(Q_OS_MAC) libvlc_media_player_set_drawable(_mp, _videoWidget->winId()); //libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0. //libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); // for vlc 1.0 #else //Linux //[20101201 Ondrej Spilka] obsolete call on libVLC >=1.1.5 //libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep ); //libvlc_media_player_set_xwindow(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0 /* again note X11 handle on Linux is needed winID() returns X11 handle when QX11EmbedContainer us used */ int windid = _videoWidget->winId(); libvlc_media_player_set_xwindow (_mp, windid ); #endif //raise(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. /* Play */ libvlc_media_player_play (_mp); //libvlc_media_player_play (_mp, &_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0. //raise(&_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0. _isPlaying=true; }
bool VlcVideoPlayer::loadVideo(const char* path) { if(vlcMedia = libvlc_media_new_path(vlcInstance, path)) { libvlc_media_player_set_media(vlcPlayer, vlcMedia); libvlc_media_release(vlcMedia); // Needed for mixing VLC and wxWidgets. // Needs to be after above calls, or else bug with stop button! libvlc_media_player_set_hwnd( vlcPlayer, reinterpret_cast<void *> ( (HWND)this->GetHandle() ) ); /// @todo ???? // Stuff //libvlc_media_player_next_frame(vlcPlayer); //libvlc_video_set_format(vlcPlayer); _DEBUG_ DSTREAM << "Loaded video file." << endl; } else { _DEBUG_ DSTREAM << "Can't load media from path" << endl; wxMessageDialog (this, "Can't load media from path"); return false; } return true; // Didn't fails loading. }
void VLCMainwindow::openFile() { /* Just the basic file-select box */ QString fileOpen = QFileDialog::getOpenFileName(this,tr("Load a file"), "~"); fileOpen.replace("/", "\\"); /* Stop if something is playing */ if( vlcPlayer && libvlc_media_player_is_playing(vlcPlayer) ) stop(); /* New Media */ libvlc_media_t *vlcMedia = libvlc_media_new_path(vlcObject,qtu(fileOpen)); if( !vlcMedia ) return; vlcPlayer = libvlc_media_player_new_from_media (vlcMedia); libvlc_media_release(vlcMedia); /* Integrate the video in the interface */ #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(vlcPlayer, videoWidget->winId()); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(vlcPlayer, videoWidget->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(vlcPlayer, videoWidget->winId()); #endif //int windid = videoWidget->winId(); //libvlc_media_player_set_xwindow (vlcPlayer, windid ); /* And play */ libvlc_media_player_play (vlcPlayer); //Set vars and text correctly playBut->setText("Pause"); }
void MainWindow::initVLC() { #ifdef __WXGTK__ libvlc_media_player_set_xwindow(media_player, GET_XID(this->player_widget)); #else libvlc_media_player_set_hwnd(media_player, this->player_widget->GetHandle()); #endif }
static void widget_on_realize(GtkWidget *widget, gpointer user_data) { GtkVlcPlayer *player = GTK_VLC_PLAYER(user_data); GdkWindow *window = gtk_widget_get_window(widget); libvlc_media_player_set_hwnd(player->priv->media_player, GDK_WINDOW_HWND(window)); }
void LiveWidget::setupRenderTarget(bool windowMode) { #if defined(Q_OS_WIN) libvlc_media_player_set_hwnd(this->vlcMediaPlayer, (windowMode == true) ? this->liveDialog->getRenderTarget()->winId() : this->labelLive->winId()); #elif defined(Q_OS_MAC) libvlc_media_player_set_nsobject(this->vlcMediaPlayer, (windowMode == true) ? (void*)this->liveDialog->getRenderTarget()->winId() : (void*)this->labelLive->winId()); #elif defined(Q_OS_LINUX) libvlc_media_player_set_xwindow(this->vlcMediaPlayer, (windowMode == true) ? this->liveDialog->getRenderTarget()->winId() : this->labelLive->winId()); #endif }
int mediacontrol_set_visual( mediacontrol_Instance *self, WINDOWHANDLE visual_id, mediacontrol_Exception *exception ) { mediacontrol_exception_init( exception ); #ifdef WIN32 libvlc_media_player_set_hwnd( self->p_media_player, visual_id ); #else libvlc_media_player_set_xwindow( self->p_media_player, visual_id ); #endif return true; }
void VLCVideoWidgetDelegator::attachVLCRenderContext( QWidget * parent){ if( m_player != Nullptr && m_widgetInstance == Nullptr ){ m_widgetInstance = new QWidget( parent ); #if defined(Q_OS_MAC) libvlc_media_player_set_nsobject(m_player, m_widgetInstance->winId()); #elif defined(Q_OS_UNIX) libvlc_media_player_set_xwindow(m_player, m_widgetInstance->winId()); #elif defined(Q_OS_WIN) libvlc_media_player_set_hwnd(m_player, m_widgetInstance->winId()); #endif } }
bool CAVPlayer::Play(const std::string &strPath) { if (! m_pVLC_Inst) {// 如果播放引擎没有创建,则创建它 Init(); } if(strPath.empty() || ! m_pVLC_Inst) {// 如果链接地址为空,或播放引擎没创建,则直接返回 return false; } // 验证地址是网络地址,还是本地地址 bool bURL = false; bURL = IsURL(strPath); Stop(); bool bRet = false; libvlc_media_t *m = NULL; if (bURL) {// 网络路径 m = libvlc_media_new_location(m_pVLC_Inst, strPath.c_str()); } else {// 本地路径 m = libvlc_media_new_path(m_pVLC_Inst, strPath.c_str()); } if (m) { if (m_pVLC_Player = libvlc_media_player_new_from_media(m)) { libvlc_media_player_set_hwnd(m_pVLC_Player, m_hWnd); libvlc_media_player_play(m_pVLC_Player); m_bStatus = em_play;//播放状态 // 事件管理 libvlc_event_manager_t *vlc_evt_man = libvlc_media_player_event_manager(m_pVLC_Player); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPlaying,CAVPlayer::OnVLC_Event, this); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPositionChanged, CAVPlayer::OnVLC_Event, this); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerEndReached, CAVPlayer::OnVLC_Event, this); bRet = true; } libvlc_media_release(m); } return bRet; }
void VLCHolderWnd::LibVlcDetach() { if(_p_md){ DetachFromLibVlcEventSystem(); libvlc_media_player_set_hwnd(_p_md, 0); _p_md=0; } if(_hMouseHook){ UnhookWindowsHookEx(_hMouseHook); _hMouseHook = 0; } }
void VLCWrapper::setWindow (WId winId) { libvlc_media_player_t *m = Player_.get (); int time = libvlc_media_player_get_time (m); libvlc_media_player_stop (m); #ifdef Q_OS_WIN32 libvlc_media_player_set_hwnd (m, winId); #endif #ifdef Q_WS_X11 libvlc_media_player_set_xwindow (m, winId); #endif libvlc_media_player_play (m); libvlc_media_player_set_time (m, time); }
/***************************************************************************** * VlcPlugin playlist replacement methods *****************************************************************************/ void VlcPlugin::set_player_window( libvlc_exception_t *ex ) { #ifdef XP_UNIX libvlc_media_player_set_xwindow(libvlc_media_player, (libvlc_drawable_t)getVideoWindow(), ex); #endif #ifdef XP_MACOSX // XXX FIXME insert appropriate call here #endif #ifdef XP_WIN libvlc_media_player_set_hwnd(libvlc_media_player, getWindow().window, ex); #endif }
void VlcMediaPlayer::setVideoWidgetId(const WId &id) { _widgetId = id; /* Get our media instance to use our window */ if (_vlcMediaPlayer) { #if defined(Q_WS_WIN) libvlc_media_player_set_hwnd(_vlcMediaPlayer, _widgetId); #elif defined(Q_WS_MAC) libvlc_media_player_set_nsobject(_vlcMediaPlayer, (void *)_widgetId); #else // Q_WS_X11 libvlc_media_player_set_xwindow(_vlcMediaPlayer, _widgetId); #endif // Q_WS_* VlcError::errmsg(); } }
void VLCHolderWnd::LibVlcAttach(libvlc_media_player_t* p_md) { if(!_p_md){ _p_md = p_md; libvlc_media_player_set_hwnd(p_md, getHWND()); libvlc_event_manager_t* em = libvlc_media_player_event_manager(_p_md); if(em){ //We need set hook to catch doubleclicking (to switch to fullscreen and vice versa). //But libvlc media window not exist yet, //and we don't know when it will be created, nor ThreadId of it. //So we try catch first libvlc_MediaPlayerPositionChanged event, //(suppose wnd will be created to that moment)), //and then try set mouse hook. _LibVlcESAttached = 0==libvlc_event_attach(em, libvlc_MediaPlayerPositionChanged, OnLibVlcEvent, this); } } }
void SMActionVideoVLC::go() { if (getStatus() != STATUS_PLAY && getStatus() != STATUS_ERROR) { SMAction::go(); /* Get our media instance to use our window */ #if defined(Q_OS_WIN) libvlc_media_player_set_hwnd(_mp, (void*)getView()->winId()); #elif defined(Q_OS_MAC) // libvlc_media_player_set_drawable(_mp, getView()->winId()));//_videoWidget->winId()); #else //Linux /* again note X11 handle on Linux is needed winID() returns X11 handle when QX11EmbedContainer us used */ // int windid = getView()->winId();//_videoWidget->winId(); // libvlc_media_player_set_xwindow (_mp, windid ); #endif /* Play */ libvlc_media_player_play (_mp); poller->start(100); //start timer to trigger every 100 ms the updateInterface slot } }
VideoWindow::VideoWindow(Context *context) : GcWindow(context), context(context), m_MediaChanged(false) { setControls(NULL); setProperty("color", QColor(Qt::black)); QHBoxLayout *layout = new QHBoxLayout(); setLayout(layout); init = true; // assume initialisation was ok ... #ifdef GC_VIDEO_VLC // // USE VLC VIDEOPLAYER // #if QT_VERSION >= 0x050000 #warning "WARNING: Please ensure the VLC QT4 plugin (gui/libqt4_plugin) is NOT available as it will cause GC to crash." #endif // config parameters to libvlc const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ "--disable-screensaver", /* disable screensaver during playback */ #ifdef Q_OS_LINUX "--no-xlib", // avoid xlib thread error messages #endif //"--verbose=-1", // -1 = no output at all //"--quiet" }; /* create an exception handler */ //libvlc_exception_init(&exceptions); //vlc_exceptions(&exceptions); /* Load the VLC engine */ inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); //vlc_exceptions(&exceptions); /* Create a new item */ if (inst) { // if vlc doesn't initialise don't even try! m = NULL; //vlc_exceptions(&exceptions); /* Create a media player playing environement */ mp = libvlc_media_player_new (inst); //vlc_exceptions(&exceptions); //vlc_exceptions(&exceptions); /* This is a non working code that show how to hooks into a window, * if we have a window around */ #ifdef Q_OS_LINUX #if QT_VERSION > 0x50000 x11Container = new QWidget(this); //XXX PORT TO 5.1 BROKEN CODE XXX #else x11Container = new QX11EmbedContainer(this); #endif layout->addWidget(x11Container); libvlc_media_player_set_xwindow (mp, x11Container->winId()); #endif #ifdef WIN32 container = new QWidget(this); layout->addWidget(container); libvlc_media_player_set_hwnd (mp, (HWND)(container->winId())); QString filename = context->athlete->home->config().canonicalPath() + "/" + "video-layout.xml"; QFileInfo finfo(filename); if (finfo.exists()) { QFile file(filename); // clean previous layout foreach(MeterWidget* p_meterWidget, m_metersWidget) { m_metersWidget.removeAll(p_meterWidget); delete p_meterWidget; } VideoLayoutParser handler(&m_metersWidget, container); QXmlInputSource source (&file); QXmlSimpleReader reader; reader.setContentHandler (&handler); reader.parse (source); }
VideoWindow::VideoWindow(Context *context, const QDir &home) : GcWindow(context), home(home), context(context), m_MediaChanged(false) { setControls(NULL); setInstanceName("Video Window"); setProperty("color", Qt::black); QHBoxLayout *layout = new QHBoxLayout(); setLayout(layout); // config paramaters to libvlc const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ "--disable-screensaver", /* disable screensaver during playback */ #ifdef Q_OS_LINUX "--no-xlib", // avoid xlib thread error messages #endif "--verbose=-1", // -1 = no output at all "--quiet" }; /* create an exception handler */ //libvlc_exception_init(&exceptions); //vlc_exceptions(&exceptions); /* Load the VLC engine */ inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); //vlc_exceptions(&exceptions); /* Create a new item */ m = NULL; //vlc_exceptions(&exceptions); /* Create a media player playing environement */ mp = libvlc_media_player_new (inst); //vlc_exceptions(&exceptions); //vlc_exceptions(&exceptions); /* This is a non working code that show how to hooks into a window, * if we have a window around */ #ifdef Q_OS_LINUX x11Container = new QX11EmbedContainer(this); layout->addWidget(x11Container); libvlc_media_player_set_xwindow (mp, x11Container->winId()); #endif #ifdef WIN32 container = new QWidget(this); layout->addWidget(container); libvlc_media_player_set_hwnd (mp, container->winId()); #endif connect(context, SIGNAL(stop()), this, SLOT(stopPlayback())); connect(context, SIGNAL(start()), this, SLOT(startPlayback())); connect(context, SIGNAL(pause()), this, SLOT(pausePlayback())); connect(context, SIGNAL(seek(long)), this, SLOT(seekPlayback(long))); connect(context, SIGNAL(unpause()), this, SLOT(resumePlayback())); connect(context, SIGNAL(mediaSelected(QString)), this, SLOT(mediaSelected(QString))); }
void VLCWrapperImpl::SetOutputWindow(void* pHwnd) { // Set the output window libvlc_media_player_set_hwnd(m_pMediaPlayer, pHwnd, &m_VLCex); ProcessVLCException(&m_VLCex, m_EH); }
BOOL CReportCameraWorker::StartCapturePhoto() { CString strOutputFileName; strOutputFileName = GetCaptureFileName(_T("jpg")); if (m_ReportCameraConfig.m_CaptureDevicePath.GetLength() < 1) { TRACE(_T("CReportCameraWorker::StartCaptureVideo no capture device selected\n")); return FALSE; } ////////////////////////////////////////////////////////////////////////// USES_CONVERSION; CString options; options = _T("--play-and-exit --no-osd --intf dummy --dummy-quiet --no-video-deco --aspect-ratio auto"); options += _T(" --no-fullscreen"); // options += _T(" --vout-filter \"\""); ////options += _T(" --width 640 --height 480"); CString video_input; video_input.Format(_T("dshow:// :dshow-vdev=\"%s\""), m_ReportCameraConfig.m_CaptureDevicePath); int iOutputFormat = 0/*m_wndOutputFormat.GetCurSel()*/; CString transcode; CString transcode_out_params; CString one_param; profile video_profile = video_profile_value_list[iOutputFormat]; transcode_out_params.Format(_T("vcodec=%s,scale=%d"), A2T(video_profile.video_codec), video_profile.scale); if(video_profile.video_bitrate > 0) { one_param.Format(_T(",vb=%d"), video_profile.video_bitrate); transcode_out_params += one_param; } one_param.Format(_T(",acodec=%s,ab=%d,channels=%d,samplerate=%d"), A2T(video_profile.audio_codec), video_profile.audio_bitrate, video_profile.channels, video_profile.samplerate ); transcode_out_params += one_param; transcode.Format(_T("transcode{%s}:standard{access=file,mux=%s,dst=\"%s\"}"), transcode_out_params, A2T(video_profile.Container), strOutputFileName ); CString command_line; //command_line.Format(_T("%s %s :dshow-fps=5 --sout=#duplicate{dst=display,dst={%s}"), options, video_input, transcode); command_line.Format(_T("%s %s :dshow-fps=5 --sout=#duplicate{dst=display,dst={%s}"), options, video_input, transcode); CString sout_arg; // dont show on screen/windows/etc //sout_arg.Format(_T("--sout=#duplicate{dst=display,dst={%s}"), transcode); //sout_arg.Format(_T("--sout=#duplicate{dst={%s}"), transcode); sout_arg.Format(_T("--sout=#duplicate{dst=display"), transcode); const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ // "--plugin-path=E:\\TEMP\\VLC-1.0.5\\plugins\\", T2A(sout_arg.GetBuffer(0)) }; #if 1 for (int i = 0; i < sizeof(vlc_args) / sizeof(vlc_args[0]); i++) { TRACE( _T("%d - %s\n"), i, A2T(vlc_args[i])); } #endif /* init vlc modules, should be done only once */ m_inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); if (m_inst == NULL) { return FALSE; } /* Create a new item */ //m_m = libvlc_media_new (m_inst, "E:/Media/2/1.avi", &m_ex); m_m = libvlc_media_new_path (m_inst, T2A(video_input)); if (m_m == NULL) { libvlc_release(m_inst); m_inst = NULL; return FALSE; } /* Create a media player playing environment */ m_mp = libvlc_media_player_new_from_media (m_m); if (m_mp == NULL) { libvlc_media_release(m_m); m_m = NULL; libvlc_release(m_inst); m_inst = NULL; return FALSE; } /* No need to keep the media now */ libvlc_media_release (m_m); m_m = NULL; //m_wndCaptureWindow.CreateEx(0, ) CRect rect(0, 0, 800, 600); CWnd *pWnd = new CWnd; pWnd->CreateEx(/*WS_EX_TOPMOST | */WS_EX_TOOLWINDOW, m_CaptureWndClass, _T("CaptureWindow"), WS_POPUP | WS_CHILD, rect, NULL, 0); pWnd->ShowWindow(SW_HIDE); //libvlc_media_player_set_hwnd(m_mp, m_wndCaptureWindow.GetSafeHwnd()); libvlc_media_player_set_hwnd(m_mp, pWnd->GetSafeHwnd()); /* play the media_player */ int iplay = libvlc_media_player_play (m_mp); if (iplay == -1) { libvlc_media_player_release (m_mp); m_mp = NULL; libvlc_release(m_inst); m_inst = NULL; return FALSE; } m_bCaptureStarted = TRUE; TRACE(_T("CReportCameraWorker::StartCapturePhoto m_bCaptureStarted = TRUE\n")); return TRUE; }
VideoWindow::VideoWindow(Context *context, const QDir &home) : GcWindow(context), home(home), context(context), m_MediaChanged(false) { setControls(NULL); setProperty("color", QColor(Qt::black)); QHBoxLayout *layout = new QHBoxLayout(); setLayout(layout); init = true; // assume initialisation was ok ... #ifdef GC_VIDEO_VLC // // USE VLC VIDEOPLAYER // #if QT_VERSION >= 0x050000 #warning "WARNING: Please ensure the VLC QT4 plugin (gui/libqt4_plugin) is NOT available as it will cause GC to crash." #endif // config paramaters to libvlc const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--ignore-config", /* Don't use VLC's config */ "--disable-screensaver", /* disable screensaver during playback */ #ifdef Q_OS_LINUX "--no-xlib", // avoid xlib thread error messages #endif //"--verbose=-1", // -1 = no output at all //"--quiet" }; /* create an exception handler */ //libvlc_exception_init(&exceptions); //vlc_exceptions(&exceptions); /* Load the VLC engine */ inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); //vlc_exceptions(&exceptions); /* Create a new item */ if (inst) { // if vlc doesn't initialise don't even try! m = NULL; //vlc_exceptions(&exceptions); /* Create a media player playing environement */ mp = libvlc_media_player_new (inst); //vlc_exceptions(&exceptions); //vlc_exceptions(&exceptions); /* This is a non working code that show how to hooks into a window, * if we have a window around */ #ifdef Q_OS_LINUX #if QT_VERSION > 0x50000 x11Container = new QWidget(this); //XXX PORT TO 5.1 BROKEN CODE XXX #else x11Container = new QX11EmbedContainer(this); #endif layout->addWidget(x11Container); libvlc_media_player_set_xwindow (mp, x11Container->winId()); #endif #ifdef WIN32 container = new QWidget(this); layout->addWidget(container); libvlc_media_player_set_hwnd (mp, (HWND)(container->winId())); #endif } else { // something went wrong ! init = false; } #endif #ifdef GC_VIDEO_QT5 // USE QT VIDEO PLAYER wd = new QVideoWidget(this); wd->show(); mp = new QMediaPlayer(this); mp->setVideoOutput(wd); layout->addWidget(wd); #endif if (init) { connect(context, SIGNAL(stop()), this, SLOT(stopPlayback())); connect(context, SIGNAL(start()), this, SLOT(startPlayback())); connect(context, SIGNAL(pause()), this, SLOT(pausePlayback())); connect(context, SIGNAL(seek(long)), this, SLOT(seekPlayback(long))); connect(context, SIGNAL(unpause()), this, SLOT(resumePlayback())); connect(context, SIGNAL(mediaSelected(QString)), this, SLOT(mediaSelected(QString))); } }
void VLCHolderWnd::LibVlcAttach() { if( VP() ) libvlc_media_player_set_hwnd( VP()->get_mp(), hWnd() ); }
bool VLCVideoWrapper::open(const std::string& ThePath, Window* const TheWindow) { bool errorOpening(false); //BoostPath PluginsDirPath("/Applications/VLC.app/Contents/MacOS/modules"); BoostPath PluginsDirPath("/Applications/VLC-1.1.7.app/Contents/MacOS/modules"); std::vector<std::string> VLCArguments; VLCArguments.push_back("-I"); VLCArguments.push_back("dummy"); /* no interface */ VLCArguments.push_back(std::string("--plugin-path=") + PluginsDirPath.string()); //VLCArguments.push_back("--no-audio"); [> we don't want audio <] VLCArguments.push_back("--verbose=0"); /* show only errors */ VLCArguments.push_back("--no-media-library");/* don't want that */ VLCArguments.push_back("--services-discovery=");/* don't want that */ VLCArguments.push_back("--no-video-title-show");/* don't want that */ VLCArguments.push_back("--no-stats");/* don't want that */ VLCArguments.push_back("--ignore-config"); /* don't use/overwrite the config */ VLCArguments.push_back("--no-sub-autodetect");/* don't want subtitles */ VLCArguments.push_back("--control=");/* don't want interface (again) */ VLCArguments.push_back("--no-disable-screensaver");/* don't want that */ // libvlc settings const char** args = new const char*[VLCArguments.size()]; for(UInt32 i(0) ; i<VLCArguments.size() ; ++i) { args[i] = VLCArguments[i].c_str(); } /* * Initialise libVLC */ UInt32 nargs = VLCArguments.size(); _VLCInstance = libvlc_new( nargs, args ); if(_VLCInstance == NULL) { checkVLCError("creating new vlc instance"); return false; } delete [] args; // creates vlc struct holding data to the video file libvlc_media_t *TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() ); checkVLCError("initializing media file"); // initialize a temporary media player so we can get height and width before // adding the vmem options to TheMedia libvlc_media_player_t * tempMediaPlayer = libvlc_media_player_new_from_media( TheMedia ); unsigned Width(200), Height(200); libvlc_video_set_callbacks(tempMediaPlayer, lock, unlock, display, &_VideoMemContext); _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) ) * Width * Height ) * 4 ); libvlc_video_set_format(tempMediaPlayer, "RV24", Width, Height, Width * 3); //Release the media file libvlc_media_release( TheMedia ); libvlc_media_player_play( tempMediaPlayer ); checkVLCError("playing the media"); libvlc_state_t currentState; do { currentState = libvlc_media_player_get_state(tempMediaPlayer); checkVLCError("getting state"); } while(currentState != libvlc_Playing); int VLCResult; do { VLCResult = libvlc_video_get_size(tempMediaPlayer, 0, &Width, &Height); } while(VLCResult != 0); checkVLCError("getting size"); libvlc_media_player_stop( tempMediaPlayer ); libvlc_media_player_release(tempMediaPlayer);// releases media currently in use //Now that we have the size initialize the media again TheMedia = libvlc_media_new_path( _VLCInstance, ThePath.c_str() ); checkVLCError("initializing media file"); // initialize the media player _MediaPlayer = libvlc_media_player_new_from_media( TheMedia ); checkVLCError("initializing media player"); //Release the media file libvlc_media_release( TheMedia ); #ifdef __APPLE__ //set agl handle (if TheWindow is pointing to a carbon window) if (TheWindow->getType().isDerivedFrom(CarbonWindow::getClassType())) { HIWindowRef windowRef = aglGetWindowRef(dynamic_cast<CarbonWindow* const>(TheWindow)->getContext()); HIViewRef contentView = 0; GetRootControl(windowRef, &contentView); //uint32_t aglHandler = CarbonWindowPtr::dcast(TheWindow)->winId(); libvlc_media_player_set_agl (_MediaPlayer, reinterpret_cast<uint32_t>(contentView) ); checkVLCError("attaching media player to carbon window"); } #endif #ifdef WIN32 if (TheWindow->getType().isDerivedFrom(WIN32Window::getClassType())) { libvlc_media_player_set_hwnd (_MediaPlayer, dynamic_cast<WIN32Window* const>(TheWindow)->getHwnd() ); checkVLCError("attaching media player to WIN32 window"); } #endif #ifdef __linux if (TheWindow->getType().isDerivedFrom(XWindow::getClassType())) { libvlc_media_player_set_xwindow (_MediaPlayer, dynamic_cast<XWindow* const>(TheWindow)->getDisplay() ); checkVLCError("attaching media player to Xwindow"); } #endif libvlc_video_set_callbacks(_MediaPlayer, lock, unlock, display, &_VideoMemContext); _VideoMemContext._pixels = ( UInt8* )malloc( ( sizeof( *( _VideoMemContext._pixels ) ) * Width * Height ) * 4 ); libvlc_video_set_format(_MediaPlayer, "RV24", Width, Height, Width * 3); //Start playing the video libvlc_media_player_play( _MediaPlayer ); checkVLCError("playing the media"); do { currentState = libvlc_media_player_get_state(_MediaPlayer); checkVLCError("getting state"); } while(currentState != libvlc_Playing); clock_t endwait; endwait = clock () + 2 * CLOCKS_PER_SEC ; while (clock() < endwait) {} _Initialized = true; // check if the player can be paused if(libvlc_media_player_can_pause(_MediaPlayer)) { // can pause it? do it libvlc_media_player_pause(_MediaPlayer); // error checking of course checkVLCError("pausing media player"); libvlc_media_player_set_position( _MediaPlayer, 0.0f ); checkVLCError("setting position during player initialization"); } return errorOpening; }
bool CAVPlayer::Play(const std::string &strPath) { if (! m_pVLC_Inst) { Init(); } if(strPath.empty() || ! m_pVLC_Inst) { return false; } // 验证地址是网络地址,还是本地地址 bool bURL = false; std::vector<std::string> vctURL; vctURL.push_back("http"); vctURL.push_back("https"); vctURL.push_back("ftp"); vctURL.push_back("rstp"); for (unsigned i = 0; i < vctURL.size(); i++) { // 实际使用请判断大小写 if (! strPath.compare(0, vctURL[i].size(), vctURL[i])) { bURL = true; break; } } Stop(); bool bRet = false; libvlc_media_t *m; if (bURL) { // 示例网络地址:http://zhangmenshiting.baidu.com/data2/music/1203175/51597064800128.mp3?xcode=cb97ecc9d44ba29122881c69e505a43849f04e8309ecc859 m = libvlc_media_new_location(m_pVLC_Inst, strPath.c_str()); } else { m = libvlc_media_new_path(m_pVLC_Inst, strPath.c_str()); } if (m) { if (m_pVLC_Player = libvlc_media_player_new_from_media(m)) { libvlc_media_player_set_hwnd(m_pVLC_Player, m_hWnd); libvlc_media_player_play(m_pVLC_Player); // 事件管理 libvlc_event_manager_t *vlc_evt_man = libvlc_media_player_event_manager(m_pVLC_Player); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPlaying, ::OnVLC_Event, this); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerPositionChanged, ::OnVLC_Event, this); libvlc_event_attach(vlc_evt_man, libvlc_MediaPlayerEndReached, ::OnVLC_Event, this); bRet = true; } libvlc_media_release(m); } return bRet; }
void VLCWrapperImpl::SetOutputWindow(void* pHwnd) { // Set the output window libvlc_media_player_set_hwnd(pMediaPlayer_, pHwnd); }
void set_vedio_panel(int * panel) { if(mediaplay != NULL) libvlc_media_player_set_hwnd(mediaplay,(void *)panel); else ; }