mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kutils: add bits to control audio output of media classes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
f02ad6cc2a
commit
483854d35a
3 changed files with 65 additions and 23 deletions
|
@ -102,6 +102,27 @@ QStringList KAbstractPlayer::protocols()
|
|||
return s_protocols;
|
||||
}
|
||||
|
||||
QString KAbstractPlayer::audiooutput()
|
||||
{
|
||||
return property("audio-device").toString();
|
||||
}
|
||||
|
||||
QStringList KAbstractPlayer::audiooutputs()
|
||||
{
|
||||
const QVariantList value = property("audio-device-list").toList();
|
||||
QStringList stringlist;
|
||||
foreach (QVariant variant, value) {
|
||||
QMapIterator<QString,QVariant> iter(variant.toMap());
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
if (iter.key() == "name") {
|
||||
stringlist.append(iter.value().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringlist;
|
||||
}
|
||||
|
||||
bool KAbstractPlayer::isPlaying()
|
||||
{
|
||||
return !property("pause").toBool() && !property("path").isNull();
|
||||
|
@ -150,12 +171,16 @@ void KAbstractPlayer::setVolume(int volume)
|
|||
setProperty("volume", volume);
|
||||
}
|
||||
|
||||
|
||||
void KAbstractPlayer::setMute(bool mute)
|
||||
{
|
||||
setProperty("mute", mute);
|
||||
}
|
||||
|
||||
void KAbstractPlayer::setAudioOutput(QString output)
|
||||
{
|
||||
setProperty("audio-device", output);
|
||||
}
|
||||
|
||||
void KAbstractPlayer::setFullscreen(bool fullscreen)
|
||||
{
|
||||
setProperty("fullscreen", fullscreen);
|
||||
|
@ -295,25 +320,30 @@ KAudioPlayer::KAudioPlayer(QObject *parent)
|
|||
{
|
||||
COMMON_CONSTRUCTOR
|
||||
|
||||
m_settings = new QSettings("KMediaPlayer", QCoreApplication::applicationName());
|
||||
m_appname = QCoreApplication::applicationName();
|
||||
m_settings = new QSettings("KMediaPlayer", "kmediaplayer");
|
||||
if (m_handle) {
|
||||
mpv_set_wakeup_callback(m_handle, wakeup_audio, this);
|
||||
// TODO: newer releases use vid, video is compat!
|
||||
// NOTE: the change is pre-2014
|
||||
setProperty("video", "no");
|
||||
|
||||
setVolume(m_settings->value("state/volume", 90).toInt());
|
||||
setMute(m_settings->value("state/mute", false).toBool());
|
||||
QString globalaudio = m_settings->value("global/audiooutput", "auto").toString();
|
||||
int globalvolume = m_settings->value("global/volume", 90).toInt();
|
||||
bool globalmute = m_settings->value("global/mute", false).toBool();
|
||||
setAudioOutput(m_settings->value(m_appname + "/audiooutput", globalaudio).toString());
|
||||
setVolume(m_settings->value(m_appname + "/volume", globalvolume).toInt());
|
||||
setMute(m_settings->value(m_appname + "/mute", globalmute).toBool());
|
||||
}
|
||||
}
|
||||
|
||||
KAudioPlayer::~KAudioPlayer()
|
||||
{
|
||||
if (m_handle && m_settings && m_settings->isWritable()) {
|
||||
m_settings->beginGroup("state");
|
||||
m_settings->beginGroup(m_appname);
|
||||
m_settings->setValue("audiooutput", audiooutput());
|
||||
m_settings->setValue("volume", volume());
|
||||
m_settings->setValue("mute", mute());
|
||||
m_settings->setValue("fullScreen", isFullscreen());
|
||||
m_settings->endGroup();
|
||||
m_settings->sync();
|
||||
} else {
|
||||
|
@ -364,7 +394,8 @@ KMediaPlayer::KMediaPlayer(QWidget *parent)
|
|||
{
|
||||
COMMON_CONSTRUCTOR
|
||||
|
||||
m_settings = new QSettings("KMediaPlayer", QCoreApplication::applicationName());
|
||||
m_appname = QCoreApplication::applicationName();
|
||||
m_settings = new QSettings("KMediaPlayer", "kmediaplayer");
|
||||
if (m_handle) {
|
||||
mpv_set_wakeup_callback(m_handle, wakeup_media, this);
|
||||
QVariant wid;
|
||||
|
@ -376,19 +407,22 @@ KMediaPlayer::KMediaPlayer(QWidget *parent)
|
|||
}
|
||||
setOption("wid", wid);
|
||||
|
||||
setVolume(m_settings->value("state/volume", 90).toInt());
|
||||
setMute(m_settings->value("state/mute", false).toBool());
|
||||
setFullscreen(m_settings->value("state/fullscreen", false).toBool());
|
||||
QString globalaudio = m_settings->value("global/audiooutput", "auto").toString();
|
||||
int globalvolume = m_settings->value("global/volume", 90).toInt();
|
||||
bool globalmute = m_settings->value("global/mute", false).toBool();
|
||||
setAudioOutput(m_settings->value(m_appname + "/audiooutput", globalaudio).toString());
|
||||
setVolume(m_settings->value(m_appname + "/volume", globalvolume).toInt());
|
||||
setMute(m_settings->value(m_appname + "/mute", globalmute).toBool());
|
||||
}
|
||||
}
|
||||
|
||||
KMediaPlayer::~KMediaPlayer()
|
||||
{
|
||||
if (m_handle && m_settings && m_settings->isWritable()) {
|
||||
m_settings->beginGroup("state");
|
||||
m_settings->beginGroup(m_appname);
|
||||
m_settings->setValue("audiooutput", audiooutput());
|
||||
m_settings->setValue("volume", volume());
|
||||
m_settings->setValue("mute", mute());
|
||||
m_settings->setValue("fullScreen", isFullscreen());
|
||||
m_settings->endGroup();
|
||||
m_settings->sync();
|
||||
} else {
|
||||
|
|
|
@ -125,6 +125,15 @@ public:
|
|||
@see isProtocolSupported
|
||||
*/
|
||||
QStringList protocols();
|
||||
/*!
|
||||
@return Audio output
|
||||
*/
|
||||
QString audiooutput();
|
||||
/*!
|
||||
@return Audio outputs
|
||||
@todo maybe that should return a QMap?
|
||||
*/
|
||||
QStringList audiooutputs();
|
||||
/*!
|
||||
@return Whether the current state is playing (not paused), does not mean it's not buffering
|
||||
*/
|
||||
|
@ -182,6 +191,10 @@ public:
|
|||
@param mute mute state
|
||||
*/
|
||||
void setMute(bool mute);
|
||||
/*!
|
||||
@param output audio output
|
||||
*/
|
||||
void setAudioOutput(QString output);
|
||||
/*!
|
||||
@param fullscreen wheather it should take all screen space
|
||||
@warning This will most likely fail and the property will be set but MPV will do nothing
|
||||
|
@ -250,6 +263,7 @@ private:
|
|||
#ifdef MAKE_KMEDIAPLAYER_LIB
|
||||
mpv_handle *m_handle;
|
||||
#endif // MAKE_KMEDIAPLAYER_LIB
|
||||
QString m_appname;
|
||||
QSettings *m_settings;
|
||||
};
|
||||
|
||||
|
@ -315,6 +329,7 @@ private:
|
|||
#ifdef MAKE_KMEDIAPLAYER_LIB
|
||||
mpv_handle *m_handle;
|
||||
#endif // MAKE_KMEDIAPLAYER_LIB
|
||||
QString m_appname;
|
||||
QSettings *m_settings;
|
||||
};
|
||||
|
||||
|
|
|
@ -58,22 +58,15 @@ public:
|
|||
enum KMediaOption {
|
||||
//! @brief No options at all
|
||||
NoOptions = 0,
|
||||
/*!
|
||||
@long When URL is dragged to the widget it will be opened
|
||||
*/
|
||||
//! @brief When URL is dragged to the widget it will be opened
|
||||
DragDrop = 1,
|
||||
/*!
|
||||
@long Provide fullscreen option, it is such because it will ask the parent to do it
|
||||
*/
|
||||
//! @brief Provide fullscreen option, it is such because it will ask the parent to do it
|
||||
FullscreenVideo = 2,
|
||||
/*!
|
||||
@long After a certain amount of time the controls will hide themselfs allowing more
|
||||
screen space to be taken by the video widget
|
||||
*/
|
||||
//! @brief After a certain amount of time the controls will hide and show again when needed
|
||||
HiddenControls = 3,
|
||||
//! @brief All available options
|
||||
AllOptions = DragDrop | FullscreenVideo | HiddenControls,
|
||||
//! @brief Default options, currently none
|
||||
//! @brief Default options
|
||||
DefaultOptions = NoOptions
|
||||
};
|
||||
Q_DECLARE_FLAGS(KMediaOptions, KMediaOption);
|
||||
|
|
Loading…
Add table
Reference in a new issue