void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream)
{
    Q_Q(QMediaPlayer);

    if (!control)
        return;

    QScopedPointer<QFile> file;

    // Backends can't play qrc files directly.
    // If the backend supports StreamPlayback, we pass a QFile for that resource.
    // If it doesn't, we copy the data to a temporary file and pass its path.
    if (!media.isNull() && !stream && media.canonicalUrl().scheme() == QLatin1String("qrc")) {
        qrcMedia = media;

        file.reset(new QFile(QLatin1Char(':') + media.canonicalUrl().path()));
        if (!file->open(QFile::ReadOnly)) {
            QMetaObject::invokeMethod(q, "_q_error", Qt::QueuedConnection,
                                      Q_ARG(int, QMediaPlayer::ResourceError),
                                      Q_ARG(QString, QMediaPlayer::tr("Attempting to play invalid Qt resource")));
            QMetaObject::invokeMethod(q, "_q_mediaStatusChanged", Qt::QueuedConnection,
                                      Q_ARG(QMediaPlayer::MediaStatus, QMediaPlayer::InvalidMedia));
            file.reset();
            // Ignore the next NoMedia status change, we just want to clear the current media
            // on the backend side since we can't load the new one and we want to be in the
            // InvalidMedia status.
            ignoreNextStatusChange = QMediaPlayer::NoMedia;
            control->setMedia(QMediaContent(), 0);

        } else if (hasStreamPlaybackFeature) {
Beispiel #2
0
/*------------------------------------------------------------------------------
|    OpenMAXILPlayerControl::setMedia
+-----------------------------------------------------------------------------*/
void OpenMAXILPlayerControl::setMedia(const QMediaContent& content, QIODevice* stream)
{
   Q_UNUSED(stream);

   log_debug_func;

   logi_debug("Media: %s.", qPrintable(content.canonicalUrl().toString()));
   logi_debug("setMedia thread is: %p.", ((unsigned int)QThread::currentThread()));

   if (!m_mediaProcessor->setFilename(content.canonicalUrl().toString()))
      return;
   m_currentResource = content;
   emit mediaChanged(content);
}
Beispiel #3
0
FileHelper::FileHelper(const QMediaContent &track)
	: _file(nullptr), _fileType(UNKNOWN), _isValid(false)
{
	bool b = init(QDir::fromNativeSeparators(track.canonicalUrl().toLocalFile()));
	if (!b) {
		b = init(QDir::toNativeSeparators(track.canonicalUrl().toLocalFile()));
	}
	if (!b) {
		if (_file != nullptr) {
			delete _file;
			_file = nullptr;
		}
		_fileType = UNKNOWN;
	}
}
QVariant MusicPlayListModel::data(const QModelIndex & index, int role) const
{
    if (index.isValid())
    {
        QMediaContent item = _mediaplay_list->media(index.row());
        if (item == NULL)
        {
            return QVariant();
        }
        if (role == Number)
        {
            return index.row() + 1;
        }
        if (role == Name)
        {
            QUrl location = item.canonicalUrl();
            return QFileInfo(location.path()).fileName();
        }
        if (role == Duration)
        {
            return 0;
        }
    }
    return QVariant();
}
Beispiel #5
0
void QWmpPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
{
    if (!content.isNull() && !stream)
        setUrl(content.canonicalUrl());
    else
        setUrl(QUrl());
}
void QWinRTMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream)
{
    Q_D(QWinRTMediaPlayerControl);

    if (d->media == media)
        return;

    d->media = media;
    d->stream.reset(stream);
    if (d->hasAudio != false) {
        d->hasAudio = false;
        emit audioAvailableChanged(d->hasAudio);
    }
    if (d->hasVideo != false) {
        d->hasVideo = false;
        emit videoAvailableChanged(d->hasVideo);
    }
    if (d->seekable != false) {
        d->seekable = false;
        emit seekableChanged(d->seekable);
    }
    if (d->bufferStatus != 0) {
        d->bufferStatus = 0;
        emit bufferStatusChanged(d->bufferStatus);
    }
    if (d->position != 0) {
        d->position = 0;
        emit positionChanged(d->position);
    }
    if (d->duration != 0) {
        d->duration = 0;
        emit durationChanged(d->duration);
    }
    QMediaPlayer::MediaStatus mediaStatus = media.isNull() ? QMediaPlayer::NoMedia
                                                           : QMediaPlayer::LoadingMedia;
    if (d->mediaStatus != mediaStatus) {
        d->mediaStatus = mediaStatus;
        emit mediaStatusChanged(d->mediaStatus);
    }
    emit mediaChanged(media);

    QString urlString = media.canonicalUrl().toString();
    if (!d->stream) {
        // If we can read the file via Qt, use the byte stream approach
        foreach (const QMediaResource &resource, media.resources()) {
            const QUrl url = resource.url();
            if (url.isLocalFile()) {
                urlString = url.toLocalFile();
                QScopedPointer<QFile> file(new QFile(urlString));
                if (file->open(QFile::ReadOnly)) {
                    file->setProperty(QT_WINRT_MEDIAPLAYER_STREAM_ID, true);
                    d->stream.reset(file.take());
                    break;
                }
            }
        }
    }
Beispiel #7
0
void MediaPlayer::playMediaContent(const QMediaContent &mc)
{
	if ((_state == QMediaPlayer::PlayingState) || (_state == QMediaPlayer::PausedState)) {
		this->stop();
	}

	// Everything is splitted in 2: local actions and remote actions
	if (mc.canonicalUrl().isLocalFile()) {
		_localPlayer->play(mc.canonicalUrl().toLocalFile());
	} else {
		// Find remote player attached to mediaContent
		_remotePlayer = _remotePlayers.value(mc.canonicalUrl().host());
		if (_remotePlayer) {
			_remotePlayer->play(mc.canonicalUrl());
        }
	}
	this->setVolume(Settings::instance()->volume());
}
void tst_QMediaContent::testNull()
{
    QMediaContent media;

    QCOMPARE(media.isNull(), true);
    QCOMPARE(media.canonicalUrl(), QUrl());
    QCOMPARE(media.canonicalResource(), QMediaResource());
    QCOMPARE(media.resources(), QMediaResourceList());
}
/*------------------------------------------------------------------------------
|    OpenMAXILPlayerControl::setMediaInt
+-----------------------------------------------------------------------------*/
void OpenMAXILPlayerControl::setMediaInt(const QMediaContent& mediaContent)
{
   LOG_DEBUG(LOG_TAG, "%s", Q_FUNC_INFO);

   m_mediaProcessor->stop();

   m_textureData = NULL;
   if (!m_mediaProcessor->setFilename(mediaContent.canonicalUrl().toString(), m_textureData))
      return;
   m_currentResource = mediaContent;
   emit mediaChanged(mediaContent);
}
Beispiel #10
0
void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
{
    QMediaPlayer::State oldState = m_state;
    m_state = QMediaPlayer::StoppedState;    
    m_session->stop();

    if (m_bufferProgress != -1) {
        m_bufferProgress = -1;
        emit bufferStatusChanged(0);
    }

    if (m_stream) {
        closeFifo();

        disconnect(m_stream, SIGNAL(readyRead()), this, SLOT(writeFifo()));
        m_stream = 0;
    }

    m_currentResource = content;
    m_stream = stream;

    QUrl url;

    if (m_stream) {
        if (m_stream->isReadable() && openFifo()) {
            url = QUrl(QString(QLatin1String("fd://%1")).arg(m_fifoFd[0]));
        }
    } else if (!content.isNull()) {
        url = content.canonicalUrl();
    }

    m_session->load(url);

    if (m_fifoFd[1] >= 0) {
        m_fifoCanWrite = true;

        writeFifo();
    }

    if (!url.isEmpty()) {
        if (m_mediaStatus != QMediaPlayer::LoadingMedia)
            emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::LoadingMedia);
        m_session->pause();
    } else {
        if (m_mediaStatus != QMediaPlayer::NoMedia)
            emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::NoMedia);
        setBufferProgress(0);
    }

    emit mediaChanged(m_currentResource);
    if (m_state != oldState)
        emit stateChanged(m_state);
}
Beispiel #11
0
/*------------------------------------------------------------------------------
|    OpenMAXILPlayerControl::setMediaInt
+-----------------------------------------------------------------------------*/
void OpenMAXILPlayerControl::setMediaInt(const QMediaContent& mediaContent)
{
   log_debug_func;

   m_mediaProcessor->stop();

   m_textureData = NULL;
   if (!m_mediaProcessor->setFilename(mediaContent.canonicalUrl().toString(), m_textureData))
      return;
   m_currentResource = mediaContent;
   emit mediaChanged(mediaContent);
}
Beispiel #12
0
bool QWmpPlaylist::insertMedia(int pos, const QMediaContent &content)
{
    bool inserted = false;

    IWMPMedia *media = 0;
    if (m_playlist && m_player && m_player->newMedia(
            QAutoBStr(content.canonicalUrl()), &media) == S_OK) {
        inserted = m_playlist->insertItem(pos, media) == S_OK;

        media->Release();
    }

    return inserted;
}
Beispiel #13
0
bool QWmpPlaylist::addMedia(const QMediaContent &content)
{
    bool appended = false;

    IWMPMedia *media = 0;
    if (!content.isNull() && m_playlist && m_player && m_player->newMedia(
            QAutoBStr(content.canonicalUrl()), &media) == S_OK) {
        appended = m_playlist->appendItem(media) == S_OK;

        media->Release();
    }

    return appended;
}
void PlaylistItemDelegate::commitAndClose()
{
	auto db = SqlDatabase::instance();
	QStringList tracksToUpdate;
	QStringList tracksToUpdate2;
	// Multiple editors might have been opened by one, therefore it's required to commit and close all of them
	for (StarEditor *se : parent()->findChildren<StarEditor*>()) {
		QMediaContent mediaContent = _playlist->mediaPlaylist()->media(se->index().row());
		QString fileName = QString(QFile::encodeName(mediaContent.canonicalUrl().toLocalFile()));
		FileHelper fh(fileName);
		fh.setRating(se->starRating.starCount());
		commitData(se);
		closeEditor(se);
		tracksToUpdate << fileName;
		tracksToUpdate2 << QString();
	}
	db->updateTracks(tracksToUpdate, tracksToUpdate2);
}
Beispiel #15
0
/*------------------------------------------------------------------------------
|    OpenMAXILPlayerControl::setMedia
+-----------------------------------------------------------------------------*/
void OpenMAXILPlayerControl::setMedia(const QMediaContent& content, QIODevice* stream)
{
   Q_UNUSED(stream);

   log_debug_func;
   log_debug("Media: %s.", qPrintable(content.canonicalUrl().toString()));
   log_debug("setMedia thread is: 0x%x.", ((unsigned int)QThread::currentThread()));

   log_verbose("Deferring setMedia()...");
   /*QUrl url = content.canonicalUrl();
   if (url.isLocalFile() && !QFile(url.path()).exists()) {
      log_warn("Does not exist!");
      return;
   }*/

   PlayerCommandSetMedia* setMedia = new PlayerCommandSetMedia;
   setMedia->m_playerCommandType = PLAYER_COMMAND_TYPE_SET_MEDIA;
   setMedia->m_mediaContent = content;
   appendCommand(setMedia);
}
/*------------------------------------------------------------------------------
|    OpenMAXILPlayerControl::setMedia
+-----------------------------------------------------------------------------*/
void OpenMAXILPlayerControl::setMedia(const QMediaContent& content, QIODevice* stream)
{
   Q_UNUSED(stream);

   LOG_DEBUG(LOG_TAG, "%s", Q_FUNC_INFO);
   LOG_DEBUG(LOG_TAG, "Media: %s.", qPrintable(content.canonicalUrl().path()));
   LOG_DEBUG(LOG_TAG, "setMedia thread is: 0x%x.", ((unsigned int)QThread::currentThread()));

   LOG_VERBOSE(LOG_TAG, "Deferring setMedia()...");
   LOG_VERBOSE(LOG_TAG, "SKIPPED LOCAL PATH CHECKING!");
   //QUrl url = content.canonicalUrl();
   //if (url.isLocalFile() && !QFile(url.path()).exists()) {
   //   LOG_DEBUG(LOG_TAG, "Does not exist!");
   //   return;
   //}

   PlayerCommandSetMedia* setMedia = new PlayerCommandSetMedia;
   setMedia->m_playerCommandType = PLAYER_COMMAND_TYPE_SET_MEDIA;
   setMedia->m_mediaContent = content;
   appendCommand(setMedia);
}
void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
                                          QIODevice *stream)
{
    mMediaContent = mediaContent;
    mMediaStream = stream;

    const QString uri = mediaContent.canonicalUrl().toString();

    if (!uri.isEmpty())
        mMediaPlayer->setDataSource(uri);
    else
        setMediaStatus(QMediaPlayer::NoMedia);

    Q_EMIT mediaChanged(mMediaContent);

    resetBufferingProgress();

    // reset some properties
    setAudioAvailable(false);
    setVideoAvailable(false);
    setSeekable(true);
}
void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
                                          QIODevice *stream)
{
    mMediaContent = mediaContent;
    mMediaStream = stream;

    if (mVideoOutput && !mMediaPlayer->display()) {
        // if a video output is set but the video texture is not ready, delay loading the media
        // since it can cause problems on some hardware
        mPendingSetMedia = true;
        return;
    }

    const QUrl url = mediaContent.canonicalUrl();
    QString mediaPath;
    if (url.scheme() == QLatin1String("qrc")) {
        const QString path = url.toString().mid(3);
        mTempFile.reset(QTemporaryFile::createNativeFile(path));
        if (!mTempFile.isNull())
            mediaPath = QLatin1String("file://") + mTempFile->fileName();
    } else {
        mediaPath = url.toString();
    }

    if (!mediaPath.isEmpty())
        mMediaPlayer->setDataSource(mediaPath);
    else
        setMediaStatus(QMediaPlayer::NoMedia);

    Q_EMIT mediaChanged(mMediaContent);

    resetBufferingProgress();

    // reset some properties
    setAudioAvailable(false);
    setVideoAvailable(false);
    setSeekable(true);
}
 virtual bool writeItem(const QMediaContent& item)
 {
     *m_textStream << item.canonicalUrl().toString() << endl;
     return true;
 }
