You are on page 1of 3

Qt Mobility 1.

1: Multimedia QML PluginHomeQt Mobility Reference Documentation


Qt HOME DEV LABS DOC BLOG
Mobility 1.1 ALL VERSIONS API Lookup
Class index
Function index
Modules
Examples
Examples
Search index:
API Lookup
Class index
Function index
Modules
Platform Compatibility
QML Plugins
Qt Topics
Qt 4.7
Basic Qt architecture
Device UI's & Qt Quick
Desktop UI components
Platform-specific info
Examples
Examples
Home Multimedia QML Plugin A A A Print
ContentsOverview
Elements
Audio
Video
Multimedia QML Plugin
OverviewThe Multimedia API in the Mobility Project gives developers a simplified
way to use audio and video playback. The Multimedia QML Plugin provides a QML
friendly interface to these features.
ElementsAudioThe audio element is an easy way to add audio playback to a Qt
Quick scene. Mobility provides properties for control, methods (functions) and
signals.
The code extract below shows the creation and use of an audio element.
import Qt 4.7
import QtMultimediaKit 1.1
...
Audio {
id: playMusic
source: "music.wav"
}
MouseArea {
id: playArea
anchors.fill: parent
onPressed: { playMusic.play() }
}The snippet above shows how the inclusion of playMusic enables audio
features on the element that contains it. So that when the parent's MouseArea is
clicked the play() method of the audio element is run. Other typical audio
control methods are available such as pause() and stop().
Much of the getting / setting of audio parameters is done through properties.
These include
PropertyDescription
sourceThe source URL of the media.
autoLoadIndicates if loading of media should begin immediately.
playingIndicates that the media is playing.
pausedThe media is paused.
statusThe status of media loading.
durationAmount of time in milliseconds the media will play.
positionCurrent position in the media in milliseconds of play.
volumeAudio output volume: from 0.0 (silent) to 1.0 (maximum)
mutedIndicates audio is muted.
bufferProgressIndicates how full the data buffer is: 0.0 (empty) to 1.0
(full).
seekableIndicates whether the audio position can be changed.
playbackRateThe rate at which audio is played at as a multiple of the
normal rate.
errorAn error code for the error state including NoError
errorStringA description of the current error condition.
The set of signals available allow the developer to create custom behavior when
the following events occur,
SignalDescription
onStartedCalled when playback has been started.
onResumedCalled when playback is resumed from the paused state.
onPausedCalled when playback is paused.
onStoppedCalled when playback is stopped.
onErrorCalled when the specified error occurs.
VideoAdding video playback, with sound, to a Qt Quick scene is also easy. The
process is very similar to that of Audio above, in fact 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
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
}There are similar features like 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 Video element, most of them deal
with meta-data, control of the video media and aspects of presentation.
Note: This element is currently not supported on Symbian platforms.
[+] Documentation Feedback© 2008-2010 Nokia Corporation and/or its subsidiaries.
Nokia, Qt and their respective logos are trademarks of Nokia Corporation in
Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy
PolicyXThank you for giving your feedback.
Make sure it is related to this specific page. For more general bugs and
requests, please use the Qt Bug Tracker.

You might also like