Пример #1
0
static void test_media_subitems(const char** argv, int argc)
{
    const char *subitems_path = SRCDIR"/samples/subitems";

    libvlc_instance_t *vlc = libvlc_new (argc, argv);
    assert (vlc != NULL);
    libvlc_media_t *media;

    log ("Testing media_subitems: path: '%s'\n", subitems_path);
    media = libvlc_media_new_path (vlc, subitems_path);
    assert (media != NULL);
    test_media_subitems_media (media, false);
    libvlc_media_release (media);

    #define NB_LOCATIONS 2
    char *subitems_realpath = realpath (subitems_path, NULL);
    assert (subitems_realpath != NULL);
    const char *schemes[NB_LOCATIONS] = { "file://", "dir://" };
    for (unsigned i = 0; i < NB_LOCATIONS; ++i)
    {
        char *location;
        assert (asprintf (&location, "%s%s", schemes[i], subitems_realpath) != -1);
        log ("Testing media_subitems: location: '%s'\n", location);
        media = libvlc_media_new_location (vlc, location);
        assert (media != NULL);
        test_media_subitems_media (media, false);
        free (location);
        libvlc_media_release (media);
    }
    free (subitems_realpath);

#ifdef HAVE_OPENAT
    /* listing directory via a fd works only if HAVE_OPENAT is defined */
    int fd = open (subitems_path, O_RDONLY);
    log ("Testing media_subitems: fd: '%d'\n", fd);
    assert (fd >= 0);
    media = libvlc_media_new_fd (vlc, fd);
    assert (media != NULL);
    test_media_subitems_media (media, true);
    libvlc_media_release (media);
    close (fd);
#else
#warning not testing subitems list via a fd location
#endif

    libvlc_release (vlc);
}
Пример #2
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;
}