Logo Search packages:      
Sourcecode: bangarang version File versions  Download package

void Playlist::playItemAt ( int  row,
Playlist::Model  model = Playlist::PlaylistModel 
)

Plays item at the specified row of the specified model

Parameters:
row row of the specified model
model either Playlist::PlaylistModel or Playlist::QueueModel

Definition at line 98 of file playlist.cpp.

References MediaItemModel::clearMediaListData(), MediaItem::fields, MediaItemModel::loadMediaList(), MediaItemModel::mediaItemAt(), MediaItemModel::mediaList(), MediaItem::nowPlaying, MediaItem::playlistIndex, MediaItemModel::rowOfUrl(), and MediaItem::url.

Referenced by playNext(), playPrevious(), and start().

{
    MediaItem nextMediaItem;
    if (model == Playlist::PlaylistModel) {
        //Get media item from playlist
        nextMediaItem = m_currentPlaylist->mediaItemAt(row);
        nextMediaItem.playlistIndex = row;
        nextMediaItem.nowPlaying = true;
        
        bool isNowPlaying = false;
        if (m_nowPlaying->rowCount() > 0) {
            if (nextMediaItem.url == m_nowPlaying->mediaItemAt(0).url) {
                isNowPlaying = true;
            }
        }

        //Update Queue Model
        if (m_mode == Playlist::Normal) {
            //Just build a new queue from the specified row
            buildQueueFrom(row);
        } else if (m_mode == Playlist::Shuffle) {
            if (m_playlistIndicesHistory.indexOf(row) == -1) {
                //If item has not yet played move it to the front
                if (m_queue->rowOfUrl(nextMediaItem.url) != -1) {
                    QList<MediaItem> queueMediaList = m_queue->mediaList();
                    queueMediaList.move(m_queue->rowOfUrl(nextMediaItem.url), 0);
                    m_queue->clearMediaListData();
                    m_queue->loadMediaList(queueMediaList, true);
                } else {
                    QList<MediaItem> queueMediaList = m_queue->mediaList();
                    queueMediaList.insert(0, nextMediaItem);
                    if (queueMediaList.count() > m_queueDepth) {
                        queueMediaList.removeLast();
                    }
                    m_queue->clearMediaListData();
                    m_queue->loadMediaList(queueMediaList, true);
                }
            } else {
                //If item has already played remove from history and place at front of queue
                m_playlistIndicesHistory.removeAt(m_playlistIndicesHistory.indexOf(row));
                m_playlistUrlHistory.removeAt(m_playlistIndicesHistory.indexOf(row));
                QList<MediaItem> queueMediaList = m_queue->mediaList();
                queueMediaList.insert(0, nextMediaItem);
                queueMediaList.removeLast();
                m_queue->clearMediaListData();
                m_queue->loadMediaList(queueMediaList, true);
            }    
        }

        //Play media Item
        m_mediaObject->clearQueue();
        if (nextMediaItem.fields["audioType"].toString() == "CD Track") {
            m_mediaObject->setCurrentSource(Phonon::Cd);
            m_mediaController->setAutoplayTitles(false);
            m_mediaController->setCurrentTitle(nextMediaItem.fields["trackNumber"].toInt());
            m_mediaObject->play();
        } else if (nextMediaItem.fields["videoType"].toString() == "DVD Title") {
            m_mediaObject->setCurrentSource(Phonon::Dvd);
            m_mediaController->setAutoplayTitles(false);
            m_mediaController->setCurrentTitle(nextMediaItem.fields["trackNumber"].toInt());
            m_mediaObject->play();
        } else {
            m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromPercentEncoding(nextMediaItem.url.toUtf8())));
            m_mediaObject->play();
        }
        m_state = Playlist::Playing;
        

    } else if (model == Playlist::QueueModel) {
        //Get media item from queue list
        nextMediaItem = m_queue->mediaItemAt(row);
        nextMediaItem.nowPlaying = true;
        
        //Update Queue Model
        if (m_mode == Playlist::Normal) {
            //Just build a new queue from the row of the item in the playlist
            buildQueueFrom(nextMediaItem.playlistIndex);
        } else if (m_mode == Playlist::Shuffle) {
            if (row > 0) {
                //Move item to front of queue
                QList<MediaItem> queueMediaList = m_queue->mediaList();
                queueMediaList.move(row, 0);
                m_queue->clearMediaListData();
                m_queue->loadMediaList(queueMediaList, true);
            }
        }
        
        //Play media Item
        m_mediaObject->clearQueue();
        if (nextMediaItem.fields["audioType"].toString() == "CD Track") {
            m_mediaObject->setCurrentSource(Phonon::Cd);
            m_mediaController->setAutoplayTitles(false);
            m_mediaController->setCurrentTitle(nextMediaItem.fields["trackNumber"].toInt());
        } else if (nextMediaItem.fields["videoType"].toString() == "DVD Title") {
            m_mediaObject->setCurrentSource(Phonon::Dvd);
            m_mediaController->setAutoplayTitles(false);
            m_mediaController->setCurrentTitle(nextMediaItem.fields["trackNumber"].toInt());
        } else {
            m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromPercentEncoding(nextMediaItem.url.toUtf8())));
        }
        m_mediaObject->play();
        m_state = Playlist::Playing;
    }
    
    
}


Generated by  Doxygen 1.6.0   Back to index