From: Thomas McGuire Date: Thu, 26 Jul 2012 14:06:17 +0000 (+0200) Subject: Blackberry: Fix playback from certain URLs X-Git-Tag: upstream/5.2.95+rc1~229 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37ee0912d6519a22f81a1adc9c01812997b00d68;p=platform%2Fupstream%2Fqtmultimedia.git Blackberry: Fix playback from certain URLs Previously, playback from URLs of the form "file:path/to/file" did not work. Change-Id: Iecd293d09f7c448438dbf259710c0aab218c2591 Reviewed-by: Sean Harmer --- diff --git a/src/plugins/blackberry/bbmediaplayercontrol.cpp b/src/plugins/blackberry/bbmediaplayercontrol.cpp index 3a84149..1fe21de 100644 --- a/src/plugins/blackberry/bbmediaplayercontrol.cpp +++ b/src/plugins/blackberry/bbmediaplayercontrol.cpp @@ -143,6 +143,42 @@ void BbMediaPlayerControl::closeConnection() } } +QString BbMediaPlayerControl::resourcePathForUrl(const QUrl &url) +{ + // If this is a local file, mmrenderer expects the file:// prefix and an absolute path. + // We treat URLs without scheme as local files, most likely someone just forgot to set the + // file:// prefix when constructing the URL. + if (url.isLocalFile() || url.scheme().isEmpty()) { + QString relativeFilePath; + if (!url.scheme().isEmpty()) + relativeFilePath = url.toLocalFile(); + else + relativeFilePath = url.path(); + const QFileInfo fileInfo(relativeFilePath); + return QStringLiteral("file://") + fileInfo.absoluteFilePath(); + + // QRC, copy to temporary file, as mmrenderer does not support resource files + } else if (url.scheme() == QStringLiteral("qrc")) { + const QString qrcPath = ':' + url.path(); + const QFileInfo resourceFileInfo(qrcPath); + m_tempMediaFileName = QDir::tempPath() + QStringLiteral("/qtmedia_") + + QUuid::createUuid().toString() + QStringLiteral(".") + + resourceFileInfo.suffix(); + if (!QFile::copy(qrcPath, m_tempMediaFileName)) { + const QString errorMsg = + QString("Failed to copy resource file to temporary file %1 for playback").arg(m_tempMediaFileName); + qBbMediaDebug() << errorMsg; + emit error(0, errorMsg); + return QString(); + } + return m_tempMediaFileName; + + // HTTP or similar URL, use as-is + } else { + return url.toString(); + } +} + void BbMediaPlayerControl::attach() { if (m_media.isNull() || !m_context) { @@ -159,35 +195,14 @@ void BbMediaPlayerControl::attach() return; } - // If this is a local file, use the full path as the resource identifier - QString mediaFile = m_media.canonicalUrl().toString(); - - // The mmrenderer does not support playback from resource files, so copy it to a temporary - // file - const QString resourcePrefix("qrc:"); - if (mediaFile.startsWith(resourcePrefix)) { - mediaFile.remove(0, resourcePrefix.length() - 1); - const QFileInfo resourceFileInfo(mediaFile); - m_tempMediaFileName = QDir::tempPath() + "/qtmedia_" + QUuid::createUuid().toString() + "." + - resourceFileInfo.suffix(); - if (!QFile::copy(mediaFile, m_tempMediaFileName)) { - const QString errorMsg = - QString("Failed to copy resource file to temporary file %1 for playback").arg(m_tempMediaFileName); - qBbMediaDebug() << errorMsg; - emit error(0, errorMsg); - detach(); - return; - } - mediaFile = m_tempMediaFileName; - } - - if (m_media.canonicalUrl().scheme().isEmpty()) { - const QFileInfo fileInfo(mediaFile); - mediaFile = "file://" + fileInfo.absoluteFilePath(); + const QString resourcePath = resourcePathForUrl(m_media.canonicalUrl()); + if (resourcePath.isEmpty()) { + detach(); + return; } - if (mmr_input_attach(m_context, QFile::encodeName(mediaFile), "track") != 0) { - emitMmError(QString("mmr_input_attach() for %1 failed").arg(mediaFile)); + if (mmr_input_attach(m_context, QFile::encodeName(resourcePath), "track") != 0) { + emitMmError(QString("mmr_input_attach() for %1 failed").arg(resourcePath)); setMediaStatus(QMediaPlayer::InvalidMedia); detach(); return; diff --git a/src/plugins/blackberry/bbmediaplayercontrol.h b/src/plugins/blackberry/bbmediaplayercontrol.h index e8a9ed8..2f304e0 100644 --- a/src/plugins/blackberry/bbmediaplayercontrol.h +++ b/src/plugins/blackberry/bbmediaplayercontrol.h @@ -105,6 +105,7 @@ private Q_SLOTS: void continueLoadMedia(); private: + QString resourcePathForUrl(const QUrl &url); void openConnection(); void closeConnection(); void attach();