-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.qml
195 lines (162 loc) · 5.54 KB
/
main.qml
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
import QtQuick 2.12
import QtQuick.Window 2.2
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12
import QtQuick.Layouts 1.12
import QtQuick.Dialogs 1.2
import Qt.labs.settings 1.1
import QtMultimedia 5.12
ApplicationWindow {
visible: true
id: application
width: Screen.width*(2.5/5)
height: Screen.height*(2/3)
maximumHeight: height
maximumWidth: width
minimumHeight: height
minimumWidth: width
//flags: Qt.FramelessWindowHint
title: qsTr("Music Player")
Material.theme: lightThemeOn ? Material.Light : Material.Dark
Material.primary: themeColor
Material.background: lightThemeOn ? lightBackground : darkBackground
Material.accent: themeColor
Material.foreground: lightThemeOn ? darkForeground : lightForeground
property bool lightThemeOn: true
property var barsColor: Material.color(Material.Grey,Material.Shade200)
property color themeColor: "#5900b3"
property color lightBackground: "white"
property color darkBackground: "black"
property color lightForeground: "#f2f2f2"
property color darkForeground: "#0d0d0d"
function changeTheme() {
//console.log("in changeTheme()");
lightThemeOn=!lightThemeOn;
}
Rectangle {
id: appRect
anchors.fill: parent
color: parent.Material.background
focus: true
Keys.onPressed: {
if ((event.key === Qt.Key_T) && (event.modifiers & Qt.ControlModifier))
application.changeTheme()
else if ((event.key === Qt.Key_Q) && (event.modifiers & Qt.ControlModifier))
application.close()
else if ((event.key === Qt.Key_Space)) {
if(audioPlayer.playbackState==MediaPlayer.PlayingState)
audioPlayer.pause()
else if(audioPlayer.playbackState==MediaPlayer.PausedState)
audioPlayer.play()
}
}
OptionBar {
id: optionBar
width: parent.width/12
height: parent.height*(7.7/10)
anchors.left: parent.left
anchors.top: parent.top
anchors.right: contentArea.left
}
ContentArea {
id: contentArea
visible: true
width: parent.width*(11/12)
//height: parent.height
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
}
MiniPlayer {
id: miniPlayer
visible: true
anchors.bottom: parent.bottom
controllingPlaylist: audioPlaylist
musicPlayer: audioPlayer
}
}
ColorDialog {
id: colorPicker
title: "Select Theme Color"
showAlphaChannel: false
onAccepted: {
application.themeColor=color
close()
}
onRejected: {
close()
}
}
FileDialog {
id: filesLoader
title: "Chose Songs"
folder: shortcuts.music
selectMultiple: true
selectExisting: true
nameFilters: ["Mp3 Files (*.mp3)"]
onAccepted: {
audioPlaylist.addItems(fileUrls)
if(audioPlaylist.save("file:///C:/MyMusicPlayer/Playlists/global_playlist.m3u","m3u")) {
console.log("Playlist Saved")
}
else {
console.log("Playlist Save Failed"+audioPlaylist.errorString)
}
if(audioPlayer.status==MediaPlayer.NoMedia) {
audioPlaylist.currentIndex=0
}
}
function basename(url) {
return (String(url).slice(String(url).lastIndexOf("/")+1,-4))
}
}
MediaPlayer {
id: audioPlayer
objectName: "mediaPlayer"
audioRole: Audio.MusicRole
autoPlay: true
property int durationProgress: position
property double volumeValue: volume
property Playlist songsQueue: audioPlaylist
source: ""
property var coverArtURL: metaData.coverArtUrlSmall ? metaData.coverArtUrlSmall : "qrc:/player/no_album_cover"
onStopped: {
if(duration==position)
songsQueue.next()
source= songsQueue.currentItemSource
console.log(metaData.coverArtUrlSmall)
}
}
Playlist {
id: audioPlaylist
property int lastSongPlayed: currentIndex
Component.onCompleted: {
audioPlaylist.load("file:///C:/MyMusicPlayer/Playlists/global_playlist.m3u","m3u")
var pos= audioPlayer.durationProgress
audioPlaylist.currentIndex= lastSongPlayed<=audioPlaylist.itemCount ? lastSongPlayed : 0
audioPlayer.source= audioPlaylist.currentItemSource
audioPlayer.seek(pos)
audioPlayer.pause()
audioPlayer.volume= audioPlayer.volumeValue
}
Component.onDestruction: {
audioPlaylist.save("file:///C:/MyMusicPlayer/Playlists/global_playlist.m3u","m3u")
}
}
Settings {
id: appSettings
category: "Application Settings"
property alias appThemeMode: application.lightThemeOn
property alias colorTheme: application.themeColor
}
Settings {
id: playerSettings
category: "Audio Player Settings"
property alias lastSongIndex: audioPlaylist.lastSongPlayed
property alias durToContinue: audioPlayer.durationProgress
property alias playerVolume: audioPlayer.volumeValue
}
Component.onCompleted: {
console.log("Application is loaded")
}
}