File indexing completed on 2024-04-28 03:50:23
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2011 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #include "AudioOutput.h" 0007 0008 #include "MarbleDirs.h" 0009 #include "MarbleDebug.h" 0010 #include "routing/VoiceNavigationModel.h" 0011 #include "routing/Route.h" 0012 0013 #include <QUrl> 0014 #include <phonon/MediaObject> 0015 #include <phonon/MediaSource> 0016 #include <phonon/AudioOutput> 0017 0018 namespace Marble 0019 { 0020 0021 class AudioOutputPrivate 0022 { 0023 public: 0024 AudioOutput *q; 0025 0026 Phonon::MediaObject *m_output; 0027 0028 bool m_muted; 0029 0030 VoiceNavigationModel m_voiceNavigation; 0031 0032 AudioOutputPrivate( AudioOutput* parent ); 0033 0034 void audioOutputFinished(); 0035 0036 void setupAudio(); 0037 0038 void reset(); 0039 0040 void playInstructions(); 0041 }; 0042 0043 AudioOutputPrivate::AudioOutputPrivate( AudioOutput* parent ) : 0044 q( parent ), m_output( nullptr ), m_muted( false ) 0045 { 0046 QObject::connect( &m_voiceNavigation, SIGNAL(instructionChanged()), 0047 q, SLOT(playInstructions()) ); 0048 } 0049 0050 void AudioOutputPrivate::audioOutputFinished() 0051 { 0052 m_output->setCurrentSource( Phonon::MediaSource() ); 0053 m_output->clearQueue(); 0054 } 0055 0056 void AudioOutputPrivate::setupAudio() 0057 { 0058 if ( !m_output ) { 0059 m_output = new Phonon::MediaObject( q ); 0060 Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput( Phonon::VideoCategory, q ); 0061 Phonon::createPath( m_output, audioOutput ); 0062 0063 q->connect( m_output, SIGNAL(finished()), q, SLOT(audioOutputFinished()) ); 0064 } 0065 } 0066 0067 void AudioOutputPrivate::reset() 0068 { 0069 if ( m_output ) { 0070 m_output->stop(); 0071 m_output->setCurrentSource( Phonon::MediaSource() ); 0072 m_output->clearQueue(); 0073 } 0074 0075 m_voiceNavigation.reset(); 0076 } 0077 0078 void AudioOutputPrivate::playInstructions() 0079 { 0080 setupAudio(); 0081 if ( m_output ) { 0082 m_output->enqueue( QUrl::fromLocalFile( m_voiceNavigation.instruction() ) ); 0083 m_output->play(); 0084 } 0085 } 0086 0087 AudioOutput::AudioOutput( QObject* parent ) : QObject( parent ), 0088 d( new AudioOutputPrivate( this ) ) 0089 { 0090 setSoundEnabled( false ); 0091 } 0092 0093 AudioOutput::~AudioOutput() 0094 { 0095 delete d; 0096 } 0097 0098 void AudioOutput::update(const Route &route, qreal distanceManeuver, qreal distanceTarget, bool deviated ) 0099 { 0100 d->m_voiceNavigation.update( route, distanceManeuver, distanceTarget, deviated ); 0101 } 0102 0103 void AudioOutput::setMuted( bool muted ) 0104 { 0105 d->m_muted = muted; 0106 } 0107 0108 bool AudioOutput::isMuted() const 0109 { 0110 return d->m_muted; 0111 } 0112 0113 void AudioOutput::setSpeaker( const QString &speaker ) 0114 { 0115 d->m_voiceNavigation.setSpeaker( speaker ); 0116 } 0117 0118 QString AudioOutput::speaker() const 0119 { 0120 return d->m_voiceNavigation.speaker(); 0121 } 0122 0123 void AudioOutput::setSoundEnabled( bool enabled ) 0124 { 0125 d->m_voiceNavigation.setSpeakerEnabled( !enabled ); 0126 } 0127 0128 bool AudioOutput::isSoundEnabled() const 0129 { 0130 return !d->m_voiceNavigation.isSpeakerEnabled(); 0131 } 0132 0133 } 0134 0135 #include "moc_AudioOutput.cpp"