コード例 #1
0
void QWmpPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream)
{
    if (!content.isNull() && !stream)
        setUrl(content.canonicalUrl());
    else
        setUrl(QUrl());
}
コード例 #2
0
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();
}
コード例 #3
0
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) {
コード例 #4
0
void tst_QMediaContent::testNull()
{
    QMediaContent media;

    QCOMPARE(media.isNull(), true);
    QCOMPARE(media.canonicalUrl(), QUrl());
    QCOMPARE(media.canonicalResource(), QMediaResource());
    QCOMPARE(media.resources(), QMediaResourceList());
}
コード例 #5
0
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;
    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;
                }
            }
        }
    }
コード例 #6
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;
    m_seekToStartPending = false;

    QNetworkRequest request;

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

    m_session->load(request);    

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

        writeFifo();
    }

    if (!request.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);
}
コード例 #7
0
ファイル: mediaplayer.cpp プロジェクト: MBach/Miam-Player
/** Play current track in the playlist. */
void MediaPlayer::play()
{
	// Check if it's possible to play tracks first
	if (!_playlist) {
		return;
	}
	QMediaContent mc = _playlist->media(_playlist->currentIndex());
	if (mc.isNull()) {
		return;
	}
	this->playMediaContent(mc);
}
コード例 #8
0
ファイル: openmaxilplayercontrol.cpp プロジェクト: darcyg/pi
/*------------------------------------------------------------------------------
|    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);
}
コード例 #9
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;
}
コード例 #10
0
ファイル: filehelper.cpp プロジェクト: percevall/Miam-Player
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;
	}
}
コード例 #11
0
void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media)
{
    if (!control)
        return;

    const QMediaPlayer::State currentState = state;

    filterStates = true;
    control->setMedia(media, 0);

    if (!media.isNull()) {
        switch (currentState) {
        case QMediaPlayer::PlayingState:
            control->play();
            break;
        case QMediaPlayer::PausedState:
            control->pause();
            break;
        default:
            break;
        }
    }
    filterStates = false;

    state = control->state();

    if (state != currentState)
        emit q_func()->stateChanged(state);
}
コード例 #12
0
ファイル: mediaplayer.cpp プロジェクト: MBach/Miam-Player
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());
}
コード例 #13
0
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);
}
コード例 #14
0
/*------------------------------------------------------------------------------
|    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);
}
コード例 #15
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);
}
コード例 #16
0
void DirectShowPlayerService::load(const QMediaContent &media, QIODevice *stream)
{
    QMutexLocker locker(&m_mutex);

    m_pendingTasks = 0;

    if (m_graph)
        releaseGraph();

    m_resources = media.resources();
    m_stream = stream;
    m_error = QMediaPlayer::NoError;
    m_errorString = QString();
    m_position = 0;
    m_duration = 0;
    m_streamTypes = 0;
    m_executedTasks = 0;
    m_buffering = false;
    m_seekable = false;
    m_atEnd = false;
    m_metaDataControl->updateGraph(0, 0);

    if (m_resources.isEmpty() && !stream) {
        m_pendingTasks = 0;
        m_graphStatus = NoMedia;

        m_url.clear();
    } else if (stream && (!stream->isReadable() || stream->isSequential())) {
        m_pendingTasks = 0;
        m_graphStatus = InvalidMedia;
        m_error = QMediaPlayer::ResourceError;
    } else {
        // {36b73882-c2c8-11cf-8b46-00805f6cef60}
        static const GUID iid_IFilterGraph2 = {
            0x36b73882, 0xc2c8, 0x11cf, {0x8b, 0x46, 0x00, 0x80, 0x5f, 0x6c, 0xef, 0x60} };
        m_graphStatus = Loading;

        m_graph = com_new<IFilterGraph2>(CLSID_FilterGraph, iid_IFilterGraph2);

        if (stream)
            m_pendingTasks = SetStreamSource;
        else
            m_pendingTasks = SetUrlSource;

        ::SetEvent(m_taskHandle);
    }

    m_playerControl->updateError(m_error, m_errorString);
    m_playerControl->updateMediaInfo(m_duration, m_streamTypes, m_seekable);
    m_playerControl->updateState(QMediaPlayer::StoppedState);
    m_playerControl->updatePosition(m_position);
    updateStatus();
}
コード例 #17
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;
}
コード例 #18
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);
}
コード例 #19
0
/*------------------------------------------------------------------------------
|    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);
}
コード例 #20
0
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);
}
コード例 #21
0
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);
}
コード例 #22
0
ファイル: qmediaplayer.cpp プロジェクト: RobinD42/qt-mobility
void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media)
{
    Q_Q(QMediaPlayer);

    if (!control)
        return;

    const QMediaPlayer::State currentState = state;

    filterStates = true;
    control->setMedia(media, 0);

    if (!media.isNull()) {
        switch (currentState) {
        case QMediaPlayer::PlayingState:
            control->play();
            break;
        case QMediaPlayer::PausedState:
            control->pause();
            break;
        default:
            break;
        }
    }
    filterStates = false;

    state = control->state();

    if (state != currentState) {
        if (state == QMediaPlayer::PlayingState)
            q->addPropertyWatch("position");
        else
            q->removePropertyWatch("position");

        emit q->stateChanged(state);
    }
}
コード例 #23
0
void QMediaPlayerPrivate::_q_updateMedia(const QMediaContent &media)
{
    Q_Q(QMediaPlayer);

    if (!control)
        return;

    // check if the current playlist is a top-level playlist
    Q_ASSERT(playlist);
    if (media.isNull() && playlist != rootMedia.playlist()) {
        // switch back to parent playlist
        QMediaPlaylist *pls = parentPlaylist(playlist);
        Q_ASSERT(pls);
        disconnectPlaylist();
        playlist = pls;
        connectPlaylist();

        Q_ASSERT(!pendingPlaylist.playlist());
        nestedPlaylists--;
        Q_ASSERT(nestedPlaylists >= 0);

        playlist->next();
        return;
    }

    if (media.playlist()) {
        if (nestedPlaylists < MAX_NESTED_PLAYLISTS) {
            nestedPlaylists++;
            Q_ASSERT(!pendingPlaylist.playlist());

            // disconnect current playlist
            disconnectPlaylist();
            // new playlist signals are connected
            // in the call to setPlaylist() in _q_handlePlaylistLoaded()
            playlist = media.playlist();
            emit q->currentMediaChanged(media);
            _q_handlePlaylistLoaded();
            return;
        } else if (playlist) {
            playlist->next();
        }
        return;
    }

    const QMediaPlayer::State currentState = state;

    setMedia(media, 0);

    if (!media.isNull()) {
        switch (currentState) {
        case QMediaPlayer::PlayingState:
            control->play();
            break;
        case QMediaPlayer::PausedState:
            control->pause();
            break;
        default:
            break;
        }
    }

    _q_stateChanged(control->state());
}
コード例 #24
0
ファイル: window.cpp プロジェクト: chideat/media-player
void Window::currentMediaChanged(const QMediaContent &media) {
    process->setValue(0);
    metaData(media.canonicalUrl());
}
コード例 #25
0
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);
}
コード例 #26
0
 virtual bool writeItem(const QMediaContent& item)
 {
     *m_textStream << item.canonicalUrl().toString() << endl;
     return true;
 }