Exemple #1
0
void PlaybackWidget::playNextSong(){
  Phonon::MediaSource nextSong = dataStore->takeNextSongToPlay();
  mediaObject->setCurrentSource(nextSong);
  if(nextSong.type() != Phonon::MediaSource::Empty){
    mediaObject->play();
  }
}
        void MediaObject::setSource(const Phonon::MediaSource &source)
        {
            if (m_state == Phonon::PlayingState)
            {
                setError(Phonon::NormalError, QLatin1String("source changed while playing"));
                stop();
            }

            m_source = source;
            m_hasSource = true;
            m_sourceIsValid = false;

            emit currentSourceChanged(source);

            if (source.type() == Phonon::MediaSource::LocalFile) {
                if (!openWaveFile(source.fileName())) {
                  setError(Phonon::FatalError, QLatin1String("cannot open media file"));
                  return ;
                }
            } else if (source.type() == Phonon::MediaSource::Stream) {
                if (m_stream)
                   delete m_stream;
                m_stream = new IOWrapper(this, source);
                m_mediaSize = m_stream->size();
            } else if (source.type() == Phonon::MediaSource::Url) {
                if (!openWaveFile(source.url().toLocalFile())) {
                    setError(Phonon::FatalError, QLatin1String("cannot open media file"));
                    return ;
                }
            } else {
                setError(Phonon::FatalError, QLatin1String("type of source not supported"));
                return ;
            }
            setState(Phonon::LoadingState);

            if (!readHeader())
                setError(Phonon::FatalError, QLatin1String("invalid header"));
            else if (!getWaveOutDevice())
                setError(Phonon::FatalError, QLatin1String("No waveOut device available"));
            else if (!fillBuffers())
                setError(Phonon::FatalError, QLatin1String("no data for buffering"));
            else if (!prepareBuffers())
                setError(Phonon::FatalError, QLatin1String("cannot prepare buffers"));
            else
                m_sourceIsValid = true;

            if (m_sourceIsValid)
                setState(Phonon::StoppedState);
        }
