/* TODO: NOT IN VLC API */
void
Java_org_videolan_libvlc_MediaPlayer_nativePlayMRL(JNIEnv *env, jobject thiz,
                                                   jstring mrl,
                                                   jobjectArray mediaOptions)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* New Media */
    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
    libvlc_media_t* p_md = libvlc_media_new_location(p_obj->p_libvlc, p_mrl);

    /* media options */
    if (mediaOptions != NULL)
        add_media_options(p_md, env, mediaOptions);

    (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);

    /* Connect the media event manager. */
    /* TODO use VlcObject events */
    libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
    static const libvlc_event_type_t mp_media_events[] = {
        libvlc_MediaParsedChanged,
        libvlc_MediaMetaChanged,
    };
    for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
        libvlc_event_attach(ev_media, mp_media_events[i], vlc_event_callback, NULL);

    libvlc_media_player_set_media(p_obj->u.p_mp, p_md);
    libvlc_media_release(p_md);

    libvlc_media_player_play(p_obj->u.p_mp);
}
Exemple #2
0
/**************************************************************************
 *       set_current_playing_item (private)
 *
 * Playlist lock should be held
 **************************************************************************/
static void
set_current_playing_item(libvlc_media_list_player_t * p_mlp, libvlc_media_list_path_t path)
{
    assert_locked(p_mlp);

    /* First, save the new path that we are going to play */
    if (p_mlp->current_playing_item_path != path)
    {
        free(p_mlp->current_playing_item_path);
        p_mlp->current_playing_item_path = path;
    }

    if (!path)
        return;

    libvlc_media_t * p_md;
    p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
    if (!p_md)
        return;
    
    /* Make sure media_player_reached_end() won't get called */
    uninstall_media_player_observer(p_mlp);

    /* Create a new media_player if there is none */
    if (!p_mlp->p_mi)
        p_mlp->p_mi = libvlc_media_player_new_from_media(p_md, NULL);

    libvlc_media_player_set_media(p_mlp->p_mi, p_md, NULL);

    install_media_player_observer(p_mlp);
    libvlc_media_release(p_md); /* for libvlc_media_list_item_at_index */
}
Exemple #3
0
void
play_next(struct info *data)
{
	char errormsg[] = "Next mix not found.";
	int errn;
	struct track *t;
	libvlc_media_t *media;

	/* Check if we are already on the last track.
	 * If so request a similar mix and continue playing.
	 */
	if (data->m->track_count > 0) {
		if (data->m->track[data->m->track_count-1]->last == TRUE) {
			errn = search_nextmix(data);
			if (errn == ERROR) {
				draw_error(errormsg);
				data->state = START;
				return;
			}
		}
	}

	t = mix_nexttrack(data);
	if (t == NULL)
		return;

	media = libvlc_media_new_location(data->vlc_inst, t->url);
	if (media == NULL)
		return;
	libvlc_media_player_set_media(data->vlc_mp, media);
	(void)libvlc_media_player_play(data->vlc_mp);
	libvlc_media_release(media);
}
void
Java_org_videolan_libvlc_MediaPlayer_stop(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* TODO: REMOVE */
    libvlc_media_t* p_md = libvlc_media_player_get_media(p_obj->u.p_mp);
    if (p_md)
    {
        libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
        static const libvlc_event_type_t mp_media_events[] = {
            libvlc_MediaParsedChanged,
            libvlc_MediaMetaChanged,
        };
        for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
            libvlc_event_detach(ev_media, mp_media_events[i], vlc_event_callback, NULL);
        libvlc_media_release(p_md);
        libvlc_media_player_set_media(p_obj->u.p_mp, NULL);
    }

    libvlc_media_player_stop(p_obj->u.p_mp);
}
Exemple #5
0
    void
    VLC::load(const std::string & theFilename) {

        AC_DEBUG << "VLC::load('" << theFilename << "')";

        _EOF = false;
        _playTime = 0;
        
        std::vector<std::string> elements = asl::splitString(theFilename, "#");
        if (elements.size() == 2) {
            _playTime = as<asl::Unsigned64>(elements[1]);
            AC_DEBUG << "parsed playback position at " << _playTime << " milliseconds.";
        }
        
        _mediaURL = elements[0];
        libvlc_media_t *media = libvlc_media_new_location(_libvlc, _mediaURL.c_str());
        libvlc_media_player_set_media(_mediaPlayer, media);
        libvlc_media_release(media);

        libvlc_video_set_callbacks(_mediaPlayer, VLC::lock, VLC::unlock, VLC::display, this);
        _rasterEncoding = BGR;
        setPixelFormat(_rasterEncoding);
        libvlc_video_set_format_callbacks(_mediaPlayer, VLC::setup_video, VLC::cleanup_video);

        libvlc_media_player_play(_mediaPlayer);
        if (_playTime > 0) {
            libvlc_media_player_set_time(_mediaPlayer, _playTime);
        }
    }
