Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update MythMusic use playback registration API
Following 5201ed1, MythMusic lost the ability to stop / resume music playback when TV/video playback starts. This restore this functionality. Also now compatible with AirPlay
  • Loading branch information
jyavenard committed Jul 14, 2013
1 parent 14c3a84 commit c167ae4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
59 changes: 29 additions & 30 deletions mythplugins/mythmusic/mythmusic/musicplayer.cpp
Expand Up @@ -102,6 +102,9 @@ MusicPlayer::MusicPlayer(QObject *parent)
loadSettings();

gCoreContext->addListener(this);
gCoreContext->RegisterForPlayback(this, SLOT(StopPlayback()));
connect(gCoreContext, SIGNAL(TVPlaybackStopped()), this, SLOT(StartPlayback()));
connect(gCoreContext, SIGNAL(TVPlaybackAborted()), this, SLOT(StartPlayback()));
}

MusicPlayer::~MusicPlayer()
Expand All @@ -110,6 +113,7 @@ MusicPlayer::~MusicPlayer()
savePosition();

gCoreContext->removeListener(this);
gCoreContext->UnregisterForPlayback(this);

stop(true);

Expand Down Expand Up @@ -502,6 +506,30 @@ void MusicPlayer::nextAuto(void)
}
}

void MusicPlayer::StartPlayback(void)
{
if (!gCoreContext->InWantingPlayback() && m_wasPlaying)
{
play();
seek(gCoreContext->GetNumSetting("MusicBookmarkPosition", 0));
gCoreContext->SaveSetting("MusicBookmark", "");
gCoreContext->SaveSetting("MusicBookmarkPosition", 0);

m_wasPlaying = false;
}
}

void MusicPlayer::StopPlayback(void)
{
if (m_isPlaying)
{
m_wasPlaying = m_isPlaying;

savePosition();
stop(true);
}
}

void MusicPlayer::customEvent(QEvent *event)
{
// handle decoderHandler events
Expand Down Expand Up @@ -552,36 +580,7 @@ void MusicPlayer::customEvent(QEvent *event)
if (!me)
return;

if (me->Message().left(14) == "PLAYBACK_START")
{
m_wasPlaying = m_isPlaying;
QString hostname = me->Message().mid(15);

if (hostname == gCoreContext->GetHostName())
{
if (m_isPlaying)
savePosition();
stop(true);
}
}
else if (me->Message().left(12) == "PLAYBACK_END")
{
if (m_wasPlaying)
{
QString hostname = me->Message().mid(13);
if (hostname == gCoreContext->GetHostName())
{
play();
seek(gCoreContext->GetNumSetting(
"MusicBookmarkPosition", 0));
gCoreContext->SaveSetting("MusicBookmark", "");
gCoreContext->SaveSetting("MusicBookmarkPosition", 0);
}

m_wasPlaying = false;
}
}
else if (me->Message().left(13) == "MUSIC_COMMAND")
if (me->Message().left(13) == "MUSIC_COMMAND")
{
QStringList list = me->Message().simplified().split(' ');

Expand Down
4 changes: 4 additions & 0 deletions mythplugins/mythmusic/mythmusic/musicplayer.h
Expand Up @@ -180,6 +180,10 @@ class MusicPlayer : public QObject, public MythObservable

void getBufferStatus(int *bufferAvailable, int *bufferSize);

public slots:
void StartPlayback(void);
void StopPlayback(void);

protected:
void customEvent(QEvent *event);

Expand Down

0 comments on commit c167ae4

Please sign in to comment.