void FindSubtitles::findSubtitles() {
	Phonon::MediaObject * mediaObject = quarkPlayer().currentMediaObject();
	if (mediaObject) {
		Phonon::MediaSource source = mediaObject->currentSource();
		QString fileName(source.fileName());

		static FindSubtitlesWindow * findSubtitlesWindow = NULL;
		if (!findSubtitlesWindow) {
			findSubtitlesWindow = new FindSubtitlesWindow(MainWindowFactory::mainWindow());
			connect(findSubtitlesWindow, SIGNAL(subtitleDownloaded(const QString &)),
				SLOT(loadSubtitle(const QString &)));
		}
		findSubtitlesWindow->setMovieFileName(fileName);
		findSubtitlesWindow->setLanguage(Config::instance().language());
		findSubtitlesWindow->show();
	}
}
void Playlist::currentSourceChanged(const Phonon::MediaSource & newSource) //connected to MediaObject::currentSourceChanged
{
    //Update currentUrl and check next mediaItem to decide how to setAutoplayTitles
    if (newSource.type() == Phonon::MediaSource::Disc) {
        if (m_queue->rowCount() > 0) {
            if (Utilities::isDisc(m_queue->mediaItemAt(0).url)) {
                m_currentUrl = m_queue->mediaItemAt(0).url;
                if (m_queue->rowCount() >1) {
                    m_mediaController->setAutoplayTitles((m_queue->mediaItemAt(1).fields["trackNumber"].toInt() == m_mediaController->currentTitle() + 1));
                }
            }
        }
    } else {
        m_currentUrl = newSource.url().toString();
    }
    updateNowPlaying();
}
Exemple #5
0
void DataStore::addSongToLibrary(const Phonon::MediaSource& song, QSqlQuery &addQuery){
  QString fileName = song.fileName();
  QString songName;
  QString artistName;
  QString albumName;
  QString genre;
  int track;
  int duration;
  TagLib::FileRef f(fileName.toStdString().c_str());
  if(!f.isNull() && f.tag() && f.audioProperties()){
    TagLib::Tag *tag = f.tag();
    songName = TStringToQString(tag->title());
    artistName = TStringToQString(tag->artist());
    albumName = TStringToQString(tag->album());
    genre = TStringToQString(tag->genre());
    duration = f.audioProperties()->length();
    track = tag->track();
  }
  else{
    //TODO throw error
    return;
  }

  if(songName == ""){
    songName = unknownSongTitle();
  }
  if(artistName == ""){
    artistName = unknownSongArtist();
  }
  if(albumName == ""){
    albumName = unknownSongAlbum();
  }
  if(genre == ""){
    genre = unknownGenre();
  }

  Logger::instance()->log("adding song with title: " + songName + " to database");

  library_song_id_t hostId =-1;

  addQuery.bindValue(":song", songName);
  addQuery.bindValue(":artist", artistName);
  addQuery.bindValue(":album", albumName);
  addQuery.bindValue(":genre", genre);
  addQuery.bindValue(":track", track);
  addQuery.bindValue(":file", fileName);
  addQuery.bindValue(":duration", duration);
  EXEC_INSERT(
    "Failed to add song library" << songName.toStdString(), 
    addQuery,
    hostId,
    library_song_id_t)
}
Exemple #6
0
void MediaObject::setSource(const Phonon::MediaSource& source)
{
    switch (source.type()) {
    case MediaSource::LocalFile:
    case MediaSource::Url:
        d->sources.push_front(source);
        readyContent();
        break;

    case MediaSource::Invalid:
    case MediaSource::Disc:
    default:
        // Set error code
        return;
    }
}
void MusicPlayer::addFileRow(const Phonon::MediaSource &mediaSource)
{
    QMap<QString, QString> metaData = metaInformationResolver->metaData();

    QString title = "";


    //Use meta data for title if it exists, else create title from file name
    if(metaData.value("TITLE") != NULL)
        title = metaData.value("TITLE") + " - " + metaData.value("ARTIST");
    else
    {
        //Split off dirs from the title
        QStringList titleParts = mediaSource.fileName().split("/", QString::SkipEmptyParts);

        if(titleParts.length() > 0)
        {
            title = titleParts.last();

            //Split off the file extension from the title
            titleParts = title.split(".", QString::SkipEmptyParts);

            if(titleParts.length() > 0)
            {
                title = titleParts[0];
            }

            //Turn underscores to spaces in title
            title.replace("_", " ");
            title.replace("-", " - ");

            // Get rid of extra spaces and make first letter of every word uppercase
            titleParts = title.split(" ", QString::SkipEmptyParts);
            title = "";

            foreach(QString part, titleParts)
            {
                part = part.toLower();
                part[0] = part[0].toUpper();
                title += part + " ";
            }
        }
//----------------------------------------
//--- Primary playback control methods ---
//----------------------------------------
void Playlist::playItemAt(int row, Model model)
{
    bool isQueue = (model == QueueModel);
    MediaItem nextMediaItem = isQueue ? m_queue->mediaItemAt(row) :
                                        m_currentPlaylist->mediaItemAt(row);
    if (!isQueue) {
        nextMediaItem.playlistIndex = row;
    }
    nextMediaItem.nowPlaying = true;
    
    //Update Queue Model
    if (!m_shuffle) {
        //Just build a new queue from the row of the item in the playlist
        buildQueueFrom(nextMediaItem.playlistIndex);
    } else {
        int rowInQueue = isQueue ? row : m_queue->rowOfUrl(nextMediaItem.url);

        //Add currently playing item to history
        if (rowInQueue > 0 && m_nowPlaying->rowCount() > 0) {
            if (m_nowPlaying->mediaItemAt(0).type == "Audio" || m_nowPlaying->mediaItemAt(0).type == "Video") {
                int nowPlayingIndex = m_nowPlaying->mediaItemAt(0).playlistIndex;
                m_playlistIndicesHistory.append(nowPlayingIndex);
                m_playlistUrlHistory.append(m_nowPlaying->mediaItemAt(0).url);
                if (m_queue->rowCount() > 1) {
                    m_queue->removeMediaItemAt(0);
                    rowInQueue--;
                }
            }
        }

        //Remove requested item from history
        bool inHistory = (m_playlistIndicesHistory.indexOf(nextMediaItem.playlistIndex) != -1);
        if ( inHistory ) { //remove from history
            int idx = m_playlistIndicesHistory.indexOf(row);
            m_playlistIndicesHistory.removeAt(idx);
            m_playlistUrlHistory.removeAt(idx);
        }

        //Place requested item at front of queue
        QList<MediaItem> queueMediaList = m_queue->mediaList();
        if ( rowInQueue > 0 ) { //in queue, but not at first place, so move it
            queueMediaList.move(rowInQueue, 0);
        } else if (rowInQueue < 0) { //not in queue, so add it at first place
            queueMediaList.insert(0, nextMediaItem);
            if (queueMediaList.count() > m_queueDepth) {
                queueMediaList.removeLast();
            }
        } //else it is already at first place in the queue
        m_queue->clearMediaListData();
        m_queue->loadMediaList(queueMediaList, true);

        //Fill out queue
        shuffle();
    }
    
    //Play media Item
    m_mediaObject->clearQueue();
    m_currentStream.clear();
    QString subType;
    if (nextMediaItem.type == "Audio") {
        subType = nextMediaItem.fields["audioType"].toString();
    } else if(nextMediaItem.type == "Video") {
        subType = nextMediaItem.fields["videoType"].toString();
    }
    m_currentUrl = nextMediaItem.url;
    bool isDiscTitle = Utilities::isDisc( nextMediaItem.url );
    if (isDiscTitle) {
        Solid::Device device = Solid::Device( Utilities::deviceUdiFromUrl(nextMediaItem.url) );
        if (!device.isValid()) {
            stop();
            return;
        }
        const Solid::Block* block = device.as<const Solid::Block>();
        Phonon::DiscType discType = (subType == "CD Track") ? Phonon::Cd : Phonon::Dvd;
        Phonon::MediaSource src = Phonon::MediaSource(discType, block->device());
        int title = nextMediaItem.fields["trackNumber"].toInt();
        if (m_mediaObject->currentSource().discType() != src.discType() ||
            m_mediaObject->currentSource().deviceName() != src.deviceName()) {
            m_mediaObject->setCurrentSource(src);
        }
        if (title != -1) {
            m_mediaController->setCurrentTitle(title);
            m_mediaController->setAutoplayTitles(true);
        }
        m_mediaObject->play();
    } else if (subType == "Audio Stream") {
        m_currentStream = nextMediaItem.url;
        m_streamListUrls.clear();
        if (Utilities::isPls(nextMediaItem.url) || Utilities::isM3u(nextMediaItem.url)) {
            QList<MediaItem> streamList = Utilities::mediaListFromSavedList(nextMediaItem);
            for (int i = 0; i < streamList.count(); i++) {
                m_streamListUrls << streamList.at(i).url;
                if (i == 0) {
                    m_currentUrl = streamList.at(i).url;
                } else {
                    m_mediaObject->enqueue(Phonon::MediaSource(QUrl::fromPercentEncoding(streamList.at(i).url.toUtf8())));
                }
            }
        } else {
            m_streamListUrls << nextMediaItem.url;
        }
        m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromPercentEncoding(m_currentUrl.toUtf8())));
        m_mediaObject->play();
    } else {
        m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(m_currentUrl.toUtf8())));
        m_mediaObject->play();
    }
    m_state = Playlist::Playing;
}
Exemple #9
0
void MainWindow::currentSourceChanged(Phonon::MediaSource const& mediaSource)
{
    qDebug() << "MainWindow::currentSourceChanged()" << mediaSource.url();
}