Media Player played once but then after first time no longer outputs video [SOLVED]



  • Below is my code which is quite frankly making me want to pull my hair out. First time I ran this it started straight away, then decided to run again (after trying a RTSP url instead), and now the video won't play no matter what I do. If anyone has an idea why this is happening please let me know. Cheers

    @#include "mainwindow.h"
    #include <QApplication>
    #include <QMediaPlayer>
    #include <QFileInfo>
    #include <QDebug>
    #include <QVideoWidget>
    #include <QGraphicsView>
    #include <QGraphicsVideoItem>
    #include <QGraphicsScene>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;

    QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile&#40;"big_buck_bunny_480p_surround-fix.avi"&#41;&#41;;
    

    // player->setMedia(QUrl("rtsp://192.168.100.58:8554/stream/"));
    // player->setMedia(QUrl("http://www.youtube.com/watch?v=5OC0rZCal24"));
    // player->setMedia(QUrl("http://localhost:8080/stream"));
    QVideoWidget *videoWidget = new QVideoWidget;
    w.setCentralWidget(videoWidget); // if w is a QMainWindow
    player->setVideoOutput(videoWidget);
    player->play();

    /* QGraphicsView *graphicsView = new QGraphicsView;
    // w.setCentralWidget(graphicsView); // w = QMainWindow
    QGraphicsScene *scene = new QGraphicsScene;
    QMediaPlayer *player = new QMediaPlayer;
    QGraphicsVideoItem *item = new QGraphicsVideoItem;

    graphicsView->setScene(scene);
    player->setVideoOutput(item);
    
    graphicsView->scene()->addItem(item);
    //player->setMedia(QUrl::fromLocalFile&#40;"C:/Users/nick.herniman/Downloads/big_buck_bunny_1080p_h264.mov"&#41;&#41;;
    player->setMedia(QUrl("rtsp://localhost:8554/stream"));
    player->play();
    

    */
    w.show();

    return a.exec&#40;&#41;;
    

    }@

    .pro file
    @#-------------------------------------------------

    Project created by QtCreator 2013-09-03T14:51:23

    #-------------------------------------------------

    QT += core gui multimedia widgets multimediawidgets

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Media_player_v2
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui
    @


  • Lifetime Qt Champion

    Hi,

    Where is big_buck_bunny_480p_surround-fix.avi located ?



  • Slightly confused now, ran the same program again today (only thing that has changed is that I have restarted the machine), and it's working.

    Don't suppose you have any idea why this might happen as completely miffed how this could of happened (could the file be blocked for some reason ?)


  • Lifetime Qt Champion

    Gremlins in your computer ? :D

    Seriously, can't tell



  • Ah ok well those gremlins are bloody annoying :P. Ah well ghost in the shell i guess :P.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.