Skip to content

Commit f10251a

Browse files
committed
Support playing Audio CD from menu
Add support to play an audio CD from the 'Play Optical Disc' menu. The media monitor callback function was extended by a 'forcePlayback' parameter which will override the auto play option for some of the media handlers when started explicitly by the user via the menu.
1 parent 62ad21b commit f10251a

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

mythplugins/mythmusic/mythmusic/mythmusic.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static QStringList BuildFileList(const QString &dir, const QStringList &filters)
481481
return ret;
482482
}
483483

484-
static void handleMedia(MythMediaDevice *cd)
484+
static void handleMedia(MythMediaDevice *cd, bool forcePlayback)
485485
{
486486
static QString s_mountPath;
487487

@@ -522,7 +522,7 @@ static void handleMedia(MythMediaDevice *cd)
522522
s_mountPath.clear();
523523

524524
// don't show the music screen if AutoPlayCD is off
525-
if (!gCoreContext->GetBoolSetting("AutoPlayCD", false))
525+
if (!forcePlayback && !gCoreContext->GetBoolSetting("AutoPlayCD", false))
526526
return;
527527

528528
if (!gMusicData->m_initialized)
@@ -627,7 +627,7 @@ static void handleMedia(MythMediaDevice *cd)
627627
}
628628

629629
#ifdef HAVE_CDIO
630-
static void handleCDMedia(MythMediaDevice *cd)
630+
static void handleCDMedia(MythMediaDevice *cd, bool forcePlayback)
631631
{
632632

633633
if (!cd)
@@ -739,7 +739,7 @@ static void handleCDMedia(MythMediaDevice *cd)
739739

740740
// if the AutoPlayCD setting is set we remove all the existing tracks
741741
// from the playlist and replace them with the new CD tracks found
742-
if (gCoreContext->GetBoolSetting("AutoPlayCD", false))
742+
if (forcePlayback || gCoreContext->GetBoolSetting("AutoPlayCD", false))
743743
{
744744
gMusicData->m_all_playlists->getActive()->removeAllTracks();
745745

@@ -776,7 +776,7 @@ static void handleCDMedia(MythMediaDevice *cd)
776776
}
777777
}
778778
#else
779-
static void handleCDMedia([[maybe_unused]] MythMediaDevice *cd)
779+
static void handleCDMedia([[maybe_unused]] MythMediaDevice *cd, [[maybe_unused]] bool forcePlayback)
780780
{
781781
LOG(VB_GENERAL, LOG_NOTICE, "MythMusic got a media changed event"
782782
"but cdio support is not compiled in");

mythtv/libs/libmyth/mythmediamonitor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,14 +635,13 @@ QList<MythMediaDevice*> MediaMonitor::GetMedias(unsigned mediatypes)
635635
* \param description Unused.
636636
* \param callback The function to call when an event occurs.
637637
* \param mediaType The type of media supported by this callback. The
638-
* value must be an enum of type MythMediaType.
638+
* value must be a bitmask of enums of type MythMediaType.
639639
* \param extensions A list of file name extensions supported by this
640640
* callback.
641641
*/
642642
void MediaMonitor::RegisterMediaHandler(const QString &destination,
643643
const QString &description,
644-
void (*callback)
645-
(MythMediaDevice*),
644+
MediaCallback callback,
646645
int mediaType,
647646
const QString &extensions)
648647
{
@@ -677,7 +676,7 @@ void MediaMonitor::RegisterMediaHandler(const QString &destination,
677676
* to allow the user to select which one to use,
678677
* but for now, we're going to just use the first one.
679678
*/
680-
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
679+
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback)
681680
{
682681
QVector<MHData> handlers;
683682
QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
@@ -705,7 +704,7 @@ void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
705704
// if user didn't cancel, selected = handlers.at(choice);
706705
int selected = 0;
707706

708-
handlers.at(selected).callback(pMedia);
707+
handlers.at(selected).callback(pMedia, forcePlayback);
709708
}
710709

711710
/**
@@ -819,7 +818,7 @@ bool MediaMonitor::eventFilter(QObject *obj, QEvent *event)
819818
{
820819
if ((*itr).MythMediaType & (int)pDev->getMediaType() ||
821820
pDev->getStatus() == MEDIASTAT_OPEN)
822-
(*itr).callback(pDev);
821+
(*itr).callback(pDev, false);
823822
itr++;
824823
}
825824
}

mythtv/libs/libmyth/mythmediamonitor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
#include "libmythbase/mthread.h"
1717
#include "libmythbase/mythmedia.h"
1818

19+
typedef void (*MediaCallback)(MythMediaDevice *mediadevice, bool forcePlayback);
20+
1921
/// Stores details of media handlers
2022

2123
// Adding member initializers caused compilation to fail with an error
2224
// that it cannot convert a brace-enclosed initializer list to MHData.
2325
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
2426
struct MHData
2527
{
26-
void (*callback)(MythMediaDevice *mediadevice);
28+
MediaCallback callback;
2729
int MythMediaType;
2830
QString destination;
2931
QString description;
@@ -78,10 +80,10 @@ class MPUBLIC MediaMonitor : public QObject
7880

7981
void RegisterMediaHandler(const QString &destination,
8082
const QString &description,
81-
void (*callback) (MythMediaDevice*),
83+
MediaCallback callback,
8284
int mediaType,
8385
const QString &extensions);
84-
void JumpToMediaHandler(MythMediaDevice* pMedia);
86+
void JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback = false);
8587

8688
// Plugins should use these if they need to access optical disks:
8789
static QString defaultCDdevice();
@@ -145,7 +147,7 @@ class MPUBLIC MediaMonitor : public QObject
145147
static inline void
146148
REG_MEDIA_HANDLER (const QString& destination,
147149
const QString& description,
148-
void (*callback)(MythMediaDevice*),
150+
MediaCallback callback,
149151
int mediaType,
150152
const QString& extensions)
151153
{

mythtv/programs/mythfrontend/mythfrontend.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -780,21 +780,12 @@ static void RunGallery()
780780

781781
static void playDisc()
782782
{
783-
//
784-
// Get the command string to play a DVD
785-
//
786-
787-
bool isBD = false;
788-
789-
QString command_string =
790-
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
783+
// Check for Bluray
784+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for BluRay medium");
791785
QString bluray_mountpoint =
792786
gCoreContext->GetSetting("BluRayMountpoint", "/media/cdrom");
793787
QDir bdtest(bluray_mountpoint + "/BDMV");
794-
795-
if (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray)
796-
isBD = true;
797-
788+
const bool isBD = (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray);
798789
if (isBD)
799790
{
800791
GetMythUI()->AddCurrentLocation("playdisc");
@@ -805,8 +796,19 @@ static void playDisc()
805796
0, 0, "", 0min, "", "", true);
806797

807798
GetMythUI()->RemoveCurrentLocation();
799+
return;
808800
}
809-
else
801+
802+
MediaMonitor *mediaMonitor = MediaMonitor::GetMediaMonitor();
803+
if (!mediaMonitor)
804+
{
805+
LOG(VB_MEDIA, LOG_ERR, "Could not access media monitor");
806+
return;
807+
}
808+
809+
// Check for DVD
810+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for DVD medium");
811+
if (!mediaMonitor->GetMedias(MEDIATYPE_DVD).isEmpty())
810812
{
811813
QString dvd_device = MediaMonitor::defaultDVDdevice();
812814

@@ -815,6 +817,9 @@ static void playDisc()
815817

816818
GetMythUI()->AddCurrentLocation("playdisc");
817819

820+
// Get the command string to play a DVD
821+
QString command_string =
822+
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
818823
if ((command_string.indexOf("internal", 0, Qt::CaseInsensitive) > -1) ||
819824
(command_string.length() < 1))
820825
{
@@ -830,7 +835,7 @@ static void playDisc()
830835

831836
command_string = "Internal";
832837
GetMythMainWindow()->HandleMedia(command_string, filename, "", "",
833-
"", "", 0, 0, "", 0min, "", "", true);
838+
"", "", 0, 0, "", 0min, "", "", true);
834839
GetMythUI()->RemoveCurrentLocation();
835840

836841
return;
@@ -854,13 +859,30 @@ static void playDisc()
854859
GetMythMainWindow()->activateWindow();
855860
}
856861
GetMythUI()->RemoveCurrentLocation();
862+
return;
857863
}
864+
865+
// Check for Audio CD
866+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for audio CD medium");
867+
auto audioMedia = mediaMonitor->GetMedias(MEDIATYPE_AUDIO | MEDIATYPE_MIXED);
868+
if (!audioMedia.isEmpty())
869+
{
870+
for (auto *medium : qAsConst(audioMedia))
871+
{
872+
if (medium->isUsable()) {
873+
LOG(VB_MEDIA, LOG_DEBUG, QString("Found usable audio/mixed device %1").arg(medium->getDevicePath()));
874+
mediaMonitor->JumpToMediaHandler(medium, true);
875+
return;
876+
}
877+
}
878+
}
879+
858880
}
859881

860882
/////////////////////////////////////////////////
861883
//// Media handlers
862884
/////////////////////////////////////////////////
863-
static void handleDVDMedia(MythMediaDevice *dvd)
885+
static void handleDVDMedia(MythMediaDevice *dvd, bool /*forcePlayback*/)
864886
{
865887
if (!dvd)
866888
return;
@@ -882,7 +904,7 @@ static void handleDVDMedia(MythMediaDevice *dvd)
882904
}
883905
}
884906

885-
static void handleGalleryMedia(MythMediaDevice *dev)
907+
static void handleGalleryMedia(MythMediaDevice *dev, bool forcePlayback)
886908
{
887909
// Only handle events for media that are newly mounted
888910
if (!dev || (dev->getStatus() != MEDIASTAT_MOUNTED
@@ -904,7 +926,7 @@ static void handleGalleryMedia(MythMediaDevice *dev)
904926
}
905927
}
906928

907-
if (gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
929+
if (forcePlayback || gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
908930
{
909931
LOG(VB_GUI, LOG_INFO, "Main: Autostarting Gallery for new media");
910932
GetMythMainWindow()->JumpTo(JUMP_GALLERY_DEFAULT);

0 commit comments

Comments
 (0)