forked from RSATom/QmlVlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QmlVlcPlayerProxy.h
192 lines (154 loc) · 6.26 KB
/
QmlVlcPlayerProxy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*******************************************************************************
* Copyright © 2014-2015, Sergey Radionov <rsatom_gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#pragma once
#include <QObject>
#include <QTimer>
#include <QEvent>
#include <QQmlParserStatus>
#include "QmlVlcVideoSource.h"
#include "QmlVlcAudio.h"
#include "QmlVlcInput.h"
#include "QmlVlcPlaylist.h"
#include "QmlVlcSubtitle.h"
#include "QmlVlcVideo.h"
#include "QmlVlcMedia.h"
class QmlVlcPlayerProxy
: public QmlVlcVideoSource,
protected vlc::media_player_events_callback
{
Q_OBJECT
protected:
virtual void classBegin() override;
virtual void componentComplete() override;
void classEnd();
public:
explicit QmlVlcPlayerProxy( const std::shared_ptr<vlc::playlist_player_core>& player,
QObject* parent = 0 );
~QmlVlcPlayerProxy();
Q_PROPERTY( QString vlcVersion READ get_vlcVersion )
Q_PROPERTY( bool playing READ get_playing NOTIFY playingChanged )
Q_PROPERTY( double length READ get_length NOTIFY mediaPlayerLengthChanged )
enum State {
NothingSpecial = ::libvlc_NothingSpecial,
Opening = ::libvlc_Opening,
Buffering = ::libvlc_Buffering,
Playing = ::libvlc_Playing,
Paused = ::libvlc_Paused,
Stopped = ::libvlc_Stopped,
Ended = ::libvlc_Ended,
Error = ::libvlc_Error,
};
Q_ENUMS( State )
Q_PROPERTY( State state READ get_state NOTIFY stateChanged )
Q_PROPERTY( QString mrl READ get_mrl WRITE set_mrl )
Q_PROPERTY( double position READ get_position WRITE set_position NOTIFY mediaPlayerPositionChanged )
Q_PROPERTY( double time READ get_time WRITE set_time NOTIFY mediaPlayerTimeChanged )
Q_PROPERTY( unsigned volume READ get_volume WRITE set_volume NOTIFY volumeChanged )
Q_PROPERTY( QmlVlcInput* input READ get_input CONSTANT )
Q_PROPERTY( QmlVlcVideo* video READ get_video CONSTANT )
Q_PROPERTY( QmlVlcAudio* audio READ get_audio CONSTANT )
Q_PROPERTY( QmlVlcSubtitle* subtitle READ get_subtitle CONSTANT )
Q_PROPERTY( QmlVlcPlaylist* playlist READ get_playlist CONSTANT )
Q_PROPERTY( QmlVlcMedia* mediaDescription READ get_mediaDesc CONSTANT )
Q_SIGNALS:
void playingChanged();
void stateChanged( QmlVlcPlayerProxy::State state );
public:
//QML Api
QString get_vlcVersion();
Q_INVOKABLE void play( const QString& mrl );
Q_INVOKABLE void play();
Q_INVOKABLE void pause();
Q_INVOKABLE void togglePause();
Q_INVOKABLE void stop();
Q_INVOKABLE void mute();
Q_INVOKABLE void unMute();
Q_INVOKABLE void toggleMute();
QString get_mrl();
void set_mrl( const QString& mrl );
bool get_playing();
double get_length();
double get_position();
void set_position( double );
double get_time();
void set_time( double );
unsigned int get_volume();
void set_volume( unsigned int );
State get_state();
vlc::playlist_player_core& player()
{ assert( m_player ); return *m_player; }
const std::shared_ptr<vlc::playlist_player_core>& player_ptr()
{ return m_player; }
Q_SIGNALS:
/* async events from libvlc */
void mediaPlayerMediaChanged();
void mediaPlayerNothingSpecial();
void mediaPlayerOpening();
void mediaPlayerBuffering( float percents );
void mediaPlayerPlaying();
void mediaPlayerPaused();
void mediaPlayerForward();
void mediaPlayerBackward();
void mediaPlayerEncounteredError();
void mediaPlayerEndReached();
void mediaPlayerStopped();
void mediaPlayerTitleChanged();
void mediaPlayerTimeChanged( double time );
void mediaPlayerPositionChanged( float position );
void mediaPlayerSeekableChanged( bool seekable );
void mediaPlayerPausableChanged( bool pausable );
void mediaPlayerLengthChanged( double length );
void volumeChanged();
protected:
void media_player_event( const libvlc_event_t* e ) override;
bool event( QEvent* ) override;
struct LibvlcEvent;
virtual void handleLibvlcEvent( const LibvlcEvent& );
private Q_SLOTS:
void currentItemEndReached();
public:
QmlVlcAudio* get_audio() { return &m_audio; }
QmlVlcInput* get_input() { return &m_input; }
QmlVlcPlaylist* get_playlist() { return &m_playlist; }
QmlVlcSubtitle* get_subtitle() { return &m_subtitle; }
QmlVlcVideo* get_video() { return &m_video; }
QmlVlcMedia* get_mediaDesc() { return &m_currentMediaDesc; }
private:
std::shared_ptr<vlc::playlist_player_core> m_player;
QmlVlcAudio m_audio;
QmlVlcInput m_input;
QmlVlcPlaylist m_playlist;
QmlVlcSubtitle m_subtitle;
QmlVlcVideo m_video;
QmlVlcCurrentMedia m_currentMediaDesc;
QTimer m_errorTimer;
};
struct QmlVlcPlayerProxy::LibvlcEvent : public QEvent
{
enum {
LibvlcEventId = QEvent::User,
};
LibvlcEvent( const libvlc_event_t& );
libvlc_event_t _libvlcEvent;
};