summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2023-04-05 11:50:44 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2023-04-05 14:34:51 +0200
commita5225ba82e94a549f44420f56a7cb9d7906561cc (patch)
tree084be80b91028e3bfbe8cd5e3b50ba97fa8b516d /avmedia
parent8b4af1eb0549b6832361da85ddaa1e13be34ec76 (diff)
avmedia,*: guess the mime type of media files based on file name
.. at least for the most popular types, and do it automatically in MediaItem::setURL(). This should work in practice in most cases and is much simpler than adding some type detection or calling into platform dependent avmedia backends. Remove the parameter that was only ever set to "application/vnd.sun.star.media" anyway, the same value that would be used if it's missing. Stop using that silly type for everything, only use it when guessing fails. In case an ODF document is loaded, it will use the mime type loaded from the file (see setting of MediaMimeType in SdXMLPluginShapeContext) and not guess it because that would require updating the entry in manifest.xml as well. Change-Id: I8ce29cf7425678ae11dda1d8c875be818f8623af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150049 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/source/framework/mediaitem.cxx9
-rw-r--r--avmedia/source/inc/mediamisc.hxx5
-rw-r--r--avmedia/source/viewer/mediawindow_impl.cxx7
3 files changed, 11 insertions, 10 deletions
diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx
index 77b28918f545..f177c8bea687 100644
--- a/avmedia/source/framework/mediaitem.cxx
+++ b/avmedia/source/framework/mediaitem.cxx
@@ -36,6 +36,7 @@
#include <ucbhelper/content.hxx>
+#include <comphelper/mediamimetype.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/storagehelper.hxx>
#include <mediamisc.hxx>
@@ -237,6 +238,7 @@ bool MediaItem::setURL(const OUString& rURL, const OUString& rTempURL, const OUS
m_pImpl->m_URL = rURL;
m_pImpl->m_TempFileURL = rTempURL;
m_pImpl->m_Referer = rReferer;
+ setMimeType(::comphelper::GuessMediaMimeType(GetFilename(rURL)));
}
return bChanged;
}
@@ -447,10 +449,9 @@ CreateStream(uno::Reference<embed::XStorage> const& xStorage,
uno::Reference< beans::XPropertySet > const xStreamProps(xStream,
uno::UNO_QUERY);
if (xStreamProps.is()) { // this is NOT supported in FileSystemStorage
- xStreamProps->setPropertyValue("MediaType", uno::Any(OUString(
- //FIXME how to detect real media type?
- //but currently xmloff has this one hardcoded anyway...
- "application/vnd.sun.star.media")));
+ OUString const guessed(::comphelper::GuessMediaMimeType(filename));
+ xStreamProps->setPropertyValue("MediaType",
+ uno::Any(guessed.isEmpty() ? AVMEDIA_MIMETYPE_COMMON : guessed));
xStreamProps->setPropertyValue( // turn off compression
"Compressed", uno::Any(false));
}
diff --git a/avmedia/source/inc/mediamisc.hxx b/avmedia/source/inc/mediamisc.hxx
index 061a7177f05a..f45f5b50da0b 100644
--- a/avmedia/source/inc/mediamisc.hxx
+++ b/avmedia/source/inc/mediamisc.hxx
@@ -19,6 +19,8 @@
#pragma once
+#include <comphelper/mediamimetype.hxx>
+
#include <unotools/resmgr.hxx>
#ifdef _WIN32
@@ -31,9 +33,6 @@
#endif
#endif
-// Mime types
-inline constexpr OUStringLiteral AVMEDIA_MIMETYPE_COMMON = u"application/vnd.sun.star.media";
-
inline OUString AvmResId(TranslateId aId)
{
return Translate::get(aId, Translate::Create("avmedia"));
diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx
index b74033e33749..82ca1b92821c 100644
--- a/avmedia/source/viewer/mediawindow_impl.cxx
+++ b/avmedia/source/viewer/mediawindow_impl.cxx
@@ -168,7 +168,7 @@ void MediaWindowImpl::dispose()
Control::dispose();
}
-uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rURL, const OUString& rReferer, const OUString* pMimeType)
+uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rURL, const OUString& rReferer, const OUString*)
{
uno::Reference<media::XPlayer> xPlayer;
@@ -180,7 +180,8 @@ uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rUR
return xPlayer;
}
- if (!pMimeType || *pMimeType == AVMEDIA_MIMETYPE_COMMON)
+ // currently there isn't anything else, throw any mime type to the media players
+ //if (!pMimeType || *pMimeType == AVMEDIA_MIMETYPE_COMMON)
{
uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
if (Application::GetToolkitName() == "gtk4")
@@ -397,7 +398,7 @@ void MediaWindowImpl::stopPlayingInternal(bool bStop)
void MediaWindowImpl::onURLChanged()
{
- if (m_sMimeType == AVMEDIA_MIMETYPE_COMMON)
+ //if (m_sMimeType == AVMEDIA_MIMETYPE_COMMON)
{
mpChildWindow.disposeAndClear();
mpChildWindow.reset(VclPtr<MediaChildWindow>::Create(this));