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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
// Copyright (C) 2023 The Qt Company Ltd.
// Copyright (C) 2024 Automotive Grade Linux
// SPDX-License-Identifier: GPL-3.0+
import QtQuick
import QtQuick.Window
import QtQuick.Controls.Fusion
import QtMultimedia
import QtQuick.Effects
import QtCore
import Qt.labs.folderlistmodel
import MediaControls
import Config
ApplicationWindow {
id: root
width: 1920
height: 1080
visible: true
color: Config.mainColor
title: qsTr("Momi Player")
property alias currentFile: playlistInfo.currentIndex
property alias playlistLooped: playbackControl.isPlaylistLooped
property alias metadataInfo: settingsInfo.metadataInfo
function playMedia() {
mediaPlayer.source = playlistInfo.getSource()
mediaPlayer.play()
}
function closeOverlays() {
settingsInfo.visible = false
playlistInfo.visible = false
}
function showOverlay() {
settingsInfo.visible = true
playlistInfo.visible = true
}
function scanMediaFile() {
for (var i = 0; i < mediaFolder.count; i++) {
playlistInfo.addFile(playlistInfo.mediaCount, mediaFolder.get(i, "fileUrl"))
}
if (0 < mediaFolder.count) {
currentFile = 0
playMedia()
}
}
FolderListModel {
id: mediaFolder
showDirs: false
folder: StandardPaths.standardLocations(StandardPaths.MusicLocation)[0]
nameFilters: ["*.mp3", "*.wav", "*.mpg", "*.mpeg", "*.avi", "*.mp4", "*.wmv"]
onStatusChanged: {
if (mediaFolder.status == FolderListModel.Ready) {
scanMediaFile()
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onPositionChanged: {
if (!seeker.opacity) {
if (videoOutput.fullScreen) {
showControls.start()
}
} else {
timer.restart()
}
}
}
Timer {
id: timer
interval: 3000
onTriggered: {
if (!seeker.isMediaSliderPressed) {
if (videoOutput.fullScreen) {
hideControls.start()
}
} else {
timer.restart()
}
}
}
ErrorPopup {
id: errorPopup
}
MediaPlayer {
id: mediaPlayer
videoOutput: videoOutput
audioOutput: AudioOutput {
id: audio
volume: 100
}
function updateMetadata() {
root.metadataInfo.clear()
root.metadataInfo.read(mediaPlayer.metaData)
}
onMetaDataChanged: updateMetadata()
onActiveTracksChanged: updateMetadata()
onErrorOccurred: {
errorPopup.errorMsg = mediaPlayer.errorString
errorPopup.open()
}
onTracksChanged: {
updateMetadata()
}
onMediaStatusChanged: {
if ((MediaPlayer.EndOfMedia === mediaStatus && mediaPlayer.loops !== MediaPlayer.Infinite) &&
((root.currentFile < playlistInfo.mediaCount - 1) || playlistInfo.isShuffled)) {
if (!playlistInfo.isShuffled) {
++root.currentFile
}
root.playMedia()
} else if (MediaPlayer.EndOfMedia === mediaStatus && root.playlistLooped && playlistInfo.mediaCount) {
root.currentFile = 0
root.playMedia()
}
}
}
VideoOutput {
id: videoOutput
anchors.top: parent.top
anchors.bottom: fullScreen ? parent.bottom : playbackControl.top
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: fullScreen ? 0 : 20
anchors.rightMargin: fullScreen ? 0 : 20
visible: mediaPlayer.hasVideo
property bool fullScreen: false
TapHandler {
onDoubleTapped: {
parent.fullScreen = !parent.fullScreen
}
onTapped: {
root.closeOverlays()
}
}
}
Image {
id: defaultCoverArt
anchors.horizontalCenter: videoOutput.horizontalCenter
anchors.verticalCenter: videoOutput.verticalCenter
visible: !videoOutput.visible && mediaPlayer.hasAudio
source: Config.iconSource("Default_CoverArt", false)
}
Rectangle {
id: background
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.top: seeker.opacity ? seeker.top : playbackControl.top
color: Config.mainColor
opacity: videoOutput.fullScreen ? 0.75 : 0.5
}
Image {
id: shadow
source: `qrc:/qt/qml/MediaControls/icons/Shadow.png`
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
PlaybackSeekControl {
id: seeker
anchors.left: playbackControl.left
anchors.right: playbackControl.right
anchors.bottom: playbackControl.top
mediaPlayer: mediaPlayer
}
PlaybackControl {
id: playbackControl
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
mediaPlayer: mediaPlayer
isPlaylistVisible: playlistInfo.visible
onPlayNextFile: {
if (playlistInfo.mediaCount) {
if (!playlistInfo.isShuffled){
++root.currentFile
if (root.currentFile > playlistInfo.mediaCount - 1 && root.playlistLooped) {
root.currentFile = 0
} else if (root.currentFile > playlistInfo.mediaCount - 1 && !root.playlistLooped) {
--root.currentFile
return
}
}
root.playMedia()
}
}
onPlayPreviousFile: {
if (playlistInfo.mediaCount) {
if (!playlistInfo.isShuffled){
--root.currentFile
if (root.currentFile < 0 && isPlaylistLooped) {
root.currentFile = playlistInfo.mediaCount - 1
} else if (root.currentFile < 0 && !root.playlistLooped) {
++root.currentFile
return
}
}
root.playMedia()
}
}
playlistButton.onClicked: !playlistInfo.visible ? root.showOverlay() : root.closeOverlays()
}
MultiEffect {
source: settingsInfo
anchors.fill: settingsInfo
shadowEnabled: settingsInfo.visible || playlistInfo.visible
visible: settingsInfo.visible || playlistInfo.visible
}
PlaylistInfo {
id: playlistInfo
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: seeker.opacity ? seeker.top : playbackControl.top
anchors.topMargin: 10
anchors.rightMargin: 5
visible: false
isShuffled: playbackControl.isPlaylistShuffled
onPlaylistUpdated: {
if (mediaPlayer.playbackState == MediaPlayer.StoppedState && root.currentFile < playlistInfo.mediaCount - 1) {
++root.currentFile
root.playMedia()
}
}
onCurrentFileRemoved: {
mediaPlayer.stop()
if (root.currentFile < playlistInfo.mediaCount - 1) {
root.playMedia()
} else if (playlistInfo.mediaCount) {
--root.currentFile
root.playMedia()
}
}
}
SettingsInfo {
id: settingsInfo
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: seeker.opacity ? seeker.top : playbackControl.top
anchors.topMargin: 10
anchors.rightMargin: 5
mediaPlayer: mediaPlayer
selectedAudioTrack: mediaPlayer.activeAudioTrack
selectedVideoTrack: mediaPlayer.activeVideoTrack
selectedSubtitleTrack: mediaPlayer.activeSubtitleTrack
visible: false
}
ParallelAnimation {
id: hideControls
NumberAnimation {
targets: [playbackControl, seeker, background, shadow]
property: "opacity"
to: 0
duration: 1000
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: playbackControl
property: "anchors.bottomMargin"
to: -playbackControl.height - seeker.height
duration: 1000
easing.type: Easing.InOutQuad
}
}
ParallelAnimation {
id: showControls
NumberAnimation {
targets: [playbackControl, seeker, shadow]
property: "opacity"
to: 1
duration: 1000
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: background
property: "opacity"
to: 0.5
duration: 1000
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: playbackControl
property: "anchors.bottomMargin"
to: 0
duration: 1000
easing.type: Easing.InOutQuad
}
}
}
|