Skip to content

Commit 150ee6e

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 42970b8 commit 150ee6e

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
@@ -485,7 +485,7 @@ static QStringList BuildFileList(const QString &dir, const QStringList &filters)
485485
return ret;
486486
}
487487

488-
static void handleMedia(MythMediaDevice *cd)
488+
static void handleMedia(MythMediaDevice *cd, bool forcePlayback)
489489
{
490490
static QString s_mountPath;
491491

@@ -526,7 +526,7 @@ static void handleMedia(MythMediaDevice *cd)
526526
s_mountPath.clear();
527527

528528
// don't show the music screen if AutoPlayCD is off
529-
if (!gCoreContext->GetBoolSetting("AutoPlayCD", false))
529+
if (!forcePlayback && !gCoreContext->GetBoolSetting("AutoPlayCD", false))
530530
return;
531531

532532
if (!gMusicData->m_initialized)
@@ -631,7 +631,7 @@ static void handleMedia(MythMediaDevice *cd)
631631
}
632632

633633
#ifdef HAVE_CDIO
634-
static void handleCDMedia(MythMediaDevice *cd)
634+
static void handleCDMedia(MythMediaDevice *cd, bool forcePlayback)
635635
{
636636

637637
if (!cd)
@@ -743,7 +743,7 @@ static void handleCDMedia(MythMediaDevice *cd)
743743

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

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

mythtv/libs/libmythui/mediamonitor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,13 @@ QList<MythMediaDevice*> MediaMonitor::GetMedias(unsigned mediatypes)
631631
* \param description Unused.
632632
* \param callback The function to call when an event occurs.
633633
* \param mediaType The type of media supported by this callback. The
634-
* value must be an enum of type MythMediaType.
634+
* value must be a bitmask of enums of type MythMediaType.
635635
* \param extensions A list of file name extensions supported by this
636636
* callback.
637637
*/
638638
void MediaMonitor::RegisterMediaHandler(const QString &destination,
639639
const QString &description,
640-
void (*callback)
641-
(MythMediaDevice*),
640+
MediaCallback callback,
642641
int mediaType,
643642
const QString &extensions)
644643
{
@@ -673,7 +672,7 @@ void MediaMonitor::RegisterMediaHandler(const QString &destination,
673672
* to allow the user to select which one to use,
674673
* but for now, we're going to just use the first one.
675674
*/
676-
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
675+
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback)
677676
{
678677
QVector<MHData> handlers;
679678
QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
@@ -701,7 +700,7 @@ void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
701700
// if user didn't cancel, selected = handlers.at(choice);
702701
int selected = 0;
703702

704-
handlers.at(selected).callback(pMedia);
703+
handlers.at(selected).callback(pMedia, forcePlayback);
705704
}
706705

707706
/**
@@ -817,7 +816,7 @@ bool MediaMonitor::eventFilter(QObject *obj, QEvent *event)
817816
{
818817
if ((*itr).MythMediaType & (int)pDev->getMediaType() ||
819818
pDev->getStatus() == MEDIASTAT_OPEN)
820-
(*itr).callback(pDev);
819+
(*itr).callback(pDev, false);
821820
itr++;
822821
}
823822
}

mythtv/libs/libmythui/mediamonitor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
#include "libmythbase/mythmedia.h"
1313
#include "libmythui/mythuiexp.h"
1414

15+
typedef void (*MediaCallback)(MythMediaDevice *mediadevice, bool forcePlayback);
16+
1517
/// Stores details of media handlers
1618

1719
// Adding member initializers caused compilation to fail with an error
1820
// that it cannot convert a brace-enclosed initializer list to MHData.
1921
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
2022
struct MHData
2123
{
22-
void (*callback)(MythMediaDevice *mediadevice);
24+
MediaCallback callback;
2325
int MythMediaType;
2426
QString destination;
2527
QString description;
@@ -74,10 +76,10 @@ class MUI_PUBLIC MediaMonitor : public QObject
7476

7577
void RegisterMediaHandler(const QString &destination,
7678
const QString &description,
77-
void (*callback) (MythMediaDevice*),
79+
MediaCallback callback,
7880
int mediaType,
7981
const QString &extensions);
80-
void JumpToMediaHandler(MythMediaDevice* pMedia);
82+
void JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback = false);
8183

8284
// Plugins should use these if they need to access optical disks:
8385
static QString defaultCDdevice();
@@ -137,7 +139,7 @@ class MUI_PUBLIC MediaMonitor : public QObject
137139
static inline void
138140
REG_MEDIA_HANDLER (const QString& destination,
139141
const QString& description,
140-
void (*callback)(MythMediaDevice*),
142+
MediaCallback callback,
141143
int mediaType,
142144
const QString& extensions)
143145
{

mythtv/programs/mythfrontend/mythfrontend.cpp

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

788788
static void playDisc()
789789
{
790-
//
791-
// Get the command string to play a DVD
792-
//
793-
794-
bool isBD = false;
795-
796-
QString command_string =
797-
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
790+
// Check for Bluray
791+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for BluRay medium");
798792
QString bluray_mountpoint =
799793
gCoreContext->GetSetting("BluRayMountpoint", "/media/cdrom");
800794
QDir bdtest(bluray_mountpoint + "/BDMV");
801-
802-
if (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray)
803-
isBD = true;
804-
795+
const bool isBD = (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray);
805796
if (isBD)
806797
{
807798
GetMythUI()->AddCurrentLocation("playdisc");
@@ -812,8 +803,19 @@ static void playDisc()
812803
0, 0, "", 0min, "", "", true);
813804

814805
GetMythUI()->RemoveCurrentLocation();
806+
return;
815807
}
816-
else
808+
809+
MediaMonitor *mediaMonitor = MediaMonitor::GetMediaMonitor();
810+
if (!mediaMonitor)
811+
{
812+
LOG(VB_MEDIA, LOG_ERR, "Could not access media monitor");
813+
return;
814+
}
815+
816+
// Check for DVD
817+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for DVD medium");
818+
if (!mediaMonitor->GetMedias(MEDIATYPE_DVD).isEmpty())
817819
{
818820
QString dvd_device = MediaMonitor::defaultDVDdevice();
819821

@@ -822,6 +824,9 @@ static void playDisc()
822824

823825
GetMythUI()->AddCurrentLocation("playdisc");
824826

827+
// Get the command string to play a DVD
828+
QString command_string =
829+
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
825830
if ((command_string.indexOf("internal", 0, Qt::CaseInsensitive) > -1) ||
826831
(command_string.length() < 1))
827832
{
@@ -837,7 +842,7 @@ static void playDisc()
837842

838843
command_string = "Internal";
839844
GetMythMainWindow()->HandleMedia(command_string, filename, "", "",
840-
"", "", 0, 0, "", 0min, "", "", true);
845+
"", "", 0, 0, "", 0min, "", "", true);
841846
GetMythUI()->RemoveCurrentLocation();
842847

843848
return;
@@ -861,13 +866,30 @@ static void playDisc()
861866
GetMythMainWindow()->activateWindow();
862867
}
863868
GetMythUI()->RemoveCurrentLocation();
869+
return;
864870
}
871+
872+
// Check for Audio CD
873+
LOG(VB_MEDIA, LOG_DEBUG, "Checking for audio CD medium");
874+
auto audioMedia = mediaMonitor->GetMedias(MEDIATYPE_AUDIO | MEDIATYPE_MIXED);
875+
if (!audioMedia.isEmpty())
876+
{
877+
for (auto *medium : qAsConst(audioMedia))
878+
{
879+
if (medium->isUsable()) {
880+
LOG(VB_MEDIA, LOG_DEBUG, QString("Found usable audio/mixed device %1").arg(medium->getDevicePath()));
881+
mediaMonitor->JumpToMediaHandler(medium, true);
882+
return;
883+
}
884+
}
885+
}
886+
865887
}
866888

867889
/////////////////////////////////////////////////
868890
//// Media handlers
869891
/////////////////////////////////////////////////
870-
static void handleDVDMedia(MythMediaDevice *dvd)
892+
static void handleDVDMedia(MythMediaDevice *dvd, bool /*forcePlayback*/)
871893
{
872894
if (!dvd)
873895
return;
@@ -889,7 +911,7 @@ static void handleDVDMedia(MythMediaDevice *dvd)
889911
}
890912
}
891913

892-
static void handleGalleryMedia(MythMediaDevice *dev)
914+
static void handleGalleryMedia(MythMediaDevice *dev, bool forcePlayback)
893915
{
894916
// Only handle events for media that are newly mounted
895917
if (!dev || (dev->getStatus() != MEDIASTAT_MOUNTED
@@ -911,7 +933,7 @@ static void handleGalleryMedia(MythMediaDevice *dev)
911933
}
912934
}
913935

914-
if (gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
936+
if (forcePlayback || gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
915937
{
916938
LOG(VB_GUI, LOG_INFO, "Main: Autostarting Gallery for new media");
917939
GetMythMainWindow()->JumpTo(JUMP_GALLERY_DEFAULT);

0 commit comments

Comments
 (0)