summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-02-26 21:24:49 +0200
committerTor Lillqvist <tml@collabora.com>2018-02-27 14:45:03 +0100
commit1aa5a3874bf716acfbded2a09319dce5d4ce8c0d (patch)
treeb7415214fb92de8954a5a7613e8154fd87f857dd /svx
parent0d8ea9c730abd0ffb6f52337c84835cb3d5be335 (diff)
tdf#79546: Make sure temp copy of inserted media file keeps the same extension
Inserting videos into Impress presentations with 'Insert>Audio or Video' did not work at all for me. This helps. It seems that the AVFoundation APIs are sadly rather picky about file name extensions. Why we need to make a temporary copy of the media file (which after all can be rather large) at all, when inserting it in a slide, I don't understand. But I am not going to dig into that now. Change-Id: I43fcfb5bb3ef0a2c0f8979ac3e7c458a84f180a1 Reviewed-on: https://gerrit.libreoffice.org/50390 Reviewed-by: Tor Lillqvist <tml@collabora.com> Tested-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdomedia.cxx28
1 files changed, 24 insertions, 4 deletions
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 8303e2b71fa9..4c41e76e6dc3 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column:100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -269,7 +269,8 @@ uno::Reference<io::XInputStream> SdrMediaObj::GetInputStream()
static bool lcl_CopyToTempFile(
uno::Reference<io::XInputStream> const& xInStream,
- OUString & o_rTempFileURL)
+ OUString & o_rTempFileURL,
+ const OUString& rDesiredExtension)
{
OUString tempFileURL;
::osl::FileBase::RC const err =
@@ -280,6 +281,17 @@ static bool lcl_CopyToTempFile(
return false;
}
+ if (!rDesiredExtension.isEmpty())
+ {
+ OUString newTempFileURL = tempFileURL + rDesiredExtension;
+ if (osl::File::move(tempFileURL, newTempFileURL) != osl::FileBase::E_None)
+ {
+ SAL_WARN("svx", "Could not rename file '" << tempFileURL << "' to '" << newTempFileURL << "'");
+ return false;
+ }
+ tempFileURL = newTempFileURL;
+ }
+
try
{
::ucbhelper::Content tempContent(tempFileURL,
@@ -304,7 +316,7 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream
return;
}
OUString tempFileURL;
- bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL);
+ bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL, "");
if (bSuccess)
{
m_xImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL));
@@ -348,7 +360,15 @@ static bool lcl_HandlePackageURL(
SAL_WARN("svx", "no stream?");
return false;
}
- return lcl_CopyToTempFile(xInStream, o_rTempFileURL);
+ // Make sure the temporary copy has the same file name extension as the original media file
+ // (like .mp4). That seems to be important for some AVFoundation APIs. For random extension-less
+ // file names, they don't seem to even bother looking inside the file.
+ sal_Int32 nLastDot = rURL.lastIndexOf('.');
+ sal_Int32 nLastSlash = rURL.lastIndexOf('/');
+ OUString sDesiredExtension;
+ if (nLastDot > nLastSlash && nLastDot+1 < rURL.getLength())
+ sDesiredExtension = rURL.copy(nLastDot);
+ return lcl_CopyToTempFile(xInStream, o_rTempFileURL, sDesiredExtension);
}
#endif