Beispiel #20
0
void Window::currentMediaChanged(const QMediaContent &media) {
    process->setValue(0);
    metaData(media.canonicalUrl());
}
void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
{
#ifdef DEBUG_PLAYBIN
    qDebug() << Q_FUNC_INFO;
#endif

    pushState();

    m_currentState = QMediaPlayer::StoppedState;
    QMediaContent oldMedia = m_currentResource;
    m_pendingSeekPosition = 0;
    m_session->showPrerollFrames(false); // do not show prerolled frames until pause() or play() explicitly called
    m_setMediaPending = false;

    if (!content.isNull() || stream) {
        if (!m_resources->isGranted())
            m_resources->acquire();
    } else {
        m_resources->release();
    }

    m_session->stop();

    bool userStreamValid = false;

    if (m_bufferProgress != -1) {
        m_bufferProgress = -1;
        emit bufferStatusChanged(0);
    }

    if (m_stream && m_stream != stream) {
        if (m_ownStream)
            delete m_stream;
        m_stream = 0;
        m_ownStream = false;
    }

    // If the canonical URL refers to a Qt resource, open with QFile and use
    // the stream playback capability to play.
    if (stream == 0 && content.canonicalUrl().scheme() == QLatin1String("qrc")) {
        stream = new QFile(QLatin1Char(':') + content.canonicalUrl().path(), this);
        if (!stream->open(QIODevice::ReadOnly)) {
            delete stream;
            m_mediaStatus = QMediaPlayer::InvalidMedia;
            m_currentResource = content;
            emit mediaChanged(m_currentResource);
            emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid Qt resource"));
            if (m_currentState != QMediaPlayer::PlayingState)
                m_resources->release();
            popAndNotifyState();
            return;
        }
        m_ownStream = true;
    }

    m_currentResource = content;
    m_stream = stream;

    QNetworkRequest request;

    if (m_stream) {
        userStreamValid = stream->isOpen() && m_stream->isReadable();
        request = content.canonicalRequest();
    } else if (!content.isNull()) {
        request = content.canonicalRequest();
    }

#if !defined(HAVE_GST_APPSRC)
    m_session->loadFromUri(request);
#else
    if (m_stream) {
        if (userStreamValid){
            m_session->loadFromStream(request, m_stream);
        } else {
            m_mediaStatus = QMediaPlayer::InvalidMedia;
            emit error(QMediaPlayer::FormatError, tr("Attempting to play invalid user stream"));
            if (m_currentState != QMediaPlayer::PlayingState)
                m_resources->release();
            popAndNotifyState();
            return;
        }
    } else
        m_session->loadFromUri(request);
#endif


#if defined(HAVE_GST_APPSRC)
    if (!request.url().isEmpty() || userStreamValid) {
#else
    if (!request.url().isEmpty()) {
#endif
        m_mediaStatus = QMediaPlayer::LoadingMedia;
        m_session->pause();
    } else {
        m_mediaStatus = QMediaPlayer::NoMedia;
        setBufferProgress(0);
    }

    if (m_currentResource != oldMedia)
        emit mediaChanged(m_currentResource);

    emit positionChanged(position());

    if (content.isNull() && !stream)
        m_resources->release();

    popAndNotifyState();
}

void QGstreamerPlayerControl::setVideoOutput(QObject *output)
{
    m_session->setVideoRenderer(output);
}