summaryrefslogtreecommitdiff
path: root/doc/src/plugins/qml-multimedia.qdoc
blob: 2d5d010bafb95556d5911f4af14abb61bfb12a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.
**
** 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$
**
****************************************************************************/

/*!
    \group qml-multimedia
    \title QML Multimedia Plugin
    QML Support for the QtMobility Project Multimedia API.
*/

/*!
    \page qml-multimedia.html

    \title Multimedia QML Plugin

    \brief A QML plugin for the QtMobility Project Multimedia API.


    \section1 Overview

    The Multimedia API in the QtMobility Project gives developers a simplified way to use audio and video playback, and access camera functionality. The Multimedia QML Plugin provides a QML friendly interface to these features.

    \section1 Elements

    \section2 Audio

    The \l Audio element is an easy way to add audio playback to a Qt Quick
    scene. QtMobility provides properties for control, methods (functions) and signals.

    The code extract below shows the creation and use of an audio element.

    \qml

    import Qt 4.7
    import QtMultimediaKit 1.1
    // ...

    Audio {
        id: playMusic
        source: "music.wav"
    }

    MouseArea {
        id: playArea
        anchors.fill: parent
        onPressed:  { playMusic.play() }
    }

    \endqml

    The snippet above shows how the inclusion of \i playMusic enables audio features on the element that contains it. So that when the parent's MouseArea is clicked the \l {Audio::play()}{play()} method of the audio element is run. Other typical audio control methods are available such as \l {Audio::pause}{pause()} and \l {Audio::stop()}{stop()}.

    Much of the getting / setting of \l Audio parameters is done through properties. These include
    \table 70%
        \header
            \o Property
            \o Description
        \row
            \o \l {Audio::source}{source}
            \o The source URL of the media.
        \row
            \o \l {Audio::autoLoad}{autoLoad}
            \o Indicates if loading of media should begin immediately.
        \row
            \o \l{Audio::playing}{playing}
            \o Indicates that the media is playing.
        \row
            \o \l {Audio::paused}{paused}
            \o The media is paused.
        \row
            \o \l{Audio::status}{status}
            \o The status of media loading.
        \row
            \o \l{Audio::duration}{duration}
            \o Amount of time in milliseconds the media will play.
        \row
            \o \l{Audio::position}{position}
            \o Current position in the media in milliseconds of play.
        \row
            \o \l{Audio::volume}{volume}
            \o Audio output volume: from 0.0 (silent) to 1.0 (maximum)
        \row
            \o \l{Audio::muted}{muted}
            \o Indicates audio is muted.
        \row
            \o \l{Audio::bufferProgress}{bufferProgress}
            \o Indicates how full the data buffer is: 0.0 (empty) to 1.0 (full).
        \row
            \o \l{Audio::seekable}{seekable}
            \o Indicates whether the audio position can be changed.
        \row
            \o \l{Audio::playbackRate}{playbackRate}
            \o The rate at which audio is played at as a multiple of the normal rate.
        \row
            \o \l{Audio::error}{error}
            \o An error code for the error state including NoError
        \row
            \o \l{Audio::errorString}{errorString}
            \o A description of the current error condition.
    \endtable

    The set of signals available allow the developer to create custom behavior when the following events occur,

    \table 70%
        \header
            \o Signal
            \o Description
        \row
            \o \l{Audio::onStarted}{onStarted}
            \o Called when playback has been started.
        \row
            \o \l{Audio::onResumed}{onResumed}
            \o Called when playback is resumed from the paused state.
        \row
            \o \l{Audio::onPaused}{onPaused}
            \o Called when playback is paused.
        \row
            \o \l{Audio::onStopped}{onStopped}
            \o Called when playback is stopped.
        \row
            \o \l{Audio::onError}{onError}
            \o Called when the specified error occurs.
    \endtable

    \section2 Camera

    The \l Camera element in the plugin enables still image capture using
    QML. The element has methods for starting and stopping the camera, capturing
    the image, camera settings and many signals indicating critical events.

    The follow code is taken from the \l {QML Camera Example}. This snippet
    shows the setting up of the \l Camera element

    \qml

    Camera {
        id: camera
        x : 0
        y : 0
        width : 640
        height : 480
        focus : visible //to receive focus and capture key events
        //captureResolution : "640x480"

        flashMode: stillControls.flashMode
        whiteBalanceMode: stillControls.whiteBalance
        exposureCompensation: stillControls.exposureCompensation

        onImageCaptured : {
            photoPreview.source = preview
            stillControls.previewAvailable = true
            cameraUI.state = "PhotoPreview"
        }
    }

    \endqml

    Notice that the slot for the \l {Camera::imageCaptured()}{imageCaptured()}
    signal is implemented in \i onImageCaptured. However, this code only
    changes some state information to allow previewing.

    The capture call itself is part of the implementation of the button
    that the user presses to take the image. It uses a call to
    \l {Camera::captureImage()}{captureImage()}:

    \qml

    CameraButton {
        text: "Capture"
        onClicked: camera.captureImage()
    }

    \endqml


    \section2 Video

    Adding video playback, with sound, to a Qt Quick scene is also easy. The process is very similar to that of Audio above, in fact \l {Video} shares many of the property names, methods and signals. Here is the equivalent sample code to implement a video playback element in a scene

    \qml

    Video {
        id: video
        width : 800
        height : 600
        source: "video.avi"

        MouseArea {
            anchors.fill: parent
            onClicked: {
                video.play()
            }
        }

        focus: true
        Keys.onSpacePressed: video.paused = !video.paused
        Keys.onLeftPressed: video.position -= 5000
        Keys.onRightPressed: video.position += 5000
    }

    \endqml

    There are similar features like \l {Video::play()}{play()} with new
    features specific to video.

    In the above sample when the parent of MouseArea is clicked, an area of 800x600 pixels with an id of 'video', the source "video.avi" will play in that area. Notice also that signals for the Keys element have been defined so that a spacebar will toggle the pause button; the left arrow will move the current position in the video to 5 seconds previously; and the right arrow will advance the current position in the video by 5 seconds.

    Most of the differences will obviously be about video control and information. There are many properties associated with the \l {Video} element, most of them deal with meta-data, control of the video media and aspects of presentation.

    \section2 SoundEffect

    The \l SoundEffect element provides a way to play short sound effects, like in video games. Multiple sound effect instances can be played simultaneously.
    You should use the \l Audio element for music playback.

    \qml

    import Qt 4.7
    import QtMultimediaKit 1.1


        SoundEffect {
            id: effect
            source: "test.wav"
        }
        MouseArea {
            id: playArea
            anchors.fill: parent
            onPressed:  { effect.play() }
        }

    \endqml


    In the above sample the sound effect will be played when the MouseArea is clicked.

    For a complete description of this element, see \l SoundEffect

    \section2 Camera

    Adding access to the camera viewfinder, and capturing images is possible by using the  \l Camera element.  You can adjust capture settings
    including white balance, exposure compensation and flash mode, and control zoom.

    \qml
    import Qt 4.7
    import QtMultimediaKit 1.1

    Camera {
        focus : visible // to receive focus and capture key events when visible

        flashMode: Camera.FlashRedEyeReduction
        whiteBalanceMode: Camera.WhiteBalanceFlash
        exposureCompensation: -1.0

        onImageCaptured : {
            photoPreview.source = preview  // Show the preview in an Image element
        }

    }
    \endqml

    For a complete description of this element, see \l Camera, and look at the \l {declarative-camera}{QML Camera Example}.

    \section1 Multimedia QML Elements

    \annotatedlist qml-multimedia
*/