tdf#158510 Added fallback for media files in MediaWindowImpl

When launching media from Properties -> Media Playback,
no sound is currently playing. This is due to the fact that
there is no fallback URL defined for MediaWindowImpl.

To fix this problem, new methods have been added for
setting and getting the fallback URL, passing the path to
the presentation folder from "unoshap4.cxx" to
"mediawindow_imp.cxx".

Because the setURL method starts the media immediately,
calls to "setFallbackURL" method must be made BEFORE
calling "setURL".

Change-Id: I3054c90c648c5839a2eb3fc463eaefbf97500c05
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170644
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Vladislav Tarakanov 2024-08-13 18:11:35 +04:00 committed by Mike Kaganski
parent 935afa6d82
commit 134fb4747a
6 changed files with 64 additions and 1 deletions

View file

@ -55,6 +55,7 @@ struct MediaItem::Impl
{
OUString m_URL;
OUString m_TempFileURL;
OUString m_FallbackURL;
OUString m_Referer;
OUString m_sMimeType;
AVMediaSetMask m_nMaskSet;
@ -107,6 +108,7 @@ bool MediaItem::operator==( const SfxPoolItem& rItem ) const
MediaItem const& rOther(static_cast< const MediaItem& >(rItem));
return m_pImpl->m_nMaskSet == rOther.m_pImpl->m_nMaskSet
&& m_pImpl->m_URL == rOther.m_pImpl->m_URL
&& m_pImpl->m_FallbackURL == rOther.m_pImpl->m_FallbackURL
&& m_pImpl->m_Referer == rOther.m_pImpl->m_Referer
&& m_pImpl->m_sMimeType == rOther.m_pImpl->m_sMimeType
&& m_pImpl->m_aGraphic == rOther.m_pImpl->m_aGraphic
@ -189,7 +191,11 @@ bool MediaItem::merge(const MediaItem& rMediaItem)
const AVMediaSetMask nMaskSet = rMediaItem.getMaskSet();
if( AVMediaSetMask::URL & nMaskSet )
{
bChanged = m_pImpl->m_FallbackURL == rMediaItem.getFallbackURL();
m_pImpl->m_FallbackURL = rMediaItem.getFallbackURL();
bChanged |= setURL(rMediaItem.getURL(), rMediaItem.getTempURL(), rMediaItem.getReferer());
}
if( AVMediaSetMask::MIME_TYPE & nMaskSet )
bChanged |= setMimeType(rMediaItem.getMimeType());
@ -248,6 +254,18 @@ const OUString& MediaItem::getURL() const
return m_pImpl->m_URL;
}
bool MediaItem::setFallbackURL(const OUString& rURL)
{
bool bChanged = rURL != m_pImpl->m_FallbackURL;
if (bChanged)
m_pImpl->m_FallbackURL = rURL;
return bChanged;
}
const OUString& MediaItem::getFallbackURL() const
{
return m_pImpl->m_FallbackURL;
}
const OUString& MediaItem::getTempURL() const
{
return m_pImpl->m_TempFileURL;

View file

@ -30,6 +30,7 @@
#include <sal/log.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/DirectoryHelper.hxx>
#include <comphelper/scopeguard.hxx>
#include <tools/urlobj.hxx>
#include <unotools/securityoptions.hxx>
@ -251,7 +252,19 @@ void MediaWindowImpl::setURL( const OUString& rURL,
maFileURL = rURL;
}
mxPlayer = createPlayer((!mTempFileURL.isEmpty()) ? mTempFileURL : maFileURL, rReferer, &m_sMimeType );
OUString mediaURL;
// If the file with the given URL does not exist and a fallback is specified, then use it
if ( rURL.startsWith("file:///")
&& !comphelper::DirectoryHelper::fileExists(maFileURL)
&& maFallbackFileURL.getLength() > 0 )
{
mediaURL = maFallbackFileURL;
}
else
mediaURL = (!mTempFileURL.isEmpty()) ? mTempFileURL : maFileURL;
mxPlayer = createPlayer(mediaURL, rReferer, &m_sMimeType );
onURLChanged();
}
@ -260,6 +273,16 @@ const OUString& MediaWindowImpl::getURL() const
return maFileURL;
}
void MediaWindowImpl::setFallbackURL( const OUString& rURL )
{
maFallbackFileURL = rURL;
}
const OUString& MediaWindowImpl::getFallbackURL() const
{
return maFallbackFileURL;
}
bool MediaWindowImpl::isValid() const
{
return mxPlayer.is();
@ -298,6 +321,7 @@ void MediaWindowImpl::updateMediaItem( MediaItem& rItem ) const
rItem.setMute( mxPlayer.is() && mxPlayer->isMute() );
rItem.setVolumeDB( mxPlayer.is() ? mxPlayer->getVolumeDB() : 0 );
rItem.setZoom( mxPlayerWindow.is() ? mxPlayerWindow->getZoomLevel() : media::ZoomLevel_NOT_AVAILABLE );
rItem.setFallbackURL( getFallbackURL() );
rItem.setURL( getURL(), mTempFileURL, maReferer );
}
@ -312,6 +336,7 @@ void MediaWindowImpl::executeMediaItem( const MediaItem& rItem )
if (nMaskSet & AVMediaSetMask::URL)
{
m_sMimeType = rItem.getMimeType();
setFallbackURL(rItem.getFallbackURL());
setURL(rItem.getURL(), rItem.getTempURL(), rItem.getReferer());
}

View file

@ -87,6 +87,9 @@ public:
const OUString& getURL() const;
void setFallbackURL(const OUString& rURL);
const OUString& getFallbackURL() const;
bool isValid() const;
Size getPreferredSize() const;
@ -139,6 +142,7 @@ private:
OUString maFileURL;
OUString mTempFileURL;
OUString maFallbackFileURL;
OUString maReferer;
OUString m_sMimeType;
css::uno::Reference<css::media::XPlayer> mxPlayer;

View file

@ -117,6 +117,9 @@ public:
const OUString& rReferer);
const OUString& getURL() const;
bool setFallbackURL(const OUString& rURL);
const OUString& getFallbackURL() const;
bool setMimeType(const OUString& rMimeType);
OUString getMimeType() const;
bool setGraphic(const Graphic& rGraphic);

View file

@ -400,6 +400,7 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper
{
m_xImpl->m_xCachedSnapshot.clear();
m_xImpl->m_xPlayerListener.clear();
m_xImpl->m_MediaProperties.setFallbackURL( rNewProperties.getFallbackURL() );
OUString const& url(rNewProperties.getURL());
if (url.startsWithIgnoreAsciiCase("vnd.sun.star.Package:"))
{

View file

@ -823,6 +823,18 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
if( rValue >>= aURL )
{
bOk = true;
if ( aURL.startsWith("file:///") && !comphelper::DirectoryHelper::fileExists(aURL) )
{
comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
auto fileDirectoryEndIdx = pPersist->getDocumentBaseURL().lastIndexOf("/");
auto fileNameStartIdx = aURL.lastIndexOf("/");
if (fileDirectoryEndIdx != -1 && fileNameStartIdx != -1)
{
OUString aFallbackURL = OUString::Concat(pPersist->getDocumentBaseURL().subView(0, fileDirectoryEndIdx + 1))
+ aURL.subView(fileNameStartIdx + 1);
aItem.setFallbackURL(aFallbackURL);
}
}
aItem.setURL( aURL, u""_ustr, referer_ );
}
}