Doc: Updated the \example and \snippet paths
Also: - Grouped the example docs under one group. i.e. multimedia-examples - Moved the \group page here from the qtdoc repo - Moved the snippets directory under doc from doc/src Change-Id: I28fb81cf910e58101cd601fb4c440b59b0b0366d Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
5cd23af26c
commit
0241b0e39c
251
src/multimedia/doc/snippets/multimedia-snippets/audio.cpp
Normal file
251
src/multimedia/doc/snippets/multimedia-snippets/audio.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Mobility Components.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* Audio related snippets */
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
#include "qaudiodeviceinfo.h"
|
||||
#include "qaudioinput.h"
|
||||
#include "qaudiooutput.h"
|
||||
#include "qaudioprobe.h"
|
||||
#include "qaudiodecoder.h"
|
||||
|
||||
class AudioInputExample : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void setup();
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void stopRecording();
|
||||
void stateChanged(QAudio::State newState);
|
||||
|
||||
private:
|
||||
//! [Audio input class members]
|
||||
QFile destinationFile; // class member.
|
||||
QAudioInput* audio; // class member.
|
||||
//! [Audio input class members]
|
||||
};
|
||||
|
||||
|
||||
void AudioInputExample::setup()
|
||||
//! [Audio input setup]
|
||||
{
|
||||
destinationFile.setFileName("/tmp/test.raw");
|
||||
destinationFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
|
||||
|
||||
QAudioFormat format;
|
||||
// set up the format you want, eg.
|
||||
format.setSampleRate(8000);
|
||||
format.setChannelCount(1);
|
||||
format.setSampleSize(8);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setSampleType(QAudioFormat::UnSignedInt);
|
||||
|
||||
QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
|
||||
if (!info.isFormatSupported(format)) {
|
||||
qWarning()<<"default format not supported try to use nearest";
|
||||
format = info.nearestFormat(format);
|
||||
}
|
||||
|
||||
audio = new QAudioInput(format, this);
|
||||
connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
|
||||
|
||||
QTimer::singleShot(3000, this, SLOT(stopRecording()));
|
||||
audio->start(&destinationFile);
|
||||
// Records audio for 3000ms
|
||||
}
|
||||
//! [Audio input setup]
|
||||
|
||||
//! [Audio input stop recording]
|
||||
void AudioInputExample::stopRecording()
|
||||
{
|
||||
audio->stop();
|
||||
destinationFile.close();
|
||||
delete audio;
|
||||
}
|
||||
//! [Audio input stop recording]
|
||||
|
||||
//! [Audio input state changed]
|
||||
void AudioInputExample::stateChanged(QAudio::State newState)
|
||||
{
|
||||
switch (newState) {
|
||||
case QAudio::StoppedState:
|
||||
if (audio->error() != QAudio::NoError) {
|
||||
// Error handling
|
||||
} else {
|
||||
// Finished recording
|
||||
}
|
||||
break;
|
||||
|
||||
case QAudio::ActiveState:
|
||||
// Started recording - read from IO device
|
||||
break;
|
||||
|
||||
default:
|
||||
// ... other cases as appropriate
|
||||
break;
|
||||
}
|
||||
}
|
||||
//! [Audio input state changed]
|
||||
|
||||
|
||||
class AudioOutputExample : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void setup();
|
||||
|
||||
public Q_SLOTS:
|
||||
void stateChanged(QAudio::State newState);
|
||||
|
||||
private:
|
||||
//! [Audio output class members]
|
||||
QFile sourceFile; // class member.
|
||||
QAudioOutput* audio; // class member.
|
||||
//! [Audio output class members]
|
||||
};
|
||||
|
||||
|
||||
void AudioOutputExample::setup()
|
||||
//! [Audio output setup]
|
||||
{
|
||||
sourceFile.setFileName("/tmp/test.raw");
|
||||
sourceFile.open(QIODevice::ReadOnly);
|
||||
|
||||
QAudioFormat format;
|
||||
// Set up the format, eg.
|
||||
format.setSampleRate(8000);
|
||||
format.setChannelCount(1);
|
||||
format.setSampleSize(8);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setSampleType(QAudioFormat::UnSignedInt);
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
||||
if (!info.isFormatSupported(format)) {
|
||||
qWarning() << "raw audio format not supported by backend, cannot play audio.";
|
||||
return;
|
||||
}
|
||||
|
||||
audio = new QAudioOutput(format, this);
|
||||
connect(audio, SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
|
||||
audio->start(&sourceFile);
|
||||
}
|
||||
//! [Audio output setup]
|
||||
|
||||
//! [Audio output state changed]
|
||||
void AudioOutputExample::stateChanged(QAudio::State newState)
|
||||
{
|
||||
switch (newState) {
|
||||
case QAudio::IdleState:
|
||||
// Finished playing (no more data)
|
||||
audio->stop();
|
||||
sourceFile.close();
|
||||
delete audio;
|
||||
break;
|
||||
|
||||
case QAudio::StoppedState:
|
||||
// Stopped for other reasons
|
||||
if (audio->error() != QAudio::NoError) {
|
||||
// Error handling
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// ... other cases as appropriate
|
||||
break;
|
||||
}
|
||||
}
|
||||
//! [Audio output state changed]
|
||||
|
||||
void AudioDeviceInfo()
|
||||
{
|
||||
//! [Setting audio format]
|
||||
QAudioFormat format;
|
||||
format.setSampleRate(44100);
|
||||
// ... other format parameters
|
||||
format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
||||
|
||||
if (!info.isFormatSupported(format))
|
||||
format = info.nearestFormat(format);
|
||||
//! [Setting audio format]
|
||||
|
||||
//! [Dumping audio formats]
|
||||
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
|
||||
qDebug() << "Device name: " << deviceInfo.deviceName();
|
||||
//! [Dumping audio formats]
|
||||
}
|
||||
|
||||
class AudioDecodingExample : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void decode();
|
||||
|
||||
public Q_SLOTS:
|
||||
void stateChanged(QAudio::State newState);
|
||||
void readBuffer();
|
||||
};
|
||||
|
||||
void AudioDecodingExample::decode()
|
||||
{
|
||||
//! [Local audio decoding]
|
||||
QAudioFormat desiredFormat;
|
||||
desiredFormat.setChannelCount(2);
|
||||
desiredFormat.setCodec("audio/x-raw");
|
||||
desiredFormat.setSampleType(QAudioFormat::UnSignedInt);
|
||||
desiredFormat.setSampleRate(48000);
|
||||
desiredFormat.setSampleSize(16);
|
||||
|
||||
QAudioDecoder *decoder = new QAudioDecoder(this);
|
||||
decoder->setAudioFormat(desiredFormat);
|
||||
decoder->setSourceFilename("level1.mp3");
|
||||
|
||||
connect(decoder, SIGNAL(bufferReady()), this, SLOT(readBuffer()));
|
||||
decoder->start();
|
||||
|
||||
// Now wait for bufferReady() signal and call decoder->read()
|
||||
//! [Local audio decoding]
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Mobility Components.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include <qaudiorecorder.h>
|
||||
#include <qmediaservice.h>
|
||||
|
||||
#include <QtMultimedia/qaudioformat.h>
|
||||
|
||||
#include "audiorecorder.h"
|
||||
|
||||
AudioRecorder::AudioRecorder()
|
||||
{
|
||||
//! [create-objs-1]
|
||||
capture = new QAudioRecorder();
|
||||
//! [create-objs-1]
|
||||
|
||||
// set a default file
|
||||
capture->setOutputLocation(QUrl("test.raw"));
|
||||
|
||||
QWidget *window = new QWidget;
|
||||
QGridLayout* layout = new QGridLayout;
|
||||
|
||||
QLabel* deviceLabel = new QLabel;
|
||||
deviceLabel->setText("Devices");
|
||||
deviceBox = new QComboBox(this);
|
||||
deviceBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
|
||||
|
||||
QLabel* codecLabel = new QLabel;
|
||||
codecLabel->setText("Codecs");
|
||||
codecsBox = new QComboBox(this);
|
||||
codecsBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
|
||||
|
||||
QLabel* qualityLabel = new QLabel;
|
||||
qualityLabel->setText("Quality");
|
||||
qualityBox = new QComboBox(this);
|
||||
qualityBox->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
|
||||
|
||||
//! [device-list]
|
||||
for(int i = 0; i < audiosource->deviceCount(); i++)
|
||||
deviceBox->addItem(audiosource->name(i));
|
||||
//! [device-list]
|
||||
|
||||
//! [codec-list]
|
||||
QStringList codecs = capture->supportedAudioCodecs();
|
||||
for(int i = 0; i < codecs.count(); i++)
|
||||
codecsBox->addItem(codecs.at(i));
|
||||
//! [codec-list]
|
||||
|
||||
qualityBox->addItem("Low");
|
||||
qualityBox->addItem("Medium");
|
||||
qualityBox->addItem("High");
|
||||
|
||||
connect(capture, SIGNAL(durationChanged(qint64)), this, SLOT(updateProgress(qint64)));
|
||||
connect(capture, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(stateChanged(QMediaRecorder::State)));
|
||||
|
||||
layout->addWidget(deviceLabel,0,0,Qt::AlignHCenter);
|
||||
connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int)));
|
||||
layout->addWidget(deviceBox,0,1,1,3,Qt::AlignLeft);
|
||||
|
||||
layout->addWidget(codecLabel,1,0,Qt::AlignHCenter);
|
||||
connect(codecsBox,SIGNAL(activated(int)),SLOT(codecChanged(int)));
|
||||
layout->addWidget(codecsBox,1,1,Qt::AlignLeft);
|
||||
|
||||
layout->addWidget(qualityLabel,1,2,Qt::AlignHCenter);
|
||||
connect(qualityBox,SIGNAL(activated(int)),SLOT(qualityChanged(int)));
|
||||
layout->addWidget(qualityBox,1,3,Qt::AlignLeft);
|
||||
|
||||
fileButton = new QPushButton(this);
|
||||
fileButton->setText(tr("Output File"));
|
||||
connect(fileButton,SIGNAL(clicked()),SLOT(selectOutputFile()));
|
||||
layout->addWidget(fileButton,3,0,Qt::AlignHCenter);
|
||||
|
||||
button = new QPushButton(this);
|
||||
button->setText(tr("Record"));
|
||||
connect(button,SIGNAL(clicked()),SLOT(toggleRecord()));
|
||||
layout->addWidget(button,3,3,Qt::AlignHCenter);
|
||||
|
||||
recTime = new QLabel;
|
||||
recTime->setText("0 sec");
|
||||
layout->addWidget(recTime,4,0,Qt::AlignHCenter);
|
||||
|
||||
window->setLayout(layout);
|
||||
setCentralWidget(window);
|
||||
window->show();
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
AudioRecorder::~AudioRecorder()
|
||||
{
|
||||
delete capture;
|
||||
delete audiosource;
|
||||
}
|
||||
|
||||
void AudioRecorder::updateProgress(qint64 pos)
|
||||
{
|
||||
currentTime = pos;
|
||||
if(currentTime == 0) currentTime = 1;
|
||||
QString text = QString("%1 secs").arg(currentTime/1000);
|
||||
recTime->setText(text);
|
||||
}
|
||||
|
||||
void AudioRecorder::stateChanged(QMediaRecorder::State state)
|
||||
{
|
||||
qWarning()<<"stateChanged() "<<state;
|
||||
}
|
||||
|
||||
void AudioRecorder::deviceChanged(int idx)
|
||||
{
|
||||
//! [get-device]
|
||||
for(int i = 0; i < audiosource->deviceCount(); i++) {
|
||||
if(deviceBox->itemText(idx).compare(audiosource->name(i)) == 0)
|
||||
audiosource->setSelectedDevice(i);
|
||||
}
|
||||
//! [get-device]
|
||||
}
|
||||
|
||||
void AudioRecorder::codecChanged(int idx)
|
||||
{
|
||||
Q_UNUSED(idx);
|
||||
//capture->setAudioCodec(codecsBox->itemText(idx));
|
||||
}
|
||||
|
||||
void AudioRecorder::qualityChanged(int idx)
|
||||
{
|
||||
Q_UNUSED(idx);
|
||||
/*
|
||||
if(capture->audioCodec().compare("audio/pcm") == 0) {
|
||||
if(qualityBox->itemText(idx).compare("Low") == 0) {
|
||||
// 8000Hz mono is 8kbps
|
||||
capture->setAudioBitrate(8);
|
||||
} else if(qualityBox->itemText(idx).compare("Medium") == 0) {
|
||||
// 22050Hz mono is 44.1kbps
|
||||
capture->setAudioBitrate(44);
|
||||
} else if(qualityBox->itemText(idx).compare("High") == 0) {
|
||||
// 44100Hz mono is 88.2kbps
|
||||
capture->setAudioBitrate(88);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//! [toggle-record]
|
||||
void AudioRecorder::toggleRecord()
|
||||
{
|
||||
if(!active) {
|
||||
recTime->setText("0 sec");
|
||||
currentTime = 0;
|
||||
capture->record();
|
||||
|
||||
button->setText(tr("Stop"));
|
||||
active = true;
|
||||
} else {
|
||||
capture->stop();
|
||||
button->setText(tr("Record"));
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
//! [toggle-record]
|
||||
|
||||
void AudioRecorder::selectOutputFile()
|
||||
{
|
||||
QStringList fileNames;
|
||||
|
||||
QFileDialog dialog(this);
|
||||
|
||||
dialog.setFileMode(QFileDialog::AnyFile);
|
||||
if (dialog.exec())
|
||||
fileNames = dialog.selectedFiles();
|
||||
|
||||
if(fileNames.size() > 0)
|
||||
capture->setOutputLocation(QUrl(fileNames.first()));
|
||||
}
|
||||
201
src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
Normal file
201
src/multimedia/doc/snippets/multimedia-snippets/camera.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Mobility Components.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* Camera snippets */
|
||||
|
||||
#include "qcamera.h"
|
||||
#include "qcameraviewfinder.h"
|
||||
#include "qmediarecorder.h"
|
||||
#include "qcameraimagecapture.h"
|
||||
#include "qcameraimageprocessing.h"
|
||||
#include "qabstractvideosurface.h"
|
||||
|
||||
/* Globals so that everything is consistent. */
|
||||
QCamera *camera = 0;
|
||||
QCameraViewfinder *viewfinder = 0;
|
||||
QMediaRecorder *recorder = 0;
|
||||
QCameraImageCapture *imageCapture = 0;
|
||||
|
||||
void overview_viewfinder()
|
||||
{
|
||||
//! [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 capture]
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
viewfinder = new QCameraViewfinder();
|
||||
viewfinder->show();
|
||||
|
||||
camera->setViewfinder(viewfinder);
|
||||
|
||||
imageCapture = new QCameraImageCapture(camera);
|
||||
|
||||
camera->setCaptureMode(QCamera::CaptureStillImage);
|
||||
camera->start();
|
||||
//! [Camera]
|
||||
|
||||
//! [Camera keys]
|
||||
//on half pressed shutter button
|
||||
camera->searchAndLock();
|
||||
|
||||
//on shutter button pressed
|
||||
imageCapture->capture();
|
||||
|
||||
//on shutter button released
|
||||
camera->unlock();
|
||||
//! [Camera keys]
|
||||
}
|
||||
|
||||
void cameraimageprocessing()
|
||||
{
|
||||
//! [Camera image whitebalance]
|
||||
camera = new QCamera;
|
||||
QCameraImageProcessing *imageProcessing = camera->imageProcessing();
|
||||
|
||||
if (imageProcessing->isAvailable()) {
|
||||
imageProcessing->setWhiteBalanceMode(QCameraImageProcessing::WhiteBalanceFluorescent);
|
||||
}
|
||||
//! [Camera image whitebalance]
|
||||
|
||||
//! [Camera image denoising]
|
||||
imageProcessing->setDenoisingLevel(-0.3); //reduce the amount of denoising applied
|
||||
//! [Camera image denoising]
|
||||
}
|
||||
|
||||
void camerafocus()
|
||||
{
|
||||
//! [Camera custom zoom]
|
||||
QCameraFocus *focus = camera->focus();
|
||||
focus->setFocusPointMode(QCameraFocus::FocusPointCustom);
|
||||
focus->setCustomFocusPoint(QPointF(0.25f, 0.75f)); // A point near the bottom left, 25% away from the corner, near that shiny vase
|
||||
//! [Camera custom zoom]
|
||||
|
||||
//! [Camera combined zoom]
|
||||
focus->zoomTo(3.0, 4.0); // Super zoom!
|
||||
//! [Camera combined zoom]
|
||||
|
||||
//! [Camera focus zones]
|
||||
focus->setFocusPointMode(QCameraFocus::FocusPointAuto);
|
||||
QList<QCameraFocusZone> zones = focus->focusZones();
|
||||
foreach (QCameraFocusZone zone, zones) {
|
||||
if (zone.status() == QCameraFocusZone::Focused) {
|
||||
// Draw a green box at zone.area()
|
||||
} else if (zone.status() == QCameraFocusZone::Selected) {
|
||||
// This area is selected for autofocusing, but is not in focus
|
||||
// Draw a yellow box at zone.area()
|
||||
}
|
||||
}
|
||||
//! [Camera focus zones]
|
||||
}
|
||||
315
src/multimedia/doc/snippets/multimedia-snippets/media.cpp
Normal file
315
src/multimedia/doc/snippets/multimedia-snippets/media.cpp
Normal file
@@ -0,0 +1,315 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Mobility Components.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* Media related snippets */
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
|
||||
#include "qmediaplaylist.h"
|
||||
#include "qmediarecorder.h"
|
||||
#include "qmediaservice.h"
|
||||
#include "qmediaplayercontrol.h"
|
||||
#include "qmediaplayer.h"
|
||||
#include "qradiotuner.h"
|
||||
#include "qradiodata.h"
|
||||
#include "qvideowidget.h"
|
||||
#include "qcameraimagecapture.h"
|
||||
#include "qcamera.h"
|
||||
#include "qcameraviewfinder.h"
|
||||
#include "qaudioprobe.h"
|
||||
#include "qaudiorecorder.h"
|
||||
#include "qvideoprobe.h"
|
||||
|
||||
class MediaExample : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
void MediaControl();
|
||||
void MediaPlayer();
|
||||
void RadioTuna();
|
||||
void MediaRecorder();
|
||||
void AudioRecorder();
|
||||
void EncoderSettings();
|
||||
void ImageEncoderSettings();
|
||||
void AudioProbe();
|
||||
void VideoProbe();
|
||||
|
||||
private:
|
||||
// Common naming
|
||||
QMediaService *mediaService;
|
||||
QVideoWidget *videoWidget;
|
||||
QWidget *widget;
|
||||
QMediaPlayer *player;
|
||||
QMediaPlaylist *playlist;
|
||||
QMediaContent video;
|
||||
QMediaRecorder *recorder;
|
||||
QCamera *camera;
|
||||
QCameraViewfinder *viewfinder;
|
||||
QCameraImageCapture *imageCapture;
|
||||
QString fileName;
|
||||
QRadioTuner *radio;
|
||||
QRadioData *radioData;
|
||||
QAudioRecorder *audioRecorder;
|
||||
QAudioProbe *audioProbe;
|
||||
QVideoProbe *videoProbe;
|
||||
|
||||
QMediaContent image1;
|
||||
QMediaContent image2;
|
||||
QMediaContent image3;
|
||||
|
||||
static const int yourRadioStationFrequency = 11;
|
||||
};
|
||||
|
||||
void MediaExample::MediaControl()
|
||||
{
|
||||
{
|
||||
//! [Request control]
|
||||
QMediaPlayerControl *control = qobject_cast<QMediaPlayerControl *>(
|
||||
mediaService->requestControl("org.qt-project.qt.mediaplayercontrol/5.0"));
|
||||
//! [Request control]
|
||||
Q_UNUSED(control);
|
||||
}
|
||||
|
||||
{
|
||||
//! [Request control templated]
|
||||
QMediaPlayerControl *control = mediaService->requestControl<QMediaPlayerControl *>();
|
||||
//! [Request control templated]
|
||||
Q_UNUSED(control);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MediaExample::EncoderSettings()
|
||||
{
|
||||
//! [Audio encoder settings]
|
||||
QAudioEncoderSettings audioSettings;
|
||||
audioSettings.setCodec("audio/mpeg");
|
||||
audioSettings.setChannelCount(2);
|
||||
|
||||
recorder->setAudioSettings(audioSettings);
|
||||
//! [Audio encoder settings]
|
||||
|
||||
//! [Video encoder settings]
|
||||
QVideoEncoderSettings videoSettings;
|
||||
videoSettings.setCodec("video/mpeg2");
|
||||
videoSettings.setResolution(640, 480);
|
||||
|
||||
recorder->setVideoSettings(videoSettings);
|
||||
//! [Video encoder settings]
|
||||
}
|
||||
|
||||
void MediaExample::ImageEncoderSettings()
|
||||
{
|
||||
//! [Image encoder settings]
|
||||
QImageEncoderSettings imageSettings;
|
||||
imageSettings.setCodec("image/jpeg");
|
||||
imageSettings.setResolution(1600, 1200);
|
||||
|
||||
imageCapture->setEncodingSettings(imageSettings);
|
||||
//! [Image encoder settings]
|
||||
}
|
||||
|
||||
void MediaExample::MediaPlayer()
|
||||
{
|
||||
//! [Player]
|
||||
player = new QMediaPlayer;
|
||||
connect(player, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
|
||||
player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
|
||||
player->setVolume(50);
|
||||
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"));
|
||||
playlist->addMedia(QUrl("http://example.com/movie2.mp4"));
|
||||
playlist->addMedia(QUrl("http://example.com/movie3.mp4"));
|
||||
playlist->setCurrentIndex(1);
|
||||
|
||||
player = new QMediaPlayer;
|
||||
player->setPlaylist(playlist);
|
||||
|
||||
videoWidget = new QVideoWidget;
|
||||
player->setVideoOutput(videoWidget);
|
||||
videoWidget->show();
|
||||
|
||||
player->play();
|
||||
//! [Movie playlist]
|
||||
}
|
||||
|
||||
void MediaExample::MediaRecorder()
|
||||
{
|
||||
//! [Media recorder]
|
||||
recorder = new QMediaRecorder(camera);
|
||||
|
||||
QAudioEncoderSettings audioSettings;
|
||||
audioSettings.setCodec("audio/amr");
|
||||
audioSettings.setQuality(QMultimedia::HighQuality);
|
||||
|
||||
recorder->setAudioSettings(audioSettings);
|
||||
|
||||
recorder->setOutputLocation(QUrl::fromLocalFile(fileName));
|
||||
recorder->record();
|
||||
//! [Media recorder]
|
||||
}
|
||||
|
||||
void MediaExample::AudioRecorder()
|
||||
{
|
||||
//! [Audio recorder]
|
||||
audioRecorder = new QAudioRecorder;
|
||||
|
||||
QAudioEncoderSettings audioSettings;
|
||||
audioSettings.setCodec("audio/amr");
|
||||
audioSettings.setQuality(QMultimedia::HighQuality);
|
||||
|
||||
audioRecorder->setEncodingSettings(audioSettings);
|
||||
|
||||
audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
|
||||
audioRecorder->record();
|
||||
//! [Audio recorder]
|
||||
|
||||
//! [Audio recorder inputs]
|
||||
QStringList inputs = audioRecorder->audioInputs();
|
||||
QString selectedInput = audioRecorder->defaultAudioInput();
|
||||
|
||||
foreach (QString input, inputs) {
|
||||
QString description = audioRecorder->audioInputDescription(input);
|
||||
// show descriptions to user and allow selection
|
||||
selectedInput = input;
|
||||
}
|
||||
|
||||
audioRecorder->setAudioInput(selectedInput);
|
||||
//! [Audio recorder inputs]
|
||||
}
|
||||
|
||||
void MediaExample::RadioTuna()
|
||||
{
|
||||
//! [Radio tuner]
|
||||
radio = new QRadioTuner;
|
||||
connect(radio, SIGNAL(frequencyChanged(int)), this, SLOT(freqChanged(int)));
|
||||
if (radio->isBandSupported(QRadioTuner::FM)) {
|
||||
radio->setBand(QRadioTuner::FM);
|
||||
radio->setFrequency(yourRadioStationFrequency);
|
||||
radio->setVolume(100);
|
||||
radio->start();
|
||||
}
|
||||
//! [Radio tuner]
|
||||
|
||||
//! [Radio data setup]
|
||||
radio = new QRadioTuner;
|
||||
radioData = radio->radioData();
|
||||
//! [Radio data setup]
|
||||
}
|
||||
|
||||
void MediaExample::AudioProbe()
|
||||
{
|
||||
//! [Audio probe]
|
||||
audioRecorder = new QAudioRecorder;
|
||||
|
||||
QAudioEncoderSettings audioSettings;
|
||||
audioSettings.setCodec("audio/amr");
|
||||
audioSettings.setQuality(QMultimedia::HighQuality);
|
||||
|
||||
audioRecorder->setEncodingSettings(audioSettings);
|
||||
|
||||
audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
|
||||
|
||||
audioProbe = new QAudioProbe(this);
|
||||
if (audioProbe->setSource(audioRecorder)) {
|
||||
// Probing succeeded, audioProbe->isValid() should be true.
|
||||
connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)),
|
||||
this, SLOT(calculateLevel(QAudioBuffer)));
|
||||
}
|
||||
|
||||
audioRecorder->record();
|
||||
// Now audio buffers being recorded should be signaled
|
||||
// by the probe, so we can do things like calculating the
|
||||
// audio power level, or performing a frequency transform
|
||||
//! [Audio probe]
|
||||
}
|
||||
|
||||
void MediaExample::VideoProbe()
|
||||
{
|
||||
//! [Video probe]
|
||||
camera = new QCamera;
|
||||
viewfinder = new QCameraViewfinder();
|
||||
camera->setViewfinder(viewfinder);
|
||||
|
||||
camera->setCaptureMode(QCamera::CaptureVideo);
|
||||
|
||||
videoProbe = new QVideoProbe(this);
|
||||
|
||||
if (videoProbe->setSource(camera)) {
|
||||
// Probing succeeded, videoProbe->isValid() should be true.
|
||||
connect(videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)),
|
||||
this, SLOT(detectBarcodes(QVideoFrame)));
|
||||
}
|
||||
|
||||
camera->start();
|
||||
// Viewfinder frames should now also be emitted by
|
||||
// the video probe, even in still image capture mode.
|
||||
// Another alternative is to install the probe on a
|
||||
// QMediaRecorder connected to the camera to get the
|
||||
// recorded frames, if they are different from the
|
||||
// viewfinder frames.
|
||||
|
||||
//! [Video probe]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Doc snippets - compiled for truthiness
|
||||
|
||||
TEMPLATE = lib
|
||||
TARGET = qtmmksnippets
|
||||
|
||||
INCLUDEPATH += ../../../../src/global \
|
||||
../../../../src/multimedia \
|
||||
../../../../src/multimedia/audio \
|
||||
../../../../src/multimedia/video \
|
||||
../../../../src/multimedia/camera
|
||||
|
||||
CONFIG += console
|
||||
|
||||
QT += multimedia multimediawidgets widgets multimedia-private
|
||||
|
||||
SOURCES += \
|
||||
audio.cpp \
|
||||
video.cpp \
|
||||
camera.cpp \
|
||||
media.cpp \
|
||||
qsound.cpp
|
||||
|
||||
OTHER_FILES += \
|
||||
soundeffect.qml
|
||||
85
src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp
Normal file
85
src/multimedia/doc/snippets/multimedia-snippets/qsound.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the documentation of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:BSD$
|
||||
** You may use this file under the terms of the BSD license as follows:
|
||||
**
|
||||
** "Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are
|
||||
** met:
|
||||
** * Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in
|
||||
** the documentation and/or other materials provided with the
|
||||
** distribution.
|
||||
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
|
||||
** of its contributors may be used to endorse or promote products derived
|
||||
** from this software without specific prior written permission.
|
||||
**
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qobject.h"
|
||||
#include "qsound.h"
|
||||
#include "qsoundeffect.h"
|
||||
|
||||
void qsoundsnippet() {
|
||||
//! [0]
|
||||
QSound::play("mysounds/bells.wav");
|
||||
//! [0]
|
||||
|
||||
|
||||
//! [1]
|
||||
QSound bells("mysounds/bells.wav");
|
||||
bells.play();
|
||||
//! [1]
|
||||
}
|
||||
|
||||
void qsoundeffectsnippet() {
|
||||
//! [2]
|
||||
QSoundEffect effect;
|
||||
effect.setSource(QUrl::fromLocalFile("engine.wav"));
|
||||
effect.setLoopCount(QSoundEffect::Infinite);
|
||||
effect.setVolume(0.25f);
|
||||
effect.play();
|
||||
//! [2]
|
||||
}
|
||||
|
||||
QObject *clickSource;
|
||||
|
||||
class MyGame : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
//! [3]
|
||||
MyGame()
|
||||
: m_explosion(this)
|
||||
{
|
||||
m_explosion.setSource(QUrl::fromLocalFile("explosion.wav"));
|
||||
m_explosion.setVolume(0.25f);
|
||||
|
||||
// Set up click handling etc.
|
||||
connect(clickSource, SIGNAL(clicked()), &m_explosion, SLOT(play()));
|
||||
}
|
||||
private:
|
||||
QSoundEffect m_explosion;
|
||||
//! [3]
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
//! [complete snippet]
|
||||
import QtQuick 2.0
|
||||
import QtMultimedia 5.0
|
||||
|
||||
Text {
|
||||
text: "Click Me!";
|
||||
font.pointSize: 24;
|
||||
width: 150; height: 50;
|
||||
|
||||
//! [play sound on click]
|
||||
SoundEffect {
|
||||
id: playSound
|
||||
source: "soundeffect.wav"
|
||||
}
|
||||
MouseArea {
|
||||
id: playArea
|
||||
anchors.fill: parent
|
||||
onPressed: { playSound.play() }
|
||||
}
|
||||
//! [play sound on click]
|
||||
}
|
||||
//! [complete snippet]
|
||||
193
src/multimedia/doc/snippets/multimedia-snippets/video.cpp
Normal file
193
src/multimedia/doc/snippets/multimedia-snippets/video.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/legal
|
||||
**
|
||||
** This file is part of the Qt Mobility Components.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Digia. For licensing terms and
|
||||
** conditions see http://qt.digia.com/licensing. For further information
|
||||
** use the contact form at http://qt.digia.com/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, 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, Digia gives you certain additional
|
||||
** rights. These rights are described in the Digia 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.
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* Video related snippets */
|
||||
#include "qvideorenderercontrol.h"
|
||||
#include "qmediaservice.h"
|
||||
#include "qmediaplayer.h"
|
||||
#include "qabstractvideosurface.h"
|
||||
#include "qvideowidgetcontrol.h"
|
||||
#include "qvideowindowcontrol.h"
|
||||
#include "qgraphicsvideoitem.h"
|
||||
#include "qmediaplaylist.h"
|
||||
#include "qvideosurfaceformat.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QGraphicsView>
|
||||
|
||||
//! [Derived Surface]
|
||||
class MyVideoSurface : public QAbstractVideoSurface
|
||||
{
|
||||
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
|
||||
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const
|
||||
{
|
||||
Q_UNUSED(handleType);
|
||||
|
||||
// Return the formats you will support
|
||||
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB565;
|
||||
}
|
||||
|
||||
bool present(const QVideoFrame &frame)
|
||||
{
|
||||
Q_UNUSED(frame);
|
||||
// Handle the frame and do your processing
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//! [Derived Surface]
|
||||
|
||||
//! [Video producer]
|
||||
class MyVideoProducer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QAbstractVideoSurface *videoSurface WRITE setVideoSurface)
|
||||
|
||||
public:
|
||||
void setVideoSurface(QAbstractVideoSurface *surface)
|
||||
{
|
||||
m_surface = surface;
|
||||
m_surface->start(m_format);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
public slots:
|
||||
void onNewVideoContentReceived(const QVideoFrame &frame)
|
||||
{
|
||||
if (m_surface)
|
||||
m_surface->present(frame);
|
||||
}
|
||||
|
||||
private:
|
||||
QAbstractVideoSurface *m_surface;
|
||||
QVideoSurfaceFormat m_format;
|
||||
};
|
||||
|
||||
//! [Video producer]
|
||||
|
||||
|
||||
class VideoExample : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void VideoGraphicsItem();
|
||||
void VideoRendererControl();
|
||||
void VideoWidget();
|
||||
void VideoWindowControl();
|
||||
void VideoWidgetControl();
|
||||
|
||||
private:
|
||||
// Common naming
|
||||
QMediaService *mediaService;
|
||||
QMediaPlaylist *playlist;
|
||||
QVideoWidget *videoWidget;
|
||||
QWidget *widget;
|
||||
QFormLayout *layout;
|
||||
QAbstractVideoSurface *myVideoSurface;
|
||||
QMediaPlayer *player;
|
||||
QMediaContent video;
|
||||
QGraphicsView *graphicsView;
|
||||
};
|
||||
|
||||
void VideoExample::VideoRendererControl()
|
||||
{
|
||||
//! [Video renderer control]
|
||||
QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>();
|
||||
rendererControl->setSurface(myVideoSurface);
|
||||
//! [Video renderer control]
|
||||
}
|
||||
|
||||
void VideoExample::VideoWidget()
|
||||
{
|
||||
//! [Video widget]
|
||||
player = new QMediaPlayer;
|
||||
|
||||
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);
|
||||
|
||||
videoWidget->show();
|
||||
playlist->setCurrentIndex(1);
|
||||
player->play();
|
||||
//! [Video widget]
|
||||
|
||||
player->stop();
|
||||
|
||||
//! [Setting surface in player]
|
||||
player->setVideoOutput(myVideoSurface);
|
||||
//! [Setting surface in player]
|
||||
}
|
||||
|
||||
void VideoExample::VideoWidgetControl()
|
||||
{
|
||||
//! [Video widget control]
|
||||
QVideoWidgetControl *widgetControl = mediaService->requestControl<QVideoWidgetControl *>();
|
||||
layout->addWidget(widgetControl->videoWidget());
|
||||
//! [Video widget control]
|
||||
}
|
||||
|
||||
void VideoExample::VideoWindowControl()
|
||||
{
|
||||
//! [Video window control]
|
||||
QVideoWindowControl *windowControl = mediaService->requestControl<QVideoWindowControl *>();
|
||||
windowControl->setWinId(widget->winId());
|
||||
windowControl->setDisplayRect(widget->rect());
|
||||
windowControl->setAspectRatioMode(Qt::KeepAspectRatio);
|
||||
//! [Video window control]
|
||||
}
|
||||
|
||||
void VideoExample::VideoGraphicsItem()
|
||||
{
|
||||
//! [Video graphics item]
|
||||
player = new QMediaPlayer(this);
|
||||
|
||||
QGraphicsVideoItem *item = new QGraphicsVideoItem;
|
||||
player->setVideoOutput(item);
|
||||
graphicsView->scene()->addItem(item);
|
||||
graphicsView->show();
|
||||
|
||||
player->setMedia(QUrl("http://example.com/myclip4.ogv"));
|
||||
player->play();
|
||||
//! [Video graphics item]
|
||||
}
|
||||
3
src/multimedia/doc/snippets/snippets.pro
Normal file
3
src/multimedia/doc/snippets/snippets.pro
Normal file
@@ -0,0 +1,3 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += multimedia-snippets
|
||||
Reference in New Issue
Block a user