Skip to content

Commit

Permalink
feat(qml, core): add playback state
Browse files Browse the repository at this point in the history
  • Loading branch information
aa-bamboo committed Apr 29, 2022
1 parent fa95711 commit e9b1023
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
36 changes: 18 additions & 18 deletions src/core/media.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/******************************************************************************
* This file is part of QuickVLC - Qt and libvlc connection library.
* Copyright (C) 2016 Tadej Novak <tadej@tano.si>,
* 2022 Alexey Avramchik (OU Bamboo group) <aa@bam-boo.eu>
*
* QuickVLC 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 3 of the License,
* or (at your option) any later version.
*
* QuickVLC 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 QuickVLC. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/
* This file is part of QuickVLC - Qt and libvlc connection library.
* Copyright (C) 2016 Tadej Novak <tadej@tano.si>,
* 2022 Alexey Avramchik (OU Bamboo group) <aa@bam-boo.eu>
*
* QuickVLC 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 3 of the License,
* or (at your option) any later version.
*
* QuickVLC 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 QuickVLC. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

Expand Down Expand Up @@ -58,7 +58,7 @@ class QUICKVLC_CORE_EXPORT Media : public QObject
void durationChanged(int duration);
void parsedChanged(bool status);
void freed(libvlc_media_t *media);
void stateChanged(const Enum::State &state);
void playbackStateChanged(const Enum::PlaybackState &state);

private:
void initMedia(const QString &location, bool localFile, Instance *instance);
Expand Down
10 changes: 5 additions & 5 deletions src/core/mediaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ float MediaPlayer::sampleAspectRatio() const
return sar;
}

Enum::State MediaPlayer::state() const
Enum::PlaybackState MediaPlayer::playbackState() const
{
if (!libvlc_media_player_get_media(m_vlcMediaPlayer)) {
return Enum::Idle;
Expand All @@ -144,18 +144,18 @@ Enum::State MediaPlayer::state() const

Error::printErrorMsg();

return Enum::State(state);
return Enum::PlaybackState(state);
}

void MediaPlayer::setTime(int time)
{
if (!(state() == Enum::Buffering || state() == Enum::Playing || state() == Enum::Paused)) {
if (!(playbackState() == Enum::Buffering || playbackState() == Enum::Playing || playbackState() == Enum::Paused)) {
return;
}

bool changed = libvlc_media_player_set_time(m_vlcMediaPlayer, time, false);

if (state() == Enum::Paused && changed == 0) {
if (playbackState() == Enum::Paused && changed == 0) {
emit timeChanged(time);
}

Expand Down Expand Up @@ -313,7 +313,7 @@ void MediaPlayer::libvlc_callback(const libvlc_event_t *event, void *data)
}

if (event->type >= libvlc_MediaPlayerNothingSpecial && event->type <= libvlc_MediaPlayerEncounteredError) {
emit core->stateChanged();
emit core->playbackStateChanged();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/mediaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class QUICKVLC_CORE_EXPORT MediaPlayer : public QObject

float playbackRate() const;

Enum::State state() const;
Enum::PlaybackState playbackState() const;

public slots:
void setTime(int time);
Expand Down Expand Up @@ -99,7 +99,7 @@ public slots:
void seekableChanged(bool seekable);
void stopped();
void timeChanged(int time);
void stateChanged();
void playbackStateChanged();

private:
static void libvlc_callback(const libvlc_event_t *event, void *data);
Expand Down
38 changes: 19 additions & 19 deletions src/core/vlc.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/******************************************************************************
* This file is part of QuickVLC - Qt and libvlc connection library.
* Copyright (C) 2016 Tadej Novak <tadej@tano.si>,
* 2022 Alexey Avramchik (OU Bamboo group) <aa@bam-boo.eu>
*
* QuickVLC 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 3 of the License,
* or (at your option) any later version.
*
* QuickVLC 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 QuickVLC. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/
* This file is part of QuickVLC - Qt and libvlc connection library.
* Copyright (C) 2016 Tadej Novak <tadej@tano.si>,
* 2022 Alexey Avramchik (OU Bamboo group) <aa@bam-boo.eu>
*
* QuickVLC 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 3 of the License,
* or (at your option) any later version.
*
* QuickVLC 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 QuickVLC. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/

#pragma once

Expand Down Expand Up @@ -95,7 +95,7 @@ class QUICKVLC_CORE_EXPORT Enum : public QObject

enum Scale { NoScale, S_1_05, S_1_1, S_1_2, S_1_3, S_1_4, S_1_5, S_1_6, S_1_7, S_1_8, S_1_9, S_2_0 };

enum State { Idle, Opening, Buffering, Playing, Paused, Stopped, Ended, Error };
enum PlaybackState { Idle, Opening, Buffering, Playing, Paused, Stopped, Ended, Error };

enum VideoCodec { NoVideo, MPEG2Video, MPEG4Video, H264, Theora };

Expand Down Expand Up @@ -139,7 +139,7 @@ class QUICKVLC_CORE_EXPORT Enum : public QObject
Q_ENUM(PlaybackMode)
Q_ENUM(Ratio)
Q_ENUM(Scale)
Q_ENUM(State)
Q_ENUM(PlaybackState)
Q_ENUM(VideoCodec)
Q_ENUM(VideoOutput)
};
Expand Down
5 changes: 3 additions & 2 deletions src/qml/mediaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MediaPlayer::MediaPlayer(QQuickItem *parent) : MediaSource { parent }, m_media {
connect(m_player, &Vlc::MediaPlayer::positionChanged, this, &MediaPlayer::positionChanged);
connect(m_player, &Vlc::MediaPlayer::seekableChanged, this, &MediaPlayer::seekableChanged);
connect(m_player, &Vlc::MediaPlayer::timeChanged, this, &MediaPlayer::positionChanged);
connect(m_player, &Vlc::MediaPlayer::playbackStateChanged, this, &MediaPlayer::playbackStateChanged);

setPlayer(m_player);
}
Expand Down Expand Up @@ -131,9 +132,9 @@ bool MediaPlayer::seekable() const
return m_player->seekable();
}

int MediaPlayer::state() const
int MediaPlayer::playbackState() const
{
return m_player->state();
return m_player->playbackState();
}

void MediaPlayer::open()
Expand Down
5 changes: 4 additions & 1 deletion src/qml/mediaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QUICKVLC_QML_EXPORT MediaPlayer : public MediaSource
Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged)
Q_PROPERTY(bool seekable READ seekable NOTIFY seekableChanged)
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(int playbackState READ playbackState NOTIFY playbackStateChanged)

public:
explicit MediaPlayer(QQuickItem *parent = nullptr);
Expand All @@ -71,7 +72,7 @@ class QUICKVLC_QML_EXPORT MediaPlayer : public MediaSource

bool seekable() const;

int state() const;
int playbackState() const;

signals:
void autoplayChanged();
Expand All @@ -90,4 +91,6 @@ class QUICKVLC_QML_EXPORT MediaPlayer : public MediaSource
Vlc::MediaPlayer *m_player;

bool m_autoplay;

Q_ENUM(Vlc::Enum::PlaybackState)
};

0 comments on commit e9b1023

Please sign in to comment.