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 <sean.harmer@kdab.com>
This commit is contained in:
committed by
Qt by Nokia
parent
d272782da9
commit
37ee0912d6
@@ -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()
|
void BbMediaPlayerControl::attach()
|
||||||
{
|
{
|
||||||
if (m_media.isNull() || !m_context) {
|
if (m_media.isNull() || !m_context) {
|
||||||
@@ -159,35 +195,14 @@ void BbMediaPlayerControl::attach()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a local file, use the full path as the resource identifier
|
const QString resourcePath = resourcePathForUrl(m_media.canonicalUrl());
|
||||||
QString mediaFile = m_media.canonicalUrl().toString();
|
if (resourcePath.isEmpty()) {
|
||||||
|
detach();
|
||||||
// The mmrenderer does not support playback from resource files, so copy it to a temporary
|
return;
|
||||||
// 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()) {
|
if (mmr_input_attach(m_context, QFile::encodeName(resourcePath), "track") != 0) {
|
||||||
const QFileInfo fileInfo(mediaFile);
|
emitMmError(QString("mmr_input_attach() for %1 failed").arg(resourcePath));
|
||||||
mediaFile = "file://" + fileInfo.absoluteFilePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mmr_input_attach(m_context, QFile::encodeName(mediaFile), "track") != 0) {
|
|
||||||
emitMmError(QString("mmr_input_attach() for %1 failed").arg(mediaFile));
|
|
||||||
setMediaStatus(QMediaPlayer::InvalidMedia);
|
setMediaStatus(QMediaPlayer::InvalidMedia);
|
||||||
detach();
|
detach();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ private Q_SLOTS:
|
|||||||
void continueLoadMedia();
|
void continueLoadMedia();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString resourcePathForUrl(const QUrl &url);
|
||||||
void openConnection();
|
void openConnection();
|
||||||
void closeConnection();
|
void closeConnection();
|
||||||
void attach();
|
void attach();
|
||||||
|
|||||||
Reference in New Issue
Block a user