Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Multimedia QML Plugin

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.

Elements

Audio

The 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.

 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.

Camera

The 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 QML Camera Example. This snippet shows the setting up of the Camera element

 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"
     }
 }

Notice that the slot for the imageCaptured() signal is implemented in 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 captureImage():

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

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 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.

SoundEffect

The 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 Audio element for music playback.

 import Qt 4.7
 import QtMultimediaKit 1.1


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

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

For a complete description of this element, see SoundEffect

Camera

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

 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
     }

 }

For a complete description of this element, see Camera, and look at the QML Camera Example.

Multimedia QML Elements

QML Audio Element

The Audio element allows you to add audio playback to a scene.

QML Camera Element

The Camera element allows you to add camera viewfinder to a scene.

QML Video Element

The Video element allows you to add videos to a scene.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 65
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Applications mobiles modernes avec Qt et QML

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt qtmobility-1.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web