Skip to content

Commit

Permalink
MythMusic: Check the audio output was opened without error before usi…
Browse files Browse the repository at this point in the history
…ng it.

Fixes #9403.
  • Loading branch information
Paul Harrison committed Jul 27, 2011
1 parent 6e3b759 commit 750bdf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions mythplugins/mythmusic/mythmusic/musicplayer.cpp
Expand Up @@ -271,7 +271,10 @@ void MusicPlayer::play(void)


if (!m_output)
openOutputDevice();
{
if (!openOutputDevice())
return;
}

if (!getDecoderHandler())
setupDecoderHandler();
Expand All @@ -297,7 +300,7 @@ void MusicPlayer::stopDecoder(void)
m_currentMetadata = NULL;
}

void MusicPlayer::openOutputDevice(void)
bool MusicPlayer::openOutputDevice(void)
{
QString adevice, pdevice;

Expand All @@ -309,12 +312,32 @@ void MusicPlayer::openOutputDevice(void)
pdevice = gCoreContext->GetNumSetting("PassThruDeviceOverride", false) ?
gCoreContext->GetSetting("PassThruOutputDevice") : "auto";

// TODO: Error checking that device is opened correctly!
m_output = AudioOutput::OpenAudio(
adevice, pdevice, FORMAT_S16, 2, 0, 44100,
AUDIOOUTPUT_MUSIC, true, false,
gCoreContext->GetNumSetting("MusicDefaultUpmix", 0) + 1);

if (!m_output)
{
LOG(VB_GENERAL, LOG_ERR,
QString("MusicPlayer: Cannot open audio output device: %1").arg(adevice));

return false;
}

if (!m_output->GetError().isEmpty())
{
LOG(VB_GENERAL, LOG_ERR,
QString("MusicPlayer: Cannot open audio output device: %1").arg(adevice));
LOG(VB_GENERAL, LOG_ERR,
QString("Error was: %1").arg(m_output->GetError()));

delete m_output;
m_output = NULL;

return false;
}

m_output->setBufferSize(256 * 1024);

m_output->addListener(this);
Expand All @@ -333,6 +356,8 @@ void MusicPlayer::openOutputDevice(void)
{
m_output->addListener(*it);
}

return true;
}

void MusicPlayer::next(void)
Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythmusic/mythmusic/musicplayer.h
Expand Up @@ -167,7 +167,7 @@ class MusicPlayer : public QObject, public MythObservable

private:
void stopDecoder(void);
void openOutputDevice(void);
bool openOutputDevice(void);
QString getFilenameFromID(int id);
void updateLastplay(void);
void sendVolumeChangedEvent(void);
Expand Down

0 comments on commit 750bdf1

Please sign in to comment.