17 #include "soundplayer.h"
18 #include <QMediaPlayer>
21 #include "soundclip.h"
23 SoundPlayer::SoundPlayer( )
28 SoundPlayer::~SoundPlayer()
34 Q_ASSERT( clip !=
nullptr );
37 mMediaPlayer =
new QMediaPlayer(
this );
39 QFile file(clip->fileName());
42 buffer->
setData(file.readAll());
48 clip->attachPlayer(
this );
51 qDebug() <<
"Seekable = " << mMediaPlayer->isSeekable();
54 void SoundPlayer::onKeyFrameDestroy(
KeyFrame* keyFrame )
59 bool SoundPlayer::isValid()
63 return ( mMediaPlayer->error() == QMediaPlayer::NoError );
68 void SoundPlayer::play()
76 void SoundPlayer::pause()
80 mMediaPlayer->pause();
84 void SoundPlayer::stop()
92 int64_t SoundPlayer::duration()
96 return mMediaPlayer->duration();
101 void SoundPlayer::setMediaPlayerPosition(qint64 pos)
105 mMediaPlayer->setPosition(pos);
109 void SoundPlayer::makeConnections()
111 auto errorSignal =
static_cast< void ( QMediaPlayer::* )( QMediaPlayer::Error )
>( &QMediaPlayer::error );
112 connect( mMediaPlayer, errorSignal,
this, []( QMediaPlayer::Error err )
114 qDebug() <<
"MediaPlayer Error: " << err;
117 connect( mMediaPlayer, &QMediaPlayer::durationChanged, [
this ]( qint64 duration )
119 qDebug() <<
"MediaPlayer durationChanged :" << duration;
120 emit durationChanged(
this, duration );
void setData(const QByteArray &data)
virtual bool open(QIODevice::OpenMode flags) override
virtual bool open(QIODevice::OpenMode mode) override
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QUrl fromLocalFile(const QString &localFile)