qtmobility/src/multimedia/qmediaplaylist.cpp
changeset 14 6fbed849b4f4
parent 11 06b8e2af4411
equal deleted inserted replaced
11:06b8e2af4411 14:6fbed849b4f4
    57 #include "qmediapluginloader_p.h"
    57 #include "qmediapluginloader_p.h"
    58 
    58 
    59 QT_BEGIN_NAMESPACE
    59 QT_BEGIN_NAMESPACE
    60 
    60 
    61 Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader,
    61 Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, playlistIOLoader,
    62         (QMediaPlaylistIOInterface_iid, QLatin1String("/playlistformats"), Qt::CaseInsensitive))
    62         (QMediaPlaylistIOInterface_iid, QLatin1String("playlistformats"), Qt::CaseInsensitive))
    63 
    63 
    64 
    64 
    65 /*!
    65 /*!
    66     \class QMediaPlaylist
    66     \class QMediaPlaylist
    67     \ingroup multimedia
    67     \ingroup multimedia
    69     \preliminary
    69     \preliminary
    70     \brief The QMediaPlaylist class provides a list of media content to play.
    70     \brief The QMediaPlaylist class provides a list of media content to play.
    71 
    71 
    72     QMediaPlaylist is intended to be used with other media objects,
    72     QMediaPlaylist is intended to be used with other media objects,
    73     like QMediaPlayer or QMediaImageViewer.
    73     like QMediaPlayer or QMediaImageViewer.
       
    74 
    74     QMediaPlaylist allows to access the service intrinsic playlist functionality
    75     QMediaPlaylist allows to access the service intrinsic playlist functionality
    75     if available, otherwise it provides the the local memory playlist implementation.
    76     if available, otherwise it provides the the local memory playlist implementation.
    76 
    77 
    77 \code
    78 \code
    78     player = new QMediaPlayer;
    79     player = new QMediaPlayer;
    79 
    80 
    80     playlist = new QMediaPlaylist;
    81     playlist = new QMediaPlaylist;
    81     playlist->setMediaObject(player);
       
    82     playlist->append(QUrl("http://example.com/movie1.mp4"));
    82     playlist->append(QUrl("http://example.com/movie1.mp4"));
    83     playlist->append(QUrl("http://example.com/movie2.mp4"));
    83     playlist->append(QUrl("http://example.com/movie2.mp4"));
    84     playlist->append(QUrl("http://example.com/movie3.mp4"));
    84     playlist->append(QUrl("http://example.com/movie3.mp4"));
    85 
    85 
    86     playlist->setCurrentIndex(1);
    86     playlist->setCurrentIndex(1);
    87 
    87 
       
    88     player->setPlaylist(playlist);
       
    89 
    88     player->play();
    90     player->play();
    89 \endcode
    91 \endcode
    90 
    92 
    91     Depending on playlist source implementation,
    93     Depending on playlist source implementation, most of the playlist mutating
    92     most of playlist modifcation operations can be asynchronous.
    94     operations can be asynchronous.
    93 
    95 
    94     \sa QMediaContent
    96     \sa QMediaContent
    95 */
    97 */
    96 
    98 
    97 
    99 
   100 
   102 
   101     The QMediaPlaylist::PlaybackMode describes the order items in playlist are played.
   103     The QMediaPlaylist::PlaybackMode describes the order items in playlist are played.
   102 
   104 
   103     \value CurrentItemOnce    The current item is played only once.
   105     \value CurrentItemOnce    The current item is played only once.
   104 
   106 
   105     \value CurrentItemInLoop  The current item is played in the loop.
   107     \value CurrentItemInLoop  The current item is played repeatedly in a loop.
   106 
   108 
   107     \value Linear             Playback starts from the first to the last items and stops.
   109     \value Sequential         Playback starts from the current and moves through each successive item until the last is reached and then stops.
   108                               next item is a null item when the last one is currently playing.
   110                               The next item is a null item when the last one is currently playing.
   109 
   111 
   110     \value Loop               Playback continues from the first item after the last one finished playing.
   112     \value Loop               Playback restarts at the first item after the last has finished playing.
   111 
   113 
   112     \value Random             Play items in random order.
   114     \value Random             Play items in random order.
   113 */
   115 */
   114 
   116 
   115 
   117 
   151 
   153 
   152 /*!
   154 /*!
   153   If \a mediaObject is null or doesn't have an intrinsic playlist,
   155   If \a mediaObject is null or doesn't have an intrinsic playlist,
   154   internal local memory playlist source will be created.
   156   internal local memory playlist source will be created.
   155 */
   157 */
   156 void QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
   158 bool QMediaPlaylist::setMediaObject(QMediaObject *mediaObject)
   157 {
   159 {
   158     Q_D(QMediaPlaylist);
   160     Q_D(QMediaPlaylist);
   159 
   161 
   160     if (mediaObject && mediaObject == d->mediaObject)
   162     if (mediaObject && mediaObject == d->mediaObject)
   161         return;
   163         return true;
   162 
   164 
   163     QMediaService *service = mediaObject
   165     QMediaService *service = mediaObject
   164             ? mediaObject->service() : 0;
   166             ? mediaObject->service() : 0;
   165 
   167 
   166     QMediaPlaylistControl *newControl = 0;
   168     QMediaPlaylistControl *newControl = 0;
   167 
   169 
   168     if (service)
   170     if (service)
   169         newControl = qobject_cast<QMediaPlaylistControl*>(service->control(QMediaPlaylistControl_iid));
   171         newControl = qobject_cast<QMediaPlaylistControl*>(service->requestControl(QMediaPlaylistControl_iid));
   170 
   172 
   171     if (!newControl)
   173     if (!newControl)
   172         newControl = d->localPlaylistControl;
   174         newControl = d->localPlaylistControl;
   173 
   175 
   174     if (d->control != newControl) {
   176     if (d->control != newControl) {
   191                     this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
   193                     this, SIGNAL(playbackModeChanged(QMediaPlaylist::PlaybackMode)));
   192             disconnect(d->control, SIGNAL(currentIndexChanged(int)),
   194             disconnect(d->control, SIGNAL(currentIndexChanged(int)),
   193                     this, SIGNAL(currentIndexChanged(int)));
   195                     this, SIGNAL(currentIndexChanged(int)));
   194             disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
   196             disconnect(d->control, SIGNAL(currentMediaChanged(QMediaContent)),
   195                     this, SIGNAL(currentMediaChanged(QMediaContent)));
   197                     this, SIGNAL(currentMediaChanged(QMediaContent)));
       
   198 
       
   199             if (d->mediaObject)
       
   200                 d->mediaObject->service()->releaseControl(d->control);
   196         }
   201         }
   197 
   202 
   198         d->control = newControl;
   203         d->control = newControl;
   199         QMediaPlaylistProvider *playlist = d->control->playlistProvider();
   204         QMediaPlaylistProvider *playlist = d->control->playlistProvider();
   200         connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
   205         connect(playlist, SIGNAL(loadFailed(QMediaPlaylist::Error,QString)),
   222             emit mediaAboutToBeInserted(0,playlist->mediaCount()-1);
   227             emit mediaAboutToBeInserted(0,playlist->mediaCount()-1);
   223             emit mediaInserted(0,playlist->mediaCount()-1);
   228             emit mediaInserted(0,playlist->mediaCount()-1);
   224         }
   229         }
   225     }
   230     }
   226 
   231 
   227     if (d->mediaObject)
       
   228         d->mediaObject->unbind(this);
       
   229 
       
   230     d->mediaObject = mediaObject;
   232     d->mediaObject = mediaObject;
   231     if (d->mediaObject)
   233 
   232         d->mediaObject->bind(this);
   234     return true;
   233 }
   235 }
   234 
   236 
   235 /*!
   237 /*!
   236   \property QMediaPlaylist::playbackMode
   238   \property QMediaPlaylist::playbackMode
   237 
   239 
   250     Q_D(QMediaPlaylist);
   252     Q_D(QMediaPlaylist);
   251     d->control->setPlaybackMode(mode);
   253     d->control->setPlaybackMode(mode);
   252 }
   254 }
   253 
   255 
   254 /*!
   256 /*!
   255   Returns position of the current media source in the playlist.
   257   Returns position of the current media content in the playlist.
   256 */
   258 */
   257 int QMediaPlaylist::currentIndex() const
   259 int QMediaPlaylist::currentIndex() const
   258 {
   260 {
   259     return d_func()->control->currentIndex();
   261     return d_func()->control->currentIndex();
   260 }
   262 }
   267 {
   269 {
   268     return d_func()->playlist()->media(currentIndex());
   270     return d_func()->playlist()->media(currentIndex());
   269 }
   271 }
   270 
   272 
   271 /*!
   273 /*!
   272   Returns the index of item, which were current after calling next()
   274   Returns the index of the item, which would be current after calling next()
   273   \a steps times.
   275   \a steps times.
   274 
   276 
   275   Returned value depends on the size of playlist, current position
   277   Returned value depends on the size of playlist, current position
   276   and playback mode.
   278   and playback mode.
   277 
   279 
   281 {
   283 {
   282     return d_func()->control->nextIndex(steps);
   284     return d_func()->control->nextIndex(steps);
   283 }
   285 }
   284 
   286 
   285 /*!
   287 /*!
   286   Returns the index of item, which were current after calling previous()
   288   Returns the index of the item, which would be current after calling previous()
   287   \a steps times.
   289   \a steps times.
   288 
   290 
   289   \sa QMediaPlaylist::playbackMode
   291   \sa QMediaPlaylist::playbackMode
   290 */
   292 */
   291 
   293 
   305     return d_func()->playlist()->mediaCount();
   307     return d_func()->playlist()->mediaCount();
   306 }
   308 }
   307 
   309 
   308 /*!
   310 /*!
   309   Returns true if the playlist contains no items; otherwise returns false.
   311   Returns true if the playlist contains no items; otherwise returns false.
       
   312 
   310   \sa size()
   313   \sa size()
   311   */
   314   */
   312 bool QMediaPlaylist::isEmpty() const
   315 bool QMediaPlaylist::isEmpty() const
   313 {
   316 {
   314     return mediaCount() == 0;
   317     return mediaCount() == 0;
   315 }
   318 }
   316 
   319 
   317 /*!
   320 /*!
   318   Returns true if the playlist can be modified; otherwise returns false.
   321   Returns true if the playlist can be modified; otherwise returns false.
       
   322 
   319   \sa size()
   323   \sa size()
   320   */
   324   */
   321 bool QMediaPlaylist::isReadOnly() const
   325 bool QMediaPlaylist::isReadOnly() const
   322 {
   326 {
   323     return d_func()->playlist()->isReadOnly();
   327     return d_func()->playlist()->isReadOnly();
   333 }
   337 }
   334 
   338 
   335 /*!
   339 /*!
   336   Append the media \a content to the playlist.
   340   Append the media \a content to the playlist.
   337 
   341 
   338   Returns true if the operation is successfull, other wise return false.
   342   Returns true if the operation is successful, otherwise return false.
   339   */
   343   */
   340 bool QMediaPlaylist::addMedia(const QMediaContent &content)
   344 bool QMediaPlaylist::addMedia(const QMediaContent &content)
   341 {
   345 {
   342     return d_func()->control->playlistProvider()->addMedia(content);
   346     return d_func()->control->playlistProvider()->addMedia(content);
   343 }
   347 }
   344 
   348 
   345 /*!
   349 /*!
   346   Append multiple media content \a items to the playlist.
   350   Append multiple media content \a items to the playlist.
   347 
   351 
   348   Returns true if the operation is successfull, other wise return false.
   352   Returns true if the operation is successful, otherwise return false.
   349   */
   353   */
   350 bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items)
   354 bool QMediaPlaylist::addMedia(const QList<QMediaContent> &items)
   351 {
   355 {
   352     return d_func()->control->playlistProvider()->addMedia(items);
   356     return d_func()->control->playlistProvider()->addMedia(items);
   353 }
   357 }
   375 }
   379 }
   376 
   380 
   377 /*!
   381 /*!
   378   Remove the item from the playlist at position \a pos.
   382   Remove the item from the playlist at position \a pos.
   379 
   383 
   380   Returns true if the operation is successfull, other wise return false.
   384   Returns true if the operation is successful, otherwise return false.
   381   */
   385   */
   382 bool QMediaPlaylist::removeMedia(int pos)
   386 bool QMediaPlaylist::removeMedia(int pos)
   383 {
   387 {
   384     Q_D(QMediaPlaylist);
   388     Q_D(QMediaPlaylist);
   385     return d->playlist()->removeMedia(pos);
   389     return d->playlist()->removeMedia(pos);
   386 }
   390 }
   387 
   391 
   388 /*!
   392 /*!
   389   Remove the items from the playlist from position \a start to \a end inclusive.
   393   Remove items in the playlist from \a start to \a end inclusive.
   390 
   394 
   391   Returns true if the operation is successfull, other wise return false.
   395   Returns true if the operation is successful, otherwise return false.
   392   */
   396   */
   393 bool QMediaPlaylist::removeMedia(int start, int end)
   397 bool QMediaPlaylist::removeMedia(int start, int end)
   394 {
   398 {
   395     Q_D(QMediaPlaylist);
   399     Q_D(QMediaPlaylist);
   396     return d->playlist()->removeMedia(start, end);
   400     return d->playlist()->removeMedia(start, end);
   397 }
   401 }
   398 
   402 
   399 /*!
   403 /*!
   400   Remove all the items from the playlist.
   404   Remove all the items from the playlist.
   401 
   405 
   402   Returns true if the operation is successfull, other wise return false.
   406   Returns true if the operation is successful, otherwise return false.
   403   */
   407   */
   404 bool QMediaPlaylist::clear()
   408 bool QMediaPlaylist::clear()
   405 {
   409 {
   406     Q_D(QMediaPlaylist);
   410     Q_D(QMediaPlaylist);
   407     return d->playlist()->clear();
   411     return d->playlist()->clear();
   429   Load playlist from \a location. If \a format is specified, it is used,
   433   Load playlist from \a location. If \a format is specified, it is used,
   430   otherwise format is guessed from location name and data.
   434   otherwise format is guessed from location name and data.
   431 
   435 
   432   New items are appended to playlist.
   436   New items are appended to playlist.
   433 
   437 
   434   QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully,
   438   QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
   435   otherwise the playlist emits loadFailed().
   439   otherwise the playlist emits loadFailed().
   436 */
   440 */
   437 void QMediaPlaylist::load(const QUrl &location, const char *format)
   441 void QMediaPlaylist::load(const QUrl &location, const char *format)
   438 {
   442 {
   439     Q_D(QMediaPlaylist);
   443     Q_D(QMediaPlaylist);
   475   Load playlist from QIODevice \a device. If \a format is specified, it is used,
   479   Load playlist from QIODevice \a device. If \a format is specified, it is used,
   476   otherwise format is guessed from device data.
   480   otherwise format is guessed from device data.
   477 
   481 
   478   New items are appended to playlist.
   482   New items are appended to playlist.
   479 
   483 
   480   QMediaPlaylist::loaded() signal is emited if playlist was loaded succesfully,
   484   QMediaPlaylist::loaded() signal is emitted if playlist was loaded successfully,
   481   otherwise the playlist emits loadFailed().
   485   otherwise the playlist emits loadFailed().
   482 */
   486 */
   483 void QMediaPlaylist::load(QIODevice * device, const char *format)
   487 void QMediaPlaylist::load(QIODevice * device, const char *format)
   484 {
   488 {
   485     Q_D(QMediaPlaylist);
   489     Q_D(QMediaPlaylist);
   519 
   523 
   520 /*!
   524 /*!
   521   Save playlist to \a location. If \a format is specified, it is used,
   525   Save playlist to \a location. If \a format is specified, it is used,
   522   otherwise format is guessed from location name.
   526   otherwise format is guessed from location name.
   523 
   527 
   524   Returns true if playlist was saved succesfully, otherwise returns false.
   528   Returns true if playlist was saved successfully, otherwise returns false.
   525   */
   529   */
   526 bool QMediaPlaylist::save(const QUrl &location, const char *format)
   530 bool QMediaPlaylist::save(const QUrl &location, const char *format)
   527 {
   531 {
   528     Q_D(QMediaPlaylist);
   532     Q_D(QMediaPlaylist);
   529 
   533 
   545 }
   549 }
   546 
   550 
   547 /*!
   551 /*!
   548   Save playlist to QIODevice \a device using format \a format.
   552   Save playlist to QIODevice \a device using format \a format.
   549 
   553 
   550   Returns true if playlist was saved succesfully, otherwise returns false.
   554   Returns true if playlist was saved successfully, otherwise returns false.
   551 */
   555 */
   552 bool QMediaPlaylist::save(QIODevice * device, const char *format)
   556 bool QMediaPlaylist::save(QIODevice * device, const char *format)
   553 {
   557 {
   554     Q_D(QMediaPlaylist);
   558     Q_D(QMediaPlaylist);
   555 
   559 
   661 */
   665 */
   662 
   666 
   663 /*!
   667 /*!
   664     \fn void QMediaPlaylist::mediaAboutToBeInserted(int start, int end)
   668     \fn void QMediaPlaylist::mediaAboutToBeInserted(int start, int end)
   665 
   669 
   666     Signal emitted when item to be inserted at \a start and ending at \a end.
   670     Signal emitted when items are to be inserted at \a start and ending at \a end.
   667 */
   671 */
   668 
   672 
   669 /*!
   673 /*!
   670     \fn void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end)
   674     \fn void QMediaPlaylist::mediaAboutToBeRemoved(int start, int end)
   671 
   675 
   672     Signal emitted when item to de deleted ar \a start and ending at \a end.
   676     Signal emitted when item are to be deleted at \a start and ending at \a end.
   673 */
   677 */
   674 
   678 
   675 /*!
   679 /*!
   676     \fn void QMediaPlaylist::currentMediaChanged(const QMediaContent &content)
   680     \fn void QMediaPlaylist::currentMediaChanged(const QMediaContent &content)
   677 
   681