CCIMXDesktop
 
Loading...
Searching...
No Matches
MediaPlayer.h
1#ifndef MEDIAPLAYER_H
2#define MEDIAPLAYER_H
3#include <QImage>
4#include <QObject>
5class QMediaPlayer;
6class VideoPlayer;
7class QLabel;
8class CVImage;
9
13enum class MediaError {
14 NO_ERROR,
15 UNEXSITED_SOURCE,
20 VEDIO_ONLY,
21
26 SOUND_ONLY,
27
28 UNSUPPORT_SOURCE,
29};
30
31namespace MediaPlayerPublicSettings {
36using MisSyncDelay_t = unsigned int;
37
41static constexpr MisSyncDelay_t DEF_ACCPET_DELAY = 500;
42};
43
48struct MediaInfo {
49 QString title;
50 QString author;
51 QString albumTitle;
52 QString albumArtist;
53 QString composer;
54 QString genre;
55 qint64 durationMs;
56 QString date;
57
60 QString audioCodec;
61 QString mediaType;
63 QString publisher;
64 QImage coverImage;
65};
66
77class MediaPlayer : public QObject {
78 Q_OBJECT
79public:
85 /* media status */
86 bool audio_ready { false };
87 bool video_ready { false };
88 /* What has been fucking happened */
89 QString video_discriptions {};
90 QString audio_discriptions {};
91 };
97 explicit MediaPlayer(QObject* parent = nullptr);
103
109 void setSource(const char* local_file);
114 QString source() const;
115
122 void setVolume(const float percentage);
129 float volume() const;
134 inline qint64 get_durations() const { return durations; }
135
140 inline qint64 get_position() const { return position; }
141
147 bool resume();
148
153 bool pause();
154
161 bool close();
162
169 bool isPlaying() const;
170
176 const unsigned int msec
177 = MediaPlayerPublicSettings::DEF_ACCPET_DELAY) {
178 mis_sync_seconds = msec;
179 }
180
185 void set_position(const qint64 position);
186signals:
194 void display_frame(QImage image);
195 /* volumn changed signals */
196
202 void volumeChanged(float percentage);
203
209 void sourceOpened(const QString source,
211
218 void videoAvailable(bool sourceAvailable, const QImage firstPage);
219
223 void mediaEnd();
228 void durationChanged(qint64 new_durantion);
229
234 void positionChanged(qint64 position);
235
240 void metaDataAvailable(const MediaInfo info);
241
242private:
243 /* QMediaPlayer is expected to use Audio */
244 QMediaPlayer* audioPlayer { nullptr };
245 /* VideoPlayer is expected to display the video */
246 VideoPlayer* videoPlayer { nullptr };
247 /* for status holder */
248 MediaPlayerStatus media_status;
249 MediaPlayerPublicSettings::MisSyncDelay_t
250 mis_sync_seconds { MediaPlayerPublicSettings::DEF_ACCPET_DELAY };
251 qint64 durations {};
252 qint64 position {};
253
254 /* functions */
255
256 /* invoke with initing */
257 void init_allocations();
258 void init_connections();
259
267 void process_sync(const CVImage& current_frame);
268 void handle_sync_duration(qint64 durations);
269 void handle_sync_position(qint64 position);
270 void extract_metainfo();
271};
272
273#endif // MEDIAPLAYER_H
The CVImage class is the image class that provides the image in the frameworks.
Definition CVImage.h:9
MediaPlayer is the wrapper of VideoPlayer and AudioPlayer, with the sync of video and audio basically...
Definition MediaPlayer.h:77
Q_DISABLE_COPY(MediaPlayer)
disable copy
void metaDataAvailable(const MediaInfo info)
metaDataAvailable the signal indicating the meta data available
void set_accept_missync_msecond(const unsigned int msec=MediaPlayerPublicSettings::DEF_ACCPET_DELAY)
set_accept_missync_msecond set the default mis sync tolerance
Definition MediaPlayer.h:175
QString source() const
source get the source of the media
Definition MediaPlayer.cpp:56
void setVolume(const float percentage)
setVolume set the volume of the media
Definition MediaPlayer.cpp:60
bool isPlaying() const
isPlaying check if the media is playing
Definition MediaPlayer.cpp:92
void videoAvailable(bool sourceAvailable, const QImage firstPage)
videoAvailable for mp4 like video, this means we can display the medias
qint64 get_durations() const
get_durations get the durations of the media
Definition MediaPlayer.h:134
void positionChanged(qint64 position)
positionChanged the signal indicating the position changed
void display_frame(QImage image)
display_frame display the frame by hooking this signals
void sourceOpened(const QString source, MediaPlayer::MediaPlayerStatus status)
sourceOpened the signal indicating the source opened
float volume() const
volume get the volume of the media
Definition MediaPlayer.cpp:64
void durationChanged(qint64 new_durantion)
durationChanged the signal indicating the duration changed
void set_position(const qint64 position)
set_position moves to the target positions of the media
Definition MediaPlayer.cpp:96
bool resume()
resume start the media player
Definition MediaPlayer.cpp:68
bool close()
close close the media player
Definition MediaPlayer.cpp:86
void mediaEnd()
mediaEnd the signal indicating the media end
void setSource(const char *local_file)
setSource set the source of the media
Definition MediaPlayer.cpp:38
bool pause()
pause pause the media player
Definition MediaPlayer.cpp:80
void volumeChanged(float percentage)
volumeChanged the signal indicating the volume changed
qint64 get_position() const
get_position get the position of the media
Definition MediaPlayer.h:140
Definition VideoPlayer.h:35
The MediaInfo struct provides the media information.
Definition MediaPlayer.h:48
QString albumArtist
the album artist of the media
Definition MediaPlayer.h:52
int audioBitRate
the audio bit rate of the media
Definition MediaPlayer.h:59
QString composer
the composer of the media
Definition MediaPlayer.h:53
QString publisher
the publisher of the media
Definition MediaPlayer.h:63
QString audioCodec
the audio codec of the media
Definition MediaPlayer.h:60
QString author
the author of the media
Definition MediaPlayer.h:50
qint64 durationMs
the duration of the media
Definition MediaPlayer.h:55
QString albumTitle
the album title of the media
Definition MediaPlayer.h:51
QString genre
the genre of the media
Definition MediaPlayer.h:54
QString title
the title of the media
Definition MediaPlayer.h:49
QString mediaType
the media type of the media
Definition MediaPlayer.h:61
int sampleRate
the sample rate of the media
Definition MediaPlayer.h:62
QImage coverImage
the cover image of the media
Definition MediaPlayer.h:64
int trackNumber
the track number of the media
Definition MediaPlayer.h:58
QString date
the date of the media
Definition MediaPlayer.h:56
The MediaPlayerStatus class measures the status of the media player.
Definition MediaPlayer.h:84
bool audio_ready
audio ready
Definition MediaPlayer.h:86
bool video_ready
video ready
Definition MediaPlayer.h:87
QString video_discriptions
video discriptions
Definition MediaPlayer.h:89
QString audio_discriptions
audio discriptions
Definition MediaPlayer.h:90