Commit 94665113 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): add a `SoundPlayer` component

parent 4078767c
......@@ -114,6 +114,7 @@ set(SOURCES
src/components/sip-addresses/SipAddressesModel.cpp
src/components/sip-addresses/SipAddressObserver.cpp
src/components/smart-search-bar/SmartSearchBarModel.cpp
src/components/sound-player/SoundPlayer.cpp
src/components/timeline/TimelineModel.cpp
src/externals/single-application/SingleApplication.cpp
src/main.cpp
......@@ -154,6 +155,7 @@ set(HEADERS
src/components/sip-addresses/SipAddressesModel.hpp
src/components/sip-addresses/SipAddressObserver.hpp
src/components/smart-search-bar/SmartSearchBarModel.hpp
src/components/sound-player/SoundPlayer.hpp
src/components/timeline/TimelineModel.hpp
src/externals/single-application/SingleApplication.hpp
src/externals/single-application/SingleApplicationPrivate.hpp
......
......@@ -293,6 +293,7 @@ void App::registerTypes () {
qmlRegisterType<ChatProxyModel>("Linphone", 1, 0, "ChatProxyModel");
qmlRegisterType<ContactsListProxyModel>("Linphone", 1, 0, "ContactsListProxyModel");
qmlRegisterType<SmartSearchBarModel>("Linphone", 1, 0, "SmartSearchBarModel");
qmlRegisterType<SoundPlayer>("Linphone", 1, 0, "SoundPlayer");
qRegisterMetaType<ChatModel::EntryType>("ChatModel::EntryType");
......
......@@ -20,6 +20,9 @@
* Author: Ronan Abhamon
*/
#ifndef COMPONENTS_H_
#define COMPONENTS_H_
#include "assistant/AssistantModel.hpp"
#include "authentication/Authentication.hpp"
#include "calls/CallsListModel.hpp"
......@@ -33,4 +36,7 @@
#include "presence/OwnPresenceModel.hpp"
#include "settings/AccountSettingsModel.hpp"
#include "smart-search-bar/SmartSearchBarModel.hpp"
#include "sound-player/SoundPlayer.hpp"
#include "timeline/TimelineModel.hpp"
#endif // COMPONENTS_H_
/*
* SoundPlayer.cpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: April 25, 2017
* Author: Ronan Abhamon
*/
#include "../../Utils.hpp"
#include "../core/CoreManager.hpp"
#include "SoundPlayer.hpp"
// =============================================================================
SoundPlayer::SoundPlayer (QObject *parent) : QObject(parent) {
mInternalPlayer = CoreManager::getInstance()->getCore()->createLocalPlayer("", "", nullptr);
}
// -----------------------------------------------------------------------------
void SoundPlayer::pause () {
if (mPlaybackState == SoundPlayer::PausedState)
return;
if (mInternalPlayer->pause()) {
setError(QStringLiteral("Unable to pause: `%1`").arg(mSource));
return;
}
mPlaybackState = SoundPlayer::PausedState;
emit paused();
emit playbackStateChanged(mPlaybackState);
}
void SoundPlayer::play () {
if (mPlaybackState == SoundPlayer::PlayingState)
return;
if (
(mPlaybackState == SoundPlayer::StoppedState || mPlaybackState == SoundPlayer::ErrorState) &&
mInternalPlayer->open(::Utils::qStringToLinphoneString(mSource))
) {
qWarning() << QStringLiteral("Unable to open: `%1`").arg(mSource);
return;
}
if (mInternalPlayer->start()
) {
setError(QStringLiteral("Unable to play: `%1`").arg(mSource));
return;
}
mPlaybackState = SoundPlayer::PlayingState;
emit playing();
emit playbackStateChanged(mPlaybackState);
}
void SoundPlayer::stop () {
if (mPlaybackState == SoundPlayer::StoppedState)
return;
mInternalPlayer->close();
mPlaybackState = SoundPlayer::StoppedState;
emit stopped();
emit playbackStateChanged(mPlaybackState);
}
// -----------------------------------------------------------------------------
void SoundPlayer::seek (int offset) {
mInternalPlayer->seek(offset);
}
// -----------------------------------------------------------------------------
int SoundPlayer::getPosition () const {
return mInternalPlayer->getCurrentPosition();
}
// -----------------------------------------------------------------------------
void SoundPlayer::setError (const QString &message) {
qWarning() << message;
mInternalPlayer->close();
if (mPlaybackState != SoundPlayer::ErrorState) {
mPlaybackState = SoundPlayer::ErrorState;
emit playbackStateChanged(mPlaybackState);
}
}
// -----------------------------------------------------------------------------
QString SoundPlayer::getSource () const {
return mSource;
}
void SoundPlayer::setSource (const QString &source) {
if (source == mSource)
return;
stop();
mSource = source;
emit sourceChanged(source);
}
// -----------------------------------------------------------------------------
SoundPlayer::PlaybackState SoundPlayer::getPlaybackState () const {
return mPlaybackState;
}
void SoundPlayer::setPlaybackState (PlaybackState playbackState) {
switch (playbackState) {
case PlayingState:
play();
break;
case PausedState:
pause();
break;
case StoppedState:
stop();
break;
case ErrorState:
break;
}
}
// -----------------------------------------------------------------------------
int SoundPlayer::getDuration () const {
return mInternalPlayer->getDuration();
}
/*
* SoundPlayer.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Created on: April 25, 2017
* Author: Ronan Abhamon
*/
#ifndef SOUND_PLAYER_H_
#define SOUND_PLAYER_H_
#include <memory>
#include <QObject>
// =============================================================================
namespace linphone {
class Player;
}
class SoundPlayer : public QObject {
Q_OBJECT;
Q_PROPERTY(QString source READ getSource WRITE setSource NOTIFY sourceChanged);
Q_PROPERTY(PlaybackState playbackState READ getPlaybackState WRITE setPlaybackState NOTIFY playbackStateChanged);
Q_PROPERTY(int duration READ getDuration NOTIFY sourceChanged);
public:
enum PlaybackState {
PlayingState,
PausedState,
StoppedState,
ErrorState
};
Q_ENUM(PlaybackState);
SoundPlayer (QObject *parent = Q_NULLPTR);
~SoundPlayer () = default;
void pause ();
void play ();
void stop ();
void seek (int offset);
int getPosition () const;
signals:
void sourceChanged (const QString &source);
void paused ();
void playing ();
void stopped ();
void playbackStateChanged (PlaybackState playbackState);
private:
void setError (const QString &message);
QString getSource () const;
void setSource (const QString &source);
PlaybackState getPlaybackState () const;
void setPlaybackState (PlaybackState playbackState);
int getDuration () const;
std::shared_ptr<linphone::Player> mInternalPlayer;
QString mSource;
PlaybackState mPlaybackState = StoppedState;
};
#endif // SOUND_PLAYER_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment