qtmobility/src/multimedia/qmlaudio.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qmlaudio_p.h"
       
    43 
       
    44 #include "qmediaplayercontrol.h"
       
    45 
       
    46 QML_DEFINE_TYPE(Qt,4,6,Audio,QTM_PREPEND_NAMESPACE(QmlAudio));
       
    47 
       
    48 QTM_BEGIN_NAMESPACE
       
    49 
       
    50 /*!
       
    51     \qmlclass Audio QmlAudio
       
    52     \brief The Audio element allows you to add audio to a scene.
       
    53 */
       
    54 
       
    55 /*!
       
    56     \internal
       
    57     \class QmlAudio
       
    58     \brief The QmlAudio class provides a audio item that you can add to a QmlView.
       
    59 */
       
    60 
       
    61 void QmlAudio::_q_error(QMediaPlayer::Error errorCode, const QString &errorString)
       
    62 {
       
    63     m_error = errorCode;
       
    64     m_errorString = errorString;
       
    65 
       
    66     emit error(Error(errorCode), errorString);
       
    67     emit errorChanged();
       
    68 }
       
    69 
       
    70 
       
    71 QmlAudio::QmlAudio(QObject *parent)
       
    72     : QObject(parent)
       
    73 {
       
    74     setObject(this);
       
    75 }
       
    76 
       
    77 QmlAudio::~QmlAudio()
       
    78 {
       
    79     shutdown();
       
    80 }
       
    81 
       
    82 /*!
       
    83     \qmlmethod Audio::play()
       
    84 
       
    85     Starts playback of the audio.
       
    86 */
       
    87 
       
    88 void QmlAudio::play()
       
    89 {
       
    90     m_playerControl->play();
       
    91 }
       
    92 
       
    93 /*!
       
    94     \qmlmethod Audio::pause()
       
    95 
       
    96     Pauses playback of the audio.
       
    97 */
       
    98 
       
    99 void QmlAudio::pause()
       
   100 {
       
   101     m_playerControl->pause();
       
   102 }
       
   103 
       
   104 /*!
       
   105     \qmlmethod Audio::stop()
       
   106 
       
   107     Stops playback of the audio.
       
   108 */
       
   109 
       
   110 void QmlAudio::stop()
       
   111 {
       
   112     m_playerControl->stop();
       
   113 }
       
   114 
       
   115 /*!
       
   116     \qmlproperty url Audio::source
       
   117 
       
   118     This property holds the source URL of the audio.
       
   119 */
       
   120 
       
   121 /*!
       
   122     \qmlproperty bool Audio::playing
       
   123 
       
   124     This property holds whether the audio is playing.
       
   125 */
       
   126 
       
   127 /*!
       
   128     \qmlproperty bool Audio::paused
       
   129 
       
   130     This property holds whether the audio is paused.
       
   131 */
       
   132 
       
   133 /*!
       
   134     \qmlsignal Audio::onStarted()
       
   135 
       
   136     This handler is called when playback is started.
       
   137 */
       
   138 
       
   139 /*!
       
   140     \qmlsignal Audio::onResumed()
       
   141 
       
   142     This handler is called when playback is resumed from the paused state.
       
   143 */
       
   144 
       
   145 /*!
       
   146     \qmlsignal Audio::onPaused()
       
   147 
       
   148     This handler is called when playback is paused.
       
   149 */
       
   150 
       
   151 /*!
       
   152     \qmlsignal Audio::onStopped()
       
   153 
       
   154     This handler is called when playback is stopped.
       
   155 */
       
   156 
       
   157 /*!
       
   158     \qmlproperty enum Audio::status
       
   159 
       
   160     This property holds the status of audio loading. It can be one of:
       
   161 
       
   162     \list
       
   163     \o NoMedia - no audio has been set.
       
   164     \o Loading - the audio is currently being loaded.
       
   165     \o Loaded - the audio has been loaded.
       
   166     \o Buffering - the audio is buffering data.
       
   167     \o Stalled - playback has been interrupted while the audio is buffering data.
       
   168     \o Buffered - the audio has buffered data.
       
   169     \o EndOfMedia - the audio has played to the end.
       
   170     \o InvalidMedia - the audio cannot be played.
       
   171     \o UnknownStatus - the status of the audio is unknown.
       
   172     \endlist
       
   173 */
       
   174 
       
   175 QmlAudio::Status QmlAudio::status() const
       
   176 {
       
   177     return Status(m_status);
       
   178 }
       
   179 
       
   180 /*!
       
   181     \qmlsignal Audio::onLoaded()
       
   182 
       
   183     This handler is called when the video source has been loaded.
       
   184 */
       
   185 
       
   186 /*!
       
   187     \qmlsignal Audio::onBuffering()
       
   188 
       
   189     This handler is called when the video stream starts buffering.
       
   190 */
       
   191 
       
   192 /*!
       
   193     \qmlsignal Audio::onStalled()
       
   194 
       
   195     This handler is called when playback has stalled while the video stream buffers.
       
   196 */
       
   197 
       
   198 /*!
       
   199     \qmlsignal Audio::onBuffered()
       
   200 
       
   201     This handler is called when the video stream has finished buffering.
       
   202 */
       
   203 
       
   204 /*!
       
   205     \qmlsignal Audio::onEndOfMedia
       
   206 
       
   207     This handler is called when playback stops because end of the video has been reached.
       
   208 */
       
   209 /*!
       
   210     \qmlproperty int Audio::duration
       
   211 
       
   212     This property holds the duration of the audio in milliseconds.
       
   213 
       
   214     If the audio doesn't have a fixed duration (a live stream for example) this will be 0.
       
   215 */
       
   216 
       
   217 /*!
       
   218     \qmlproperty int Audio::position
       
   219 
       
   220     This property holds the current playback position in milliseconds.
       
   221 */
       
   222 
       
   223 /*!
       
   224     \qmlproperty qreal Audio::volume
       
   225 
       
   226     This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume).
       
   227 */
       
   228 
       
   229 /*!
       
   230     \qmlproperty bool Audio::muted
       
   231 
       
   232     This property holds whether the audio output is muted.
       
   233 */
       
   234 
       
   235 /*!
       
   236     \qmlproperty qreal Audio::bufferProgress
       
   237 
       
   238     This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0
       
   239     (full).
       
   240 */
       
   241 
       
   242 /*!
       
   243     \qmlproperty bool Audio::seekable
       
   244 
       
   245     This property holds whether position of the audio can be changed.
       
   246 */
       
   247 
       
   248 /*!
       
   249     \qmlproperty qreal playbackRate
       
   250 
       
   251     This property holds the rate at which audio is played at as a multiple of the normal rate.
       
   252 */
       
   253 
       
   254 /*!
       
   255     \qmlproperty enum Audio::error
       
   256 
       
   257     This property holds the error state of the audio.  It can be one of:
       
   258 
       
   259     \list
       
   260     \o NoError - there is no current error.
       
   261     \o ResourceError - the audio cannot be played due to a problem allocating resources.
       
   262     \o FormatError - the audio format is not supported.
       
   263     \o NetworkError - the audio cannot be played due to network issues.
       
   264     \o AccessDenied - the audio cannot be played due to insufficient permissions.
       
   265     \o ServiceMissing -  the audio cannot be played because the media service could not be
       
   266     instantiated.
       
   267     \endlist
       
   268 */
       
   269 
       
   270 QmlAudio::Error QmlAudio::error() const
       
   271 {
       
   272     return Error(m_error);
       
   273 }
       
   274 
       
   275 /*!
       
   276     \qmlproperty string Audio::errorString
       
   277 
       
   278     This property holds a string describing the current error condition in more detail.
       
   279 */
       
   280 
       
   281 /*!
       
   282     \qmlproperty Audio::onError(error, errorString)
       
   283 
       
   284     This property is called when an \l {Error}{error} has occurred.  The errorString parameter
       
   285     may contain more detailed information about the error.
       
   286 */
       
   287 
       
   288 #include "moc_qmlaudio_p.cpp"
       
   289 
       
   290 QTM_END_NAMESPACE
       
   291