mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
278e05cbf3
External and internal audio players work similarly now. Fixes #950. * inherit a new ExternalAudioPlayer class from AudioPlayerInterface; * use an existing ExternalViewer class to implement ExternalAudioPlayer; * take (const char *, int) instead of std::vector<char> in ExternalViewer constructor to fit into AudioPlayerInterface; * extend ExternalViewer API to let ExternalAudioPlayer stop superseded audio player processes; * make AudioPlayerInterface::play() return an error message string to allow reporting immediate failures from derived classes; * Document AudioPlayerInterface API; * Document AudioPlayerFactory::player(); * use the common audio interface exclusively in ArticleView.
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
/* This file is (c) 2018 Igor Kushnir <igorkuo@gmail.com>
|
|
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
|
|
|
#ifndef EXTERNALAUDIOPLAYER_HH_INCLUDED
|
|
#define EXTERNALAUDIOPLAYER_HH_INCLUDED
|
|
|
|
#include <QScopedPointer>
|
|
#include <QString>
|
|
#include "audioplayerinterface.hh"
|
|
|
|
class ExternalViewer;
|
|
|
|
class ExternalAudioPlayer : public AudioPlayerInterface
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
ExternalAudioPlayer();
|
|
~ExternalAudioPlayer();
|
|
/// \param playerCommandLine_ Will be used in future play() calls.
|
|
void setPlayerCommandLine( QString const & playerCommandLine_ );
|
|
|
|
virtual QString play( const char * data, int size );
|
|
virtual void stop();
|
|
|
|
private slots:
|
|
void onViewerDestroyed( QObject * destroyedViewer );
|
|
|
|
private:
|
|
QString startViewer();
|
|
|
|
QString playerCommandLine;
|
|
ExternalViewer * exitingViewer; ///< If not null: points to the previous viewer,
|
|
///< the current viewer (if any) is not started yet
|
|
///< and waits for exitingViewer to be destroyed first.
|
|
|
|
struct ScopedPointerDeleteLater
|
|
{
|
|
static void cleanup( QObject * p ) { if( p ) p->deleteLater(); }
|
|
};
|
|
// deleteLater() is safer because viewer actively participates in the QEventLoop.
|
|
QScopedPointer< ExternalViewer, ScopedPointerDeleteLater > viewer;
|
|
};
|
|
|
|
#endif // EXTERNALAUDIOPLAYER_HH_INCLUDED
|