summaryrefslogtreecommitdiffstats
path: root/src/multimedia/doc/src/plugins/qml-multimedia.qdoc
blob: 460f08a44d521b0638c58225a39f5d55d06e184a (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
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** 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 Qt Multimedia API.
*/

/*!
    \page qml-multimedia.html

    \title Qt Multimedia QML API

    \brief A QML API for the Qt Multimedia module.


    \section1 Overview

    The Qt Multimedia module gives developers a simplified way to use audio and video playback, and access camera functionality. The Multimedia QML API provides a QML friendly interface to these features.

    \section1 Types

    \section2 Audio

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

    The code extract below shows the creation and use of an Audio instance.

    \qml

    import QtQuick 2.0
    import QtMultimedia 5.0
    // ...

    Item {
        width: 640
        height: 360

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

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

    \endqml

    The snippet above shows how the inclusion of \e playMusic enables audio features on the type that contains it. So that when the parent's MouseArea is clicked the \l {Audio::play()}{play()} method of Audio 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
            \li Property
            \li Description
        \row
            \li \l {Audio::source}{source}
            \li The source URL of the media.
        \row
            \li \l {Audio::autoLoad}{autoLoad}
            \li Indicates if loading of media should begin immediately.
        \row
            \li \l{Audio::playing}{playing}
            \li Indicates that the media is playing.
        \row
            \li \l {Audio::paused}{paused}
            \li The media is paused.
        \row
            \li \l{Audio::status}{status}
            \li The status of media loading.
        \row
            \li \l{Audio::duration}{duration}
            \li Amount of time in milliseconds the media will play.
        \row
            \li \l{Audio::position}{position}
            \li Current position in the media in milliseconds of play.
        \row
            \li \l{Audio::volume}{volume}
            \li Audio output volume: from 0.0 (silent) to 1.0 (maximum)
        \row
            \li \l{Audio::muted}{muted}
            \li Indicates audio is muted.
        \row
            \li \l{Audio::bufferProgress}{bufferProgress}
            \li Indicates how full the data buffer is: 0.0 (empty) to 1.0 (full).
        \row
            \li \l{Audio::seekable}{seekable}
            \li Indicates whether the audio position can be changed.
        \row
            \li \l{Audio::playbackRate}{playbackRate}
            \li The rate at which audio is played at as a multiple of the normal rate.
        \row
            \li \l{Audio::error}{error}
            \li An error code for the error state including NoError
        \row
            \li \l{Audio::errorString}{errorString}
            \li 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
            \li Signal
            \li Description
        \row
            \li \l{Audio::playing}{playing}
            \li Called when playback is started, or when resumed from paused state.
        \row
            \li \l{Audio::paused}{paused}
            \li Called when playback is paused.
        \row
            \li \l{Audio::stopped}{stopped}
            \li Called when playback is stopped.
        \row
            \li \l{Audio::error}{error}
            \li Called when the specified error occurs.
    \endtable

    \section2 Camera

    \l Camera enables still image and video capture using
    QML. It has a number of properties that help setting it up.

    The details of using a \l Camera are described in further depth
    in the \l {Camera Overview} and in the corresponding reference documentation.

    \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 video playback 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 \l Keys 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 \l {Video}, most of them deal with meta-data, control of the video media and aspects of presentation.

    \section2 SoundEffect

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

    \qml

    import QtQuick 2.0
    import QtMultimedia 5.0

    Item {
        width: 640
        height: 360

        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 type, see \l SoundEffect

    \section1 Multimedia QML Types

    \annotatedlist multimedia_qml
*/