Uploaded image for project: 'Qt Mobility'
  1. Qt Mobility
  2. QTMOBILITY-1905

Multiple Problems Using QMediaPlayer, QVideoWidget, QCamera and QCameraViewFinder and in the same Application

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Not Evaluated Not Evaluated
    • 1.2.0
    • 1.1.3
    • Multimedia
    • None
    • Symbian S60 5th Edition
      Nokia N97 mini, Nokia C6-00

      The QCamera and the QMediaPlayer don't work together when both have to display their images.

      My Mainwindow.ui consists of 2 Widgets, a QVideoWidget (videoWidget) and a QCameraViewFinder. Additionaly there is a QPushButton named playButton.

      i'll post only the mainwindow, the complete code is attached

      mainwindow.cpp
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      #include <QUrl>
      #include <QDebug>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
      	 ui(new Ui::MainWindow),
      	camera(NULL),
      	player(NULL)
      {
      	 ui->setupUi(this);
      	 ui->videoWidget->hide();
      
      	 player = new QMediaPlayer(this);
      	 player->setVideoOutput(ui->videoWidget);
      	 player->setMedia(QUrl::fromLocalFile("E:\\test.avi"));
      	 connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(playerStateChanged(QMediaPlayer::State)));
      	 connect(player, SIGNAL(error(QMediaPlayer::Error)), SLOT(playerError(QMediaPlayer::Error)));
      
      	 camera = new QCamera(this);
      	 camera->setViewfinder(ui->viewFinder);
      	 camera->start();
      }
      
      MainWindow::~MainWindow()
      {
      	 delete ui;
      }
      
      void MainWindow::playerError(QMediaPlayer::Error error)
      {
      	qDebug() << error << player->errorString();
      }
      
      void MainWindow::on_playButton_clicked()
      {
      	camera->unload();
      
      	ui->viewFinder->hide();
      	ui->videoWidget->show();
      
      	player->play();
      }
      
      void MainWindow::playerStateChanged(QMediaPlayer::State state)
      {
      	if(state == QMediaPlayer::StoppedState)
      	{
      		ui->videoWidget->hide();
      		ui->viewFinder->show();
      
      		camera->start();
      	}
      }
      

      the expected behaviour is:
      in the beginning the viewfinder is shown and the live image from the camera is displayed.
      when the play button is pressed the viewfinder is hidden and the multimediaplayer plays the E:\test.avi in the now shown videowidget.
      when the playback finished the videowidget is hidden and the viewfinder displays the cameraimage again.

      the real behaviour is:
      the viewfinder displays the live image from the camera.
      when the play button is pressed the first time, the camera viewfinder is hidden the player plays only sound no video output is visible
      when the playback finished the camera life image is displayed again normally
      when the play button is pressed again, the camera viewfinder hides and the video plays with image as one would expect when pressing the first time.
      when the playback is finished the camera does not display again, showing this message:

      [Qt Message] Camera error: "Access to camera device was rejected." 
      [Qt Message] Camera state changed: 0 
      

      if i use camera->stop() instead of unload() the mediaplayer never plays the visual part of the video and the camera works fine all the time.

      the player itself does not produce any errors

      I could reproduce it with the QtMobility 1.2.0 beta, too, but I have no possibility to test 1.2 final.

        1. CameraBug.zip
          12 kB
          Patrick Jahner
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            ravipati Sridhar Ravipati
            h0ll0 Patrick Jahner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes