forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTMedia.h
126 lines (107 loc) · 4.84 KB
/
TMedia.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
#ifndef MUDLET_TMEDIA_H
#define MUDLET_TMEDIA_H
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014-2017 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2014-2019 by Stephen Lyons - slysven@virginmedia.com *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "Host.h"
#include "TEvent.h"
#include "mudlet.h"
#include "TMediaData.h"
#include "pre_guard.h"
#include <QMediaPlayer>
#include "post_guard.h"
class TMediaPlayer
{
public:
TMediaPlayer()
: mpHost(nullptr)
, mMediaData()
, mMediaPlayer(nullptr)
, initialized(false)
{}
~TMediaPlayer() {}
TMediaPlayer(Host* pHost, TMediaData& mediaData)
: mpHost(pHost)
, mMediaData(mediaData)
, mMediaPlayer(new QMediaPlayer(pHost))
, initialized(true)
{}
TMediaData getMediaData() { return mMediaData; }
void setMediaData(TMediaData& mediaData) { mMediaData = mediaData; }
QMediaPlayer* getMediaPlayer() const { return mMediaPlayer; }
bool isInitialized() { return initialized; }
private:
QPointer<Host> mpHost;
TMediaData mMediaData;
QMediaPlayer* mMediaPlayer;
bool initialized;
};
class TMedia : public QObject
{
Q_OBJECT
public:
Q_DISABLE_COPY(TMedia)
TMedia(Host* pHost, const QString& profileName);
~TMedia();
void playMedia(TMediaData& mediaData);
void stopMedia(TMediaData& mediaData);
void parseGMCP(QString& packageMessage, QString& gmcp);
bool purgeMediaCache();
private:
void stopAllMediaPlayers();
QUrl parseUrl(TMediaData& mediaData);
static bool isValidUrl(QUrl& url);
static bool isFileRelative(TMediaData& mediaData);
QStringList parseFileNameList(TMediaData& mediaData, QDir& dir);
QStringList getFileNameList(TMediaData& mediaData);
QUrl getFileUrl(TMediaData& mediaData);
bool processUrl(TMediaData& mediaData);
void writeFile(QNetworkReply* reply);
void downloadFile(TMediaData& mediaData);
QString setupMediaAbsolutePathFileName(TMediaData& mediaData);
QList<TMediaPlayer> getMediaPlayerList(TMediaData& mediaData);
TMediaPlayer getMediaPlayer(TMediaData& mediaData);
TMediaPlayer matchMediaPlayer(TMediaData& mediaData, const QString& absolutePathFileName);
bool doesMediaHavePriorityToPlay(TMediaData& mediaData, const QString& absolutePathFileName);
void matchMediaKeyAndStopMediaVariants(TMediaData& mediaData, const QString& absolutePathFileName);
void play(TMediaData& mediaData);
static TMediaData::MediaType parseJSONByMediaType(QJsonObject& json);
static QString parseJSONByMediaFileName(QJsonObject& json);
static int parseJSONByMediaVolume(QJsonObject& json);
static int parseJSONByMediaPriority(QJsonObject& json);
static int parseJSONByMediaLoops(QJsonObject& json);
static TMediaData::MediaContinue parseJSONByMediaContinue(QJsonObject& json);
static QString parseJSONByMediaTag(QJsonObject& json);
static QString parseJSONByMediaUrl(QJsonObject& json);
static QString parseJSONByMediaKey(QJsonObject& json);
void parseJSONForMediaDefault(QJsonObject& json);
void parseJSONForMediaLoad(QJsonObject& json);
void parseJSONForMediaPlay(QJsonObject& json);
void parseJSONForMediaStop(QJsonObject& json);
QPointer<Host> mpHost;
QString mProfileName;
QList<TMediaPlayer> mMSPSoundList;
QList<TMediaPlayer> mMSPMusicList;
QList<TMediaPlayer> mGMCPSoundList;
QList<TMediaPlayer> mGMCPMusicList;
QNetworkAccessManager* mpNetworkAccessManager;
QMap<QNetworkReply*, TMediaData> mMediaDownloads;
};
#endif // MUDLET_TMEDIA_H