void Player::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(), &_vlcexcep ); // 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;
}
Exemple #7
0
void VLCWrapperImpl::OpenMedia(const char* pszMediaPathName)
{
	// Load a new item
	m_pMedia = libvlc_media_new (m_pVLCInstance, pszMediaPathName, &m_VLCex);
    libvlc_media_player_set_media (m_pMediaPlayer, m_pMedia, &m_VLCex);
	ProcessVLCException(&m_VLCex, m_EH);
}
Exemple #8
0
void VideoWindow::mediaSelected(QString filename)
{
    // stop any current playback
    stopPlayback();

    // release whatever is already loaded
    if (m) libvlc_media_release(m);
    m = NULL;

    if (filename.endsWith("/DVD") || (filename != "" && QFile(filename).exists())) {

#ifdef Q_OS_LINUX
        QString fileURL = "file://" + filename.replace(" ","%20").replace("\\", "/");
#else
        // A Windows "c:\xyz\abc def.avi" filename should become file:///c:/xyz/abc%20def.avi
        QString fileURL = "file:///" + filename.replace(" ","%20").replace("\\", "/");
#endif
        //qDebug()<<"file url="<<fileURL;

        /* open media */
        m = libvlc_media_new_path(inst, filename.endsWith("/DVD") ? "dvd://" : fileURL.toLatin1());

        /* set the media to playback */
        if (m) libvlc_media_player_set_media (mp, m);

        m_MediaChanged = true;
    }
}
Exemple #9
0
JNIEXPORT void JNICALL NAME(nativeSetDataSource)(JNIEnv *env, jobject thiz, jstring path)
{
    libvlc_instance_t *instance = (libvlc_instance_t *) getIntValue(env, thiz, "mLibVlcInstance");
    libvlc_media_player_t *mp = (libvlc_media_player_t *) getIntValue(env, thiz, "mLibVlcMediaPlayer");
    const char *str = (*env)->GetStringUTFChars(env, path, 0);
    if (!str)
    {
        /* XXX: throw */
        return;
    }
    libvlc_media_t *media = (*str == '/') ? libvlc_media_new_path(instance, str) : libvlc_media_new_location(instance, str);
    if (media)
    {
        libvlc_event_manager_t *em = libvlc_media_event_manager(media);
        for (int i = 0; i < sizeof(md_listening) / sizeof(*md_listening); i++)
        {
            libvlc_event_attach(em, md_listening[i], vlc_event_callback, thiz);
        }
        /* this will cancel current input and start a new one */
        libvlc_media_player_set_media(mp, media);
        setIntValue(env, thiz, "mNativeMediaBufferingCount", 0);
    }
    (*env)->ReleaseStringUTFChars(env, path, str);
    setIntValue(env, thiz, "mLibVlcMedia", (jint) media);
}
Exemple #10
0
void Player::playFile(QString ofile)
{
    /*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>]]
    */        

    /*Prevent path problems*/
    QString file = ofile.replace('/','\\');

    /* Create a new LibVLC media descriptor */
    media = libvlc_media_new_path(vlcInstance, file.toLatin1());

    libvlc_media_player_set_media (mediaPlayer, media);

    libvlc_media_player_set_xwindow (mediaPlayer, reinterpret_cast<unsigned int>(videoWidget->winId()));

    /* Play */
    libvlc_media_player_play (mediaPlayer);
    isPlaying=true;
}
Exemple #11
0
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.
}
Exemple #12
0
void VlcMediaPlayer::open(VlcMedia *media)
{
    libvlc_media_player_set_media(_vlcMediaPlayer, media->core());

    VlcError::errmsg();

    play();
}
static void
vlc_player_load_media(GtkVlcPlayer *player, libvlc_media_t *media)
{
	libvlc_media_parse(media);
	libvlc_media_player_set_media(player->priv->media_player, media);

	/* NOTE: media was parsed so get_duration works */
	update_length(player, (gint64)libvlc_media_get_duration(media));
	update_time(player, 0);
}
Exemple #14
0
void VlcControl::setVideo(QString source)
{
    setlog("set media " + source);
    if(vlcMedia)
    {
        libvlc_media_release(vlcMedia);
    }
    vlcMedia = libvlc_media_new_location(vlcInstance, source.toAscii());
    libvlc_media_player_set_media (vlcPlayer, vlcMedia);
}
Exemple #15
0
 /** File has to be in one of the following formats:
     [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>]]
 */
 void open( const std::string& file, bool needPlay=true, unsigned int w=512, unsigned int h=512 )
 {
     _vlcMedia = libvlc_media_new_path( _vlc, file.c_str() );
     libvlc_media_player_set_media( _vlcPlayer, _vlcMedia );
     libvlc_video_set_callbacks( _vlcPlayer, &VLCImageStream::lockFunc, &VLCImageStream::unlockFunc,
                                 &VLCImageStream::displayFunc, this );
     libvlc_video_set_format( _vlcPlayer, "RGBA", w, h, w*4 );
     
     allocateImage( w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE );
     if ( needPlay ) play();
 }
Exemple #16
0
/*
 * Known issues: since moving in the playlist using playlist_Next
 * or playlist_Prev implies starting to play items, the a_position
 * argument will be only honored for the 1st item in the list.
 *
 * XXX:FIXME split moving in the playlist and playing items two
 * different actions or make playlist_<Next|Prev> accept a time
 * value to start to play from.
 */
void
mediacontrol_start( mediacontrol_Instance *self,
                    const mediacontrol_Position * a_position,
                    mediacontrol_Exception *exception )
{
    libvlc_media_t * p_media;
    char * psz_name;
    libvlc_exception_t ex;

    mediacontrol_exception_init( exception );
    libvlc_exception_init( &ex );

    p_media = libvlc_media_player_get_media( self->p_media_player, &ex );
    HANDLE_LIBVLC_EXCEPTION_VOID( &ex );

    if ( ! p_media )
    {
        /* No media was defined. */
        RAISE( mediacontrol_PlaylistException, "No defined media." );
    }
    else
    {
        /* A media was defined. Get its mrl to reuse it, but reset the options
           (because start-time may have been set on the previous invocation */
        psz_name = libvlc_media_get_mrl( p_media, &ex );
        HANDLE_LIBVLC_EXCEPTION_VOID( &ex );

        /* Create a new media */
        p_media = libvlc_media_new( self->p_instance, psz_name, &ex );
        HANDLE_LIBVLC_EXCEPTION_VOID( &ex );

        if( a_position->value )
        {
            char * psz_from;
            libvlc_time_t i_from;

            /* A start position was specified. Add it to media options */
            psz_from = ( char * )malloc( 20 * sizeof( char ) );
            i_from = private_mediacontrol_position2microsecond( self->p_media_player, a_position ) / 1000000;
            snprintf( psz_from, 20, "start-time=%"PRId64, i_from );
            libvlc_media_add_option( p_media, psz_from, &ex );
            HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
        }

        libvlc_media_player_set_media( self->p_media_player, p_media, &ex );
        HANDLE_LIBVLC_EXCEPTION_VOID( &ex );

        libvlc_media_player_play( self->p_media_player, &ex );
        HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
    }
}
void VLCWrapperImpl::OpenMedia(const char* pMediaPathName)
{
	// Load a new item
	pMedia_ = libvlc_media_new_path(pVLCInstance_, pMediaPathName);
	libvlc_media_player_set_media(pMediaPlayer_, pMedia_);

	//////get file information
	//libvlc_media_parse(pMedia_);
	//unsigned w = 0, h = 0;
	//libvlc_video_get_size(pMediaPlayer_, 0, &w, &h);
	//libvlc_meta_t meta;
	//char *s = libvlc_media_get_meta(pMedia_, libvlc_meta_Title);
	////libvlc_media_get_tracks_info(pMedia_, );
}
Exemple #18
0
void VideoWindow::startPlayback()
{
    if (!m) return; // ignore if no media selected

    // stop playback & wipe player
    libvlc_media_player_stop (mp);

    /* set the media to playback */
    libvlc_media_player_set_media (mp, m);

    /* play the media_player */
    libvlc_media_player_play (mp);

    m_MediaChanged = false;
}
Exemple #19
0
gboolean
xmr_player_open(XmrPlayer	*player,
			const gchar *uri)
{
	XmrPlayerPrivate *priv;
	gchar *r_uri = NULL;
	libvlc_media_t *media = NULL;

	g_return_val_if_fail( player != NULL && uri != NULL, FALSE);
	priv = player->priv;

	{
		static const gchar * const prefix[] =
		{
			"http://", "file://" // we don't deal with others
		};
		gboolean prefix_ok = FALSE;
		gint i;

		for (i = 0; i < 2; ++i)
		{
			if (g_str_has_prefix(uri, prefix[i]))
			{
				prefix_ok = TRUE;
				break ;
			}
		}

		if (!prefix_ok) {
			r_uri = g_filename_to_uri(uri, NULL, NULL);
		} else {
			r_uri = g_strdup(uri);
		}
	}

	media = libvlc_media_new_location(priv->instance, r_uri);
	g_free(r_uri);

	if(media == NULL)
		return FALSE;
	
	libvlc_media_player_set_media(priv->player, media);
	xmr_player_set_repeat(player);

	libvlc_media_release(media);
	
	return TRUE;
}
Exemple #20
0
void MainWindow::OnOpen(wxCommandEvent& event) {
    wxFileDialog openFileDialog(this, wxT("Choose File"));

    if (openFileDialog.ShowModal() == wxID_CANCEL) {
        return;
    }
    else {
        libvlc_media_t *media;
        wxFileName filename = wxFileName::FileName(openFileDialog.GetPath());
        filename.MakeRelativeTo();
        media = libvlc_media_new_path(vlc_inst, filename.GetFullPath().mb_str());
        libvlc_media_player_set_media(media_player, media);
        play();
        libvlc_media_release(media);
    }
}
Exemple #21
0
void
mediacontrol_set_mrl( mediacontrol_Instance *self,
                      const char * psz_file,
                      mediacontrol_Exception *exception )
{
    libvlc_media_t * p_media;
    libvlc_exception_t ex;

    mediacontrol_exception_init( exception );
    libvlc_exception_init( &ex );

    p_media = libvlc_media_new( self->p_instance, psz_file, &ex );
    HANDLE_LIBVLC_EXCEPTION_VOID( &ex );

    libvlc_media_player_set_media( self->p_media_player, p_media, &ex );
    HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
Exemple #22
0
    void VLCVideoWidgetDelegator::loadVideoFromFile( const QString& path){
      if( m_player != Nullptr ){
        if( m_isPlaying ){
          libvlc_media_player_stop ( m_player );
        }
      }

      if( m_currentMedia != Nullptr ){
        libvlc_media_release( m_currentMedia );
        m_currentMedia = Nullptr;
      }

      if( m_instance != Nullptr ){
        m_currentMedia = libvlc_media_new_path (m_instance, path.toAscii().data() );
        libvlc_media_player_set_media (m_player, m_currentMedia);
      }
    }
void VideoSource::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 (_vlcinstance, file.toAscii(), &_vlcexcep);
    _m = libvlc_media_new_path (_vlcinstance, file.toAscii());
    //    raise(&_vlcexcep);

    // stuff for storing buffers
    struct ctx* context;
    context = (struct ctx*) malloc( sizeof(*context));
    context->pixels = (uchar *) malloc( (sizeof(*(context->pixels)) *VIDEO_WIDTH*VIDEO_HEIGHT) * 4);
    // mutex
    context->mutex = new QMutex();


    //    libvlc_media_player_set_media (_mp, _m, &_vlcexcep);
    libvlc_media_player_set_media (_mp, _m);
    //    raise(&_vlcexcep);

    // /!\ 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

    /* Play */
    //    libvlc_media_player_play (_mp, &_vlcexcep );
    libvlc_media_player_play (_mp);
    //    raise(&_vlcexcep);

    _isPlaying=true;
}
void VideoPlayer::open( const std::string& file, unsigned int w, unsigned int h )
{
    if ( libvlc_media_player_is_playing(_vlcPlayer)==1 )
    {
        libvlc_media_player_stop( _vlcPlayer );
        libvlc_media_release( _vlcMedia );
    }
    
    std::string protocol = osgDB::getServerProtocol( file );
    if ( !protocol.empty() ) _vlcMedia = libvlc_media_new_location( _vlc, file.c_str() );
    else _vlcMedia = libvlc_media_new_path( _vlc, file.c_str() );
    
    libvlc_media_player_set_media( _vlcPlayer, _vlcMedia );
    libvlc_video_set_callbacks( _vlcPlayer, &VideoPlayer::lockFunc, &VideoPlayer::unlockFunc,
                                &VideoPlayer::displayFunc, this );
    libvlc_video_set_format( _vlcPlayer, "RGBA", w, h, w*4 );
    
    allocateImage( w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE );
    setInternalTextureFormat( GL_RGBA );
}
Exemple #25
0
    VLCVideoWidgetDelegator::VLCVideoWidgetDelegator( const QString& path)
      :m_widgetInstance( Nullptr )
      ,m_instance( Nullptr )
      ,m_player( Nullptr )
      ,m_currentMedia( Nullptr )
      ,m_hasPaused( false )
      ,m_isPlaying( false ){

      const char * const vlc_args[] = {
        "--plugin-path=plugins\\"
      };

      m_instance= libvlc_new( sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args );

      if( m_instance != Nullptr ){
        m_player = libvlc_media_player_new (m_instance);

        m_currentMedia = libvlc_media_new_path (m_instance, path.toAscii().data() );
        libvlc_media_player_set_media (m_player, m_currentMedia);      
      }
    }
TestVideo::TestVideo(QWidget *parent) :
    QWidget(parent)
{
    QString path = QString::fromAscii("file:///Volumes/UltraFat/Ted_Bundy.avi");
    const char * const vlcArgs[] = {
        "--intf", "macosx"
    };

    qDebug() << this->winId();
    ins = libvlc_new(sizeof(vlcArgs) / sizeof(*vlcArgs), vlcArgs);
    mp = libvlc_media_player_new(ins);
    libvlc_media_player_set_nsobject( mp, (void *) this->winId());
    libvlc_media_player_set_media(mp, libvlc_media_new_path(ins, path.toLocal8Bit()));
    libvlc_media_player_play(mp);

    // Kill the stuff in 5 seconds
    timer = new QTimer(this);
    timer->setInterval(10000);
    connect(timer,SIGNAL(timeout()),this,SLOT(scrapit()));
    timer->start();
}
void SMActionVideoVLC::load(int time)
{
    if (!isLoaded())
    {
        SMAction::load(time);qInfo() << mediaVLC();
        _m = libvlc_media_new_path(_vlcinstance, mediaVLC());
        if (!_m)
        {
            setStatus(STATUS_ERROR);
            setLoadStatus(STATUS_ERROR);
            return;
        }
        libvlc_media_player_set_media (_mp, _m);

        QString options = "input-repeat=";
        options += QString::number(repeat());
        libvlc_media_add_option(_m, options.toLatin1());

        setLoadStatus(STATUS_LOADED);
    }
}
Exemple #28
0
bool VLCPlayer::loadFile(const QString & filePath) {
    VLCPlayer::mutex.lock();

    if (VLCPlayer::playbackInProgress == true) {
        qDebug() << "Playback already in progress !";
        VLCPlayer::mutex.unlock();
        return false;
    }

    void *pUserData = 0;


    libvlc_event_manager_t* eventManager = libvlc_media_player_event_manager(VLCPlayer::media_player);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerTimeChanged, handleEvent, pUserData);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerEndReached, handleEvent, pUserData);
    libvlc_event_attach(eventManager, libvlc_MediaPlayerPositionChanged, handleEvent, pUserData);


    QFile mediaFile(filePath);
    if (!mediaFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Unable to open the file : " << filePath;
        VLCPlayer::mutex.unlock();
        return false;
    }

    libvlc_media_t * media = libvlc_media_new_fd(VLCPlayer::inst, mediaFile.handle());
    libvlc_media_player_set_media(VLCPlayer::media_player, media);
    libvlc_media_player_play(VLCPlayer::media_player);


    VLCPlayer::playbackInProgress = true;
    VLCPlayer::mutex.unlock();

    while (VLCPlayer::playbackInProgress) {
        QTest::qSleep(1000);
    }
    mediaFile.close();

    return true;
}
Exemple #29
0
void Java_org_videolan_libvlc_MediaList_loadPlaylist(JNIEnv *env, jobject thiz, jobject libvlcJava, jstring mrl, jobject items) {
    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, NULL);

    libvlc_media_t *p_md = libvlc_media_new_location((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), p_mrl);
    libvlc_media_add_option(p_md, ":demux=playlist,none");
    libvlc_media_add_option(p_md, ":run-time=1");

    struct stopped_monitor* monitor = malloc(sizeof(struct stopped_monitor));
    pthread_mutex_init(&monitor->doneMutex, NULL);
    pthread_cond_init(&monitor->doneCondVar, NULL);
    monitor->stopped = false;
    pthread_mutex_lock(&monitor->doneMutex);

    libvlc_media_player_t* p_mp = libvlc_media_player_new((libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"));
    libvlc_media_player_set_video_title_display(p_mp, libvlc_position_disable, 0);
    libvlc_event_manager_t* ev = libvlc_media_player_event_manager(p_mp);
    libvlc_event_attach(ev, libvlc_MediaPlayerEndReached, stopped_callback, monitor);
    libvlc_media_player_set_media(p_mp, p_md);
    libvlc_media_player_play(p_mp);

    struct timespec deadline;
    clock_gettime(CLOCK_REALTIME, &deadline);
    deadline.tv_sec += 2; /* If "VLC can't open the file", return */
    int mp_alive = 1;
    while(!(monitor->stopped) && mp_alive) {
        pthread_cond_timedwait(&monitor->doneCondVar, &monitor->doneMutex, &deadline);
        mp_alive = libvlc_media_player_will_play(p_mp);
    }
    pthread_mutex_unlock(&monitor->doneMutex);
    pthread_mutex_destroy(&monitor->doneMutex);
    pthread_cond_destroy(&monitor->doneCondVar);
    free(monitor);

    libvlc_media_player_release(p_mp);

    expand_media_internal(env, (libvlc_instance_t*)(intptr_t)getLong(env, libvlcJava, "mLibVlcInstance"), items, p_md);

    (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);
}
Exemple #30
0
void VideoWindow::startPlayback()
{
#ifdef GC_VIDEO_VLC
    if (!m) return; // ignore if no media selected

    // stop playback & wipe player
    libvlc_media_player_stop (mp);

    /* set the media to playback */
    libvlc_media_player_set_media (mp, m);

    /* play the media_player */
    libvlc_media_player_play (mp);

    m_MediaChanged = false;
#endif

#ifdef GC_VIDEO_QT5
    // open the media object
    mp->play();
#endif
}