summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2018-02-26 21:24:49 +0200
committerAndras Timar <andras.timar@collabora.com>2018-02-28 11:11:20 +0100
commit1ea276b4034f5bd8d0b0d748914d0760aba54600 (patch)
tree0d8deac0849994afd8d5d6ac780e8ab55806d258 /svx
parent2b309a8e027173285274c68f8d2a0219fea5f3fd (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> (cherry picked from commit 1aa5a3874bf716acfbded2a09319dce5d4ce8c0d) Reviewed-on: https://gerrit.libreoffice.org/50499 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@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 2a70bf95ceb4..9608088744af 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.
*
@@ -330,7 +330,8 @@ static bool lcl_HandleJsonPackageURL(
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 =
@@ -341,6 +342,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,
@@ -365,7 +377,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, ""));
@@ -406,7 +418,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);
}
void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProperties )