Skip to content

Commit

Permalink
MythMusic: allow the music player to be controlled by sending it Myth…
Browse files Browse the repository at this point in the history
…Events.

Currently you can start, stop and pause the player, get/set the volume, play a
file, url or track id and get the metadata of the currently playing track.
Other commands will be added as they are needed.

Shortly I will add some code to the web browser widget that will allow the
music player to be controlled using JavaScript.

It would be trivial to update the network control to allow the player to be
controlled using that as well if anyone is interested.
  • Loading branch information
Paul Harrison authored and jyavenard committed Dec 14, 2010
1 parent ed93781 commit 117457e
Showing 1 changed file with 84 additions and 2 deletions.
86 changes: 84 additions & 2 deletions mythplugins/mythmusic/mythmusic/musicplayer.cpp
Expand Up @@ -468,8 +468,7 @@ void MusicPlayer::customEvent(QEvent *event)
stop(true);
}
}

if (me->Message().left(12) == "PLAYBACK_END")
else if (me->Message().left(12) == "PLAYBACK_END")
{
if (m_wasPlaying)
{
Expand All @@ -486,6 +485,89 @@ void MusicPlayer::customEvent(QEvent *event)
m_wasPlaying = false;
}
}
else if (me->Message().left(13) == "MUSIC_COMMAND")
{
QStringList list = me->Message().split(' ');

if (list.size() >= 2)
{
if (list[1] == "PLAY")
play();
else if (list[1] == "STOP")
stop();
else if (list[1] == "PAUSE")
pause();
else if (list[1] == "SET_VOLUME")
{
if (list.size() >= 3)
{
int volume = list[2].toInt();
if (volume >= 0 && volume <= 100)
setVolume(volume);
}
}
else if (list[1] == "GET_VOLUME")
{
QString message = QString("MUSIC_CONTROL ANSWER %1").arg(getVolume());
MythEvent me(message);
gCoreContext->dispatch(me);
}
else if (list[1] == "PLAY_FILE")
{
int start = me->Message().indexOf("'");
int end = me->Message().lastIndexOf("'");

if (start != -1 && end != -1 && start != end)
{
QString filename = me->Message().mid(start + 1, end - start - 1);
Metadata mdata;
mdata.setFilename(filename);
playFile(mdata);
}
else
VERBOSE(VB_IMPORTANT, QString("MusicPlayer: got invalid MUSIC_COMMAND PLAY_FILE - %1").arg(me->Message()));
}
else if (list[1] == "PLAY_URL")
{
if (list.size() == 3)
{
QString filename = list[2];
Metadata mdata;
mdata.setFilename(filename);
playFile(mdata);
}
else
VERBOSE(VB_IMPORTANT, QString("MusicPlayer: got invalid MUSIC_COMMAND PLAY_URL - %1").arg(me->Message()));
}
else if (list[1] == "PLAY_TRACK")
{
if (list.size() == 3)
{
int trackID = list[2].toInt();
Metadata *mdata = gMusicData->all_music->getMetadata(trackID);
if (mdata)
playFile(*mdata);
}
else
VERBOSE(VB_IMPORTANT, QString("MusicPlayer: got invalid MUSIC_COMMAND PLAY_TRACK - %1").arg(me->Message()));
}
else if (list[1] == "GET_METADATA")
{
QString mdataStr;
Metadata *mdata = getCurrentMetadata();
if (mdata)
mdataStr = QString("%1 by %2 from %3").arg(mdata->Title()).arg(mdata->Artist()).arg(mdata->Album());
else
mdataStr = "Unknown Track";

QString message = QString("MUSIC_CONTROL ANSWER %1").arg(mdataStr);
MythEvent me(message);
gCoreContext->dispatch(me);
}
}
else
VERBOSE(VB_IMPORTANT, QString("MusicPlayer: got unknown/invalid MUSIC_COMMAND - %1").arg(me->Message()));
}
}

if (m_isAutoplay)
Expand Down

0 comments on commit 117457e

Please sign in to comment.