Update documentation.

Rewrite the module overview, add video and audio overviews,
and update the camera overview. Tweak the radiooverview
slightly.

Still missing some links for examples and some fleshing out
but hopefully a lot better.

Change-Id: Id6486e20ba4a09c36d7739e327d4f9910ad083a5
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
This commit is contained in:
Michael Goddard
2012-01-04 14:56:31 +10:00
committed by Qt by Nokia
parent 0889d69790
commit 5ec608b006
13 changed files with 815 additions and 897 deletions

View File

@@ -46,14 +46,92 @@
#include "qmediarecorder.h"
#include "qcameraimagecapture.h"
#include "qcameraimageprocessing.h"
#include "qabstractvideosurface.h"
void camera()
/* Globals so that everything is consistent. */
QCamera *camera = 0;
QCameraViewfinder *viewfinder = 0;
QMediaRecorder *recorder = 0;
QCameraImageCapture *imageCapture = 0;
void overview_viewfinder()
{
QCamera *camera = 0;
QCameraViewfinder *viewfinder = 0;
QMediaRecorder *recorder = 0;
QCameraImageCapture *imageCapture = 0;
//! [Camera overview viewfinder]
camera = new QCamera;
viewfinder = new QCameraViewfinder;
camera->setViewfinder(viewfinder);
viewfinder->show();
camera->start(); // to start the viewfinder
//! [Camera overview viewfinder]
}
// -.-
class MyVideoSurface : public QAbstractVideoSurface
{
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
Q_UNUSED(handleType);
return QList<QVideoFrame::PixelFormat>();
}
bool present(const QVideoFrame &frame)
{
Q_UNUSED(frame);
return true;
}
};
void overview_surface()
{
MyVideoSurface *mySurface;
//! [Camera overview surface]
camera = new QCamera;
mySurface = new MyVideoSurface;
camera->setViewfinder(mySurface);
camera->start();
// MyVideoSurface::present(..) will be called with viewfinder frames
//! [Camera overview surface]
}
void overview_still()
{
//! [Camera overview capture]
imageCapture = new QCameraImageCapture(camera);
camera->setCaptureMode(QCamera::CaptureStillImage);
camera->start(); // Viewfinder frames start flowing
//on half pressed shutter button
camera->searchAndLock();
//on shutter button pressed
imageCapture->capture();
//on shutter button released
camera->unlock();
//! [Camera overview surface]
}
void overview_movie()
{
//! [Camera overview movie]
camera = new QCamera;
recorder = new QMediaRecorder(camera);
camera->setCaptureMode(QCamera::CaptureVideo);
camera->start();
//on shutter button pressed
recorder->record();
// sometime later, or on another press
recorder->stop();
//! [Camera overview movie]
}
void camera_blah()
{
//! [Camera]
camera = new QCamera;
@@ -62,7 +140,6 @@ void camera()
camera->setViewfinder(viewfinder);
recorder = new QMediaRecorder(camera);
imageCapture = new QCameraImageCapture(camera);
camera->setCaptureMode(QCamera::CaptureStillImage);
@@ -83,8 +160,6 @@ void camera()
void cameraimageprocessing()
{
QCamera *camera = 0;
//! [Camera image whitebalance]
camera = new QCamera;
QCameraImageProcessing *imageProcessing = camera->imageProcessing();
@@ -103,8 +178,6 @@ void cameraimageprocessing()
void camerafocus()
{
QCamera *camera = 0;
//! [Camera custom zoom]
QCameraFocus *focus = camera->focus();
focus->setFocusPointMode(QCameraFocus::FocusPointCustom);

View File

@@ -169,6 +169,25 @@ void MediaExample::MediaPlayer()
player->play();
//! [Player]
//! [Local playback]
player = new QMediaPlayer;
// ...
player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
player->setVolume(50);
player->play();
//! [Local playback]
//! [Audio playlist]
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://example.com/myfile1.mp3"));
playlist->addMedia(QUrl("http://example.com/myfile2.mp3"));
// ...
playlist->setCurrentIndex(1);
player->play();
//! [Audio playlist]
//! [Movie playlist]
playlist = new QMediaPlaylist;
playlist->addMedia(QUrl("http://example.com/movie1.mp4"));
@@ -194,7 +213,7 @@ void MediaExample::MediaRecorder()
recorder = new QMediaRecorder(camera);
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/vorbis");
audioSettings.setCodec("audio/amr");
audioSettings.setQuality(QtMultimedia::HighQuality);
recorder->setEncodingSettings(audioSettings);
@@ -202,6 +221,21 @@ void MediaExample::MediaRecorder()
recorder->setOutputLocation(QUrl::fromLocalFile(fileName));
recorder->record();
//! [Media recorder]
#if 0
//! [Audio recorder]
audioRecorder = new QAudioRecorder;
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/amr");
audioSettings.setQuality(QtMultimedia::HighQuality);
audioRecorder->setEncodingSettings(audioSettings);
audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
audioRecorder->record();
//! [Audio recorder]
#endif
}
void MediaExample::RadioTuna()

View File

@@ -1,317 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "player.h"
#include "playercontrols.h"
#include "playlistmodel.h"
#include "videowidget.h"
#include <qmediaservice.h>
#include <qmediaplaylist.h>
#include <QtWidgets>
Player::Player(QWidget *parent)
: QWidget(parent)
, videoWidget(0)
, coverLabel(0)
, slider(0)
, colorDialog(0)
{
//! [create-objs]
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
//! [create-objs]
connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged()));
connect(playlist, SIGNAL(playlistPositionChanged(int)), SLOT(playlistPositionChanged(int)));
connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));
connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int)));
videoWidget = new VideoWidget(player);
playlistModel = new PlaylistModel(this);
playlistModel->setPlaylist(playlist);
playlistView = new QListView;
playlistView->setModel(playlistModel);
playlistView->setCurrentIndex(playlistModel->index(playlist->currentPosition(), 0));
connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex)));
slider = new QSlider(Qt::Horizontal);
slider->setRange(0, player->duration() / 1000);
connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(seek(int)));
QPushButton *openButton = new QPushButton(tr("Open"));
connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
PlayerControls *controls = new PlayerControls;
controls->setState(player->state());
controls->setVolume(player->volume());
controls->setMuted(controls->isMuted());
connect(controls, SIGNAL(play()), player, SLOT(play()));
connect(controls, SIGNAL(pause()), player, SLOT(pause()));
connect(controls, SIGNAL(stop()), player, SLOT(stop()));
connect(controls, SIGNAL(next()), playlist, SLOT(next()));
connect(controls, SIGNAL(previous()), playlist, SLOT(previous()));
connect(controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int)));
connect(controls, SIGNAL(changeMuting(bool)), player, SLOT(setMuted(bool)));
connect(controls, SIGNAL(changeRate(qreal)), player, SLOT(setPlaybackRate(qreal)));
connect(player, SIGNAL(stateChanged(QMediaPlayer::State)),
controls, SLOT(setState(QMediaPlayer::State)));
connect(player, SIGNAL(volumeChanged(int)), controls, SLOT(setVolume(int)));
connect(player, SIGNAL(mutingChanged(bool)), controls, SLOT(setMuted(bool)));
QPushButton *fullScreenButton = new QPushButton(tr("FullScreen"));
fullScreenButton->setCheckable(true);
if (videoWidget != 0) {
connect(fullScreenButton, SIGNAL(clicked(bool)), videoWidget, SLOT(setFullScreen(bool)));
connect(videoWidget, SIGNAL(fullScreenChanged(bool)),
fullScreenButton, SLOT(setChecked(bool)));
} else {
fullScreenButton->setEnabled(false);
}
QPushButton *colorButton = new QPushButton(tr("Color Options..."));
if (videoWidget)
connect(colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
else
colorButton->setEnabled(false);
QBoxLayout *displayLayout = new QHBoxLayout;
if (videoWidget)
displayLayout->addWidget(videoWidget, 2);
else
displayLayout->addWidget(coverLabel, 2);
displayLayout->addWidget(playlistView);
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
controlLayout->addWidget(openButton);
controlLayout->addStretch(1);
controlLayout->addWidget(controls);
controlLayout->addStretch(1);
controlLayout->addWidget(fullScreenButton);
controlLayout->addWidget(colorButton);
QBoxLayout *layout = new QVBoxLayout;
layout->addLayout(displayLayout);
layout->addWidget(slider);
layout->addLayout(controlLayout);
setLayout(layout);
metaDataChanged();
}
Player::~Player()
{
delete playlist;
delete player;
}
void Player::open()
{
QStringList fileNames = QFileDialog::getOpenFileNames();
foreach (QString const &fileName, fileNames)
playlist->appendItem(QUrl::fromLocalFile(fileName));
}
void Player::durationChanged(qint64 duration)
{
slider->setMaximum(duration / 1000);
}
void Player::positionChanged(qint64 progress)
{
slider->setValue(progress / 1000);
}
void Player::metaDataChanged()
{
//qDebug() << "update metadata" << player->metaData(QtMultimedia::MetaData::Title).toString();
if (player->isMetaDataAvailable()) {
setTrackInfo(QString("%1 - %2")
.arg(player->metaData(QtMultimedia::MetaData::AlbumArtist).toString())
.arg(player->metaData(QtMultimedia::MetaData::Title).toString()));
if (coverLabel) {
QUrl url = player->metaData(QtMultimedia::MetaData::CoverArtUrlLarge).value<QUrl>();
coverLabel->setPixmap(!url.isEmpty()
? QPixmap(url.toString())
: QPixmap());
}
}
}
void Player::jump(const QModelIndex &index)
{
if (index.isValid()) {
playlist->setCurrentPosition(index.row());
}
}
void Player::playlistPositionChanged(int currentItem)
{
playlistView->setCurrentIndex(playlistModel->index(currentItem, 0));
}
void Player::seek(int seconds)
{
player->setPosition(seconds * 1000);
}
void Player::statusChanged(QMediaPlayer::MediaStatus status)
{
switch (status) {
case QMediaPlayer::UnknownMediaStatus:
case QMediaPlayer::NoMedia:
case QMediaPlayer::LoadedMedia:
case QMediaPlayer::BufferingMedia:
case QMediaPlayer::BufferedMedia:
#ifndef QT_NO_CURSOR
unsetCursor();
#endif
setStatusInfo(QString());
break;
case QMediaPlayer::LoadingMedia:
#ifndef QT_NO_CURSOR
setCursor(QCursor(Qt::BusyCursor));
#endif
setStatusInfo(tr("Loading..."));
break;
case QMediaPlayer::StalledMedia:
#ifndef QT_NO_CURSOR
setCursor(QCursor(Qt::BusyCursor));
#endif
break;
case QMediaPlayer::EndOfMedia:
#ifndef QT_NO_CURSOR
unsetCursor();
#endif
setStatusInfo(QString());
QApplication::alert(this);
break;
case QMediaPlayer::InvalidMedia:
#ifndef QT_NO_CURSOR
unsetCursor();
#endif
setStatusInfo(player->errorString());
break;
}
}
void Player::bufferingProgress(int progress)
{
setStatusInfo(tr("Buffering %4%%").arg(progress));
}
void Player::setTrackInfo(const QString &info)
{
trackInfo = info;
if (!statusInfo.isEmpty())
setWindowTitle(QString("%1 | %2").arg(trackInfo).arg(statusInfo));
else
setWindowTitle(trackInfo);
}
void Player::setStatusInfo(const QString &info)
{
statusInfo = info;
if (!statusInfo.isEmpty())
setWindowTitle(QString("%1 | %2").arg(trackInfo).arg(statusInfo));
else
setWindowTitle(trackInfo);
}
void Player::showColorDialog()
{
if (!colorDialog) {
QSlider *brightnessSlider = new QSlider(Qt::Horizontal);
brightnessSlider->setRange(-100, 100);
brightnessSlider->setValue(videoWidget->brightness());
connect(brightnessSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setBrightness(int)));
connect(videoWidget, SIGNAL(brightnessChanged(int)), brightnessSlider, SLOT(setValue(int)));
QSlider *contrastSlider = new QSlider(Qt::Horizontal);
contrastSlider->setRange(-100, 100);
contrastSlider->setValue(videoWidget->contrast());
connect(contrastSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setContrast(int)));
connect(videoWidget, SIGNAL(contrastChanged(int)), contrastSlider, SLOT(setValue(int)));
QSlider *hueSlider = new QSlider(Qt::Horizontal);
hueSlider->setRange(-100, 100);
hueSlider->setValue(videoWidget->hue());
connect(hueSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setHue(int)));
connect(videoWidget, SIGNAL(hueChanged(int)), hueSlider, SLOT(setValue(int)));
QSlider *saturationSlider = new QSlider(Qt::Horizontal);
saturationSlider->setRange(-100, 100);
saturationSlider->setValue(videoWidget->saturation());
connect(saturationSlider, SIGNAL(sliderMoved(int)), videoWidget, SLOT(setSaturation(int)));
connect(videoWidget, SIGNAL(saturationChanged(int)), saturationSlider, SLOT(setValue(int)));
QFormLayout *layout = new QFormLayout;
layout->addRow(tr("Brightness"), brightnessSlider);
layout->addRow(tr("Contrast"), contrastSlider);
layout->addRow(tr("Hue"), hueSlider);
layout->addRow(tr("Saturation"), saturationSlider);
colorDialog = new QDialog(this);
colorDialog->setWindowTitle(tr("Color Options"));
colorDialog->setLayout(layout);
}
colorDialog->show();
}

View File

@@ -47,6 +47,7 @@
#include "qvideowidgetcontrol.h"
#include "qvideowindowcontrol.h"
#include "qgraphicsvideoitem.h"
#include "qmediaplaylist.h"
#include <QFormLayout>
#include <QGraphicsView>
@@ -63,6 +64,7 @@ public:
private:
// Common naming
QMediaService *mediaService;
QMediaPlaylist *playlist;
QVideoWidget *videoWidget;
QWidget *widget;
QFormLayout *layout;
@@ -85,12 +87,15 @@ void VideoExample::VideoWidget()
//! [Video widget]
player = new QMediaPlayer;
videoWidget = new QVideoWidget;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
player->setMedia(QUrl("http://example.com/movie.mp4"));
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();
//! [Video widget]
}
@@ -123,7 +128,7 @@ void VideoExample::VideoGraphicsItem()
graphicsView->scene()->addItem(item);
graphicsView->show();
player->setMedia(video);
player->setMedia(QUrl("http://example.com/myclip4.ogv"));
player->play();
//! [Video graphics item